-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchmod.go
More file actions
33 lines (29 loc) · 764 Bytes
/
Copy pathchmod.go
File metadata and controls
33 lines (29 loc) · 764 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
package fs
import (
"context"
"errors"
)
// A ChmodFS is a file system with the Chmod method.
type ChmodFS interface {
FS
// Chmod changes the mode of the named file to mode.
Chmod(ctx context.Context, name string, mode Mode) error
}
// Chmod changes the mode of the named file to mode.
// Analogous to: [os.Chmod], chmod, 9P Twstat.
//
// Requires: [ChmodFS]
func Chmod(
ctx context.Context, fsys FS, name string, mode Mode,
) error {
var err error
if name, err = localizePath(ctx, fsys, name); err != nil {
return err
}
if cfs, ok := fsys.(ChmodFS); ok {
if err := cfs.Chmod(ctx, name, mode); !errors.Is(err, ErrUnsupported) {
return newPathError("chmod", name, err)
}
}
return &PathError{Op: "chmod", Path: name, Err: ErrUnsupported}
}