-
Notifications
You must be signed in to change notification settings - Fork 1
/
chtimes.go
38 lines (32 loc) · 1.07 KB
/
chtimes.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
package wrfs
import "time"
// ChtimesFile is a file with a Chtimes method.
type ChtimesFile interface {
File
// Chtimes changes the access and modification times of the file,
// similar to the Unix utime() or utimes() functions.
Chtimes(atime time.Time, mtime time.Time) error
}
// ChtimesFS is a file system with a Chtimes method.
type ChtimesFS interface {
FS
// Chtimes changes the access and modification times of the named file,
// similar to the Unix utime() or utimes() functions.
Chtimes(name string, atime time.Time, mtime time.Time) error
}
// Chtimes changes the access and modification times of the named file,
// similar to the Unix utime() or utimes() functions.
func Chtimes(fsys FS, name string, atime time.Time, mtime time.Time) (err error) {
if fsys, ok := fsys.(ChtimesFS); ok {
return fsys.Chtimes(name, atime, mtime)
}
file, err := fsys.Open(name)
defer safeClose(file, &err)
if err != nil {
return err
}
if file, ok := file.(ChtimesFile); ok {
return file.Chtimes(atime, mtime)
}
return &PathError{Op: "chtimes", Path: name, Err: ErrUnsupported}
}