Let a Working Folder delete a basename.

CheckDNS needs that to Remove Domain without a second storage path.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-09-28 19:31:36 +02:00
co-authored by Cursor
parent 6560dffa69
commit 300484114f
4 changed files with 65 additions and 2 deletions
+14
View File
@@ -32,6 +32,8 @@ type Folder interface {
Write(name string, data []byte) error
// Exists reports whether name is a non-directory file in the Working Folder.
Exists(name string) (bool, error)
// Remove deletes a basename in the Working Folder.
Remove(name string) error
}
// Root is User Files Root–relative folder access.
@@ -181,6 +183,18 @@ func (f localFolder) Exists(name string) (bool, error) {
return !info.IsDir(), nil
}
// Remove implements Folder for a local directory.
func (f localFolder) Remove(name string) error {
if err := RequireBasename(name); err != nil {
return err
}
err := os.Remove(filepath.Join(f.dir, name))
if err != nil && os.IsNotExist(err) {
return fmt.Errorf("%w: %s", ErrNotExist, name)
}
return err
}
// RequireBasename rejects path segments that are not a single basename.
func RequireBasename(name string) error {
if name == "" || name != path.Base(name) || strings.ContainsAny(name, `/\`) || strings.Contains(name, "..") {