mirror of
https://github.com/vbatts/go-mtree.git
synced 2024-11-22 08:25:38 +00:00
3fe21921b5
Use UtimesNanoAt from golang.org/x/sys/unix instead of manually crafting the syscall. Since UtimesNanoAt is provided for all unix-like OSes, factor out lchtimes to its own file with appropriate build tags. This allows to make use of it on darwin, dragonfly, freebsd, openbsd, netbsd and solaris in addition to linux. Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
22 lines
484 B
Go
22 lines
484 B
Go
// +build darwin dragonfly freebsd openbsd linux netbsd solaris
|
|
|
|
package mtree
|
|
|
|
import (
|
|
"os"
|
|
"time"
|
|
|
|
"golang.org/x/sys/unix"
|
|
)
|
|
|
|
func lchtimes(name string, atime time.Time, mtime time.Time) error {
|
|
utimes := []unix.Timespec{
|
|
unix.NsecToTimespec(atime.UnixNano()),
|
|
unix.NsecToTimespec(mtime.UnixNano()),
|
|
}
|
|
if e := unix.UtimesNanoAt(unix.AT_FDCWD, name, utimes, unix.AT_SYMLINK_NOFOLLOW); e != nil {
|
|
return &os.PathError{Op: "chtimes", Path: name, Err: e}
|
|
}
|
|
return nil
|
|
|
|
}
|