-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchown.go
More file actions
33 lines (29 loc) · 886 Bytes
/
Copy pathchown.go
File metadata and controls
33 lines (29 loc) · 886 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 ChownFS is a file system with the Chown method.
type ChownFS interface {
FS
// Chown changes the numeric uid and gid of the named file.
// This is typically a Unix-specific operation.
Chown(ctx context.Context, name string, uid, gid int) error
}
// Chown changes the numeric uid and gid of the named file.
// Analogous to: [os.Chown], [os.Lchown], chown, 9P Twstat.
// This is typically a Unix-specific operation.
//
// Requires: [ChownFS]
func Chown(ctx context.Context, fsys FS, name string, uid, gid int) (err error) {
if name, err = localizePath(ctx, fsys, name); err != nil {
return err
}
if cfs, ok := fsys.(ChownFS); ok {
err := cfs.Chown(ctx, name, uid, gid)
if !errors.Is(err, ErrUnsupported) {
return newPathError("chown", name, err)
}
}
return &PathError{Op: "chown", Path: name, Err: ErrUnsupported}
}