-
Notifications
You must be signed in to change notification settings - Fork 1
/
chmod.go
39 lines (31 loc) · 967 Bytes
/
chmod.go
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
36
37
38
39
package wrfs
// Chmod is a file with a Chmod method.
type ChmodFile interface {
File
// Chmod changes the mode of the file to mode.
Chmod(mode FileMode) error
}
// ChmodFS is a file system with a Chmod method.
type ChmodFS interface {
FS
// Chmod changes the mode of the named file to mode.
// If the file is a symbolic link, it changes the mode of the link's target.
Chmod(name string, mode FileMode) error
}
// Chmod changes the mode of the named file to mode.
// If the file is a symbolic link, it changes the mode of the link's target.
func Chmod(fsys FS, name string, mode FileMode) (err error) {
if fsys, ok := fsys.(ChmodFS); ok {
return fsys.Chmod(name, mode)
}
// Open the file and attempt to call chmod on it.
file, err := fsys.Open(name)
if err != nil {
return err
}
defer safeClose(file, &err)
if file, ok := file.(ChmodFile); ok {
return file.Chmod(mode)
}
return &PathError{Op: "chmod", Path: name, Err: ErrUnsupported}
}