From 30e92a19ae4a77dde818b8c3d41d51e4850cba12 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Sat, 2 Mar 2019 14:21:52 +0100 Subject: [PATCH] unix: add Lutimes Add Lutimes wrapping UtimesNanoAt. Updates golang/go#30487 Change-Id: Ic5bb3b4d88be5806522eaef9bd9b8b0f5c1c8f42 Reviewed-on: https://go-review.googlesource.com/c/sys/+/164662 Run-TryBot: Tobias Klauser TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- unix/syscall_unix.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/unix/syscall_unix.go b/unix/syscall_unix.go index 0f07d29f..ae59fba0 100644 --- a/unix/syscall_unix.go +++ b/unix/syscall_unix.go @@ -395,3 +395,22 @@ func SetNonblock(fd int, nonblocking bool) (err error) { func Exec(argv0 string, argv []string, envv []string) error { return syscall.Exec(argv0, argv, envv) } + +// Lutimes sets the access and modification times tv on path. If path refers to +// a symlink, it is not dereferenced and the timestamps are set on the symlink. +// If tv is nil, the access and modification times are set to the current time. +// Otherwise tv must contain exactly 2 elements, with access time as the first +// element and modification time as the second element. +func Lutimes(path string, tv []Timeval) error { + if tv == nil { + return UtimesNanoAt(AT_FDCWD, path, nil, AT_SYMLINK_NOFOLLOW) + } + if len(tv) != 2 { + return EINVAL + } + ts := []Timespec{ + NsecToTimespec(TimevalToNsec(tv[0])), + NsecToTimespec(TimevalToNsec(tv[1])), + } + return UtimesNanoAt(AT_FDCWD, path, ts, AT_SYMLINK_NOFOLLOW) +}