diff --git a/storage/pkg/system/utimes_freebsd.go b/storage/pkg/system/utimes_freebsd.go deleted file mode 100644 index edc588a63f..0000000000 --- a/storage/pkg/system/utimes_freebsd.go +++ /dev/null @@ -1,25 +0,0 @@ -package system - -import ( - "syscall" - "unsafe" - - "golang.org/x/sys/unix" -) - -// LUtimesNano is used to change access and modification time of the specified path. -// It's used for symbol link file because unix.UtimesNano doesn't support a NOFOLLOW flag atm. -func LUtimesNano(path string, ts []syscall.Timespec) error { - atFdCwd := unix.AT_FDCWD - - var _path *byte - _path, err := unix.BytePtrFromString(path) - if err != nil { - return err - } - if _, _, err := unix.Syscall6(unix.SYS_UTIMENSAT, uintptr(atFdCwd), uintptr(unsafe.Pointer(_path)), uintptr(unsafe.Pointer(&ts[0])), unix.AT_SYMLINK_NOFOLLOW, 0, 0); err != 0 && err != unix.ENOSYS { - return err - } - - return nil -} diff --git a/storage/pkg/system/utimes_linux.go b/storage/pkg/system/utimes_linux.go deleted file mode 100644 index edc588a63f..0000000000 --- a/storage/pkg/system/utimes_linux.go +++ /dev/null @@ -1,25 +0,0 @@ -package system - -import ( - "syscall" - "unsafe" - - "golang.org/x/sys/unix" -) - -// LUtimesNano is used to change access and modification time of the specified path. -// It's used for symbol link file because unix.UtimesNano doesn't support a NOFOLLOW flag atm. -func LUtimesNano(path string, ts []syscall.Timespec) error { - atFdCwd := unix.AT_FDCWD - - var _path *byte - _path, err := unix.BytePtrFromString(path) - if err != nil { - return err - } - if _, _, err := unix.Syscall6(unix.SYS_UTIMENSAT, uintptr(atFdCwd), uintptr(unsafe.Pointer(_path)), uintptr(unsafe.Pointer(&ts[0])), unix.AT_SYMLINK_NOFOLLOW, 0, 0); err != 0 && err != unix.ENOSYS { - return err - } - - return nil -} diff --git a/storage/pkg/system/utimes_unix.go b/storage/pkg/system/utimes_unix.go new file mode 100644 index 0000000000..2568d8a902 --- /dev/null +++ b/storage/pkg/system/utimes_unix.go @@ -0,0 +1,22 @@ +//go:build unix + +package system + +import ( + "syscall" + + "golang.org/x/sys/unix" +) + +// LUtimesNano is used to change access and modification time of the specified path. +func LUtimesNano(path string, ts []syscall.Timespec) error { + ts_ := [2]unix.Timespec{ + {Sec: ts[0].Sec, Nsec: ts[0].Nsec}, + {Sec: ts[1].Sec, Nsec: ts[1].Nsec}, + } + err := unix.UtimesNanoAt(unix.AT_FDCWD, path, ts_[:], unix.AT_SYMLINK_NOFOLLOW) + if err == unix.ENOSYS { + err = nil + } + return err +} diff --git a/storage/pkg/system/utimes_unix_test.go b/storage/pkg/system/utimes_unix_test.go index 9d4f1cbc85..d3f841d244 100644 --- a/storage/pkg/system/utimes_unix_test.go +++ b/storage/pkg/system/utimes_unix_test.go @@ -1,4 +1,4 @@ -//go:build linux || freebsd +//go:build unix package system diff --git a/storage/pkg/system/utimes_unsupported.go b/storage/pkg/system/utimes_unsupported.go index b6c36339df..2760ffa62c 100644 --- a/storage/pkg/system/utimes_unsupported.go +++ b/storage/pkg/system/utimes_unsupported.go @@ -1,10 +1,10 @@ -//go:build !linux && !freebsd +//go:build !unix package system import "syscall" -// LUtimesNano is only supported on linux and freebsd. +// LUtimesNano is only supported on Unix systems. func LUtimesNano(path string, ts []syscall.Timespec) error { return ErrNotSupportedPlatform }