-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchtimes.go
More file actions
34 lines (30 loc) · 1010 Bytes
/
Copy pathchtimes.go
File metadata and controls
34 lines (30 loc) · 1010 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
package fs
import (
"context"
"errors"
"time"
)
// A ChtimesFS is a file system with the Chtimes method.
type ChtimesFS interface {
FS
// Chtimes changes the access and modification times of the named file.
// A zero time.Time value will leave the corresponding file time unchanged.
Chtimes(ctx context.Context, name string, atime, mtime time.Time) error
}
// Chtimes changes the access and modification times of the named file.
// A zero time.Time value will leave the corresponding file time unchanged.
// Analogous to: [os.Chtimes], touch -t, 9P Twstat.
//
// Requires: [ChtimesFS]
func Chtimes(ctx context.Context, fsys FS, name string, atime, mtime time.Time) (err error) {
if name, err = localizePath(ctx, fsys, name); err != nil {
return err
}
if cfs, ok := fsys.(ChtimesFS); ok {
err := cfs.Chtimes(ctx, name, atime, mtime)
if !errors.Is(err, ErrUnsupported) {
return newPathError("chtimes", name, err)
}
}
return &PathError{Op: "chtimes", Path: name, Err: ErrUnsupported}
}