utimes_linux.go 728 B

1234567891011121314151617181920212223242526
  1. package system
  2. import (
  3. "syscall"
  4. "unsafe"
  5. )
  6. // LUtimesNano is used to change access and modification time of the specified path.
  7. // It's used for symbol link file because syscall.UtimesNano doesn't support a NOFOLLOW flag atm.
  8. func LUtimesNano(path string, ts []syscall.Timespec) error {
  9. // These are not currently available in syscall
  10. atFdCwd := -100
  11. atSymLinkNoFollow := 0x100
  12. var _path *byte
  13. _path, err := syscall.BytePtrFromString(path)
  14. if err != nil {
  15. return err
  16. }
  17. if _, _, err := syscall.Syscall6(syscall.SYS_UTIMENSAT, uintptr(atFdCwd), uintptr(unsafe.Pointer(_path)), uintptr(unsafe.Pointer(&ts[0])), uintptr(atSymLinkNoFollow), 0, 0); err != 0 && err != syscall.ENOSYS {
  18. return err
  19. }
  20. return nil
  21. }