-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremove.go
More file actions
35 lines (31 loc) · 927 Bytes
/
Copy pathremove.go
File metadata and controls
35 lines (31 loc) · 927 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package fs
import (
"context"
"errors"
)
// A RemoveFS is a file system with the Remove method.
type RemoveFS interface {
FS
// Remove removes the named file or empty directory.
// It returns an error if the file does not exist or if a directory
// is not empty.
Remove(ctx context.Context, name string) error
}
// Remove removes the named file or empty directory.
// Analogous to: [os.Remove], rm, 9P Tremove, S3 DeleteObject.
// Returns an error if the file does not exist or if a directory is not
// empty.
//
// Requires: [RemoveFS]
func Remove(ctx context.Context, fsys FS, name string) error {
var err error
if name, err = localizePath(ctx, fsys, name); err != nil {
return err
}
if rfs, ok := fsys.(RemoveFS); ok {
if err := rfs.Remove(ctx, name); !errors.Is(err, ErrUnsupported) {
return newPathError("remove", name, err)
}
}
return &PathError{Op: "remove", Path: name, Err: ErrUnsupported}
}