github.com/artpar/rclone@v1.67.3/backend/local/lchtimes_unix.go (about)

     1  //go:build !windows && !plan9 && !js
     2  
     3  package local
     4  
     5  import (
     6  	"os"
     7  	"time"
     8  
     9  	"golang.org/x/sys/unix"
    10  )
    11  
    12  const haveLChtimes = true
    13  
    14  // lChtimes changes the access and modification times of the named
    15  // link, similar to the Unix utime() or utimes() functions.
    16  //
    17  // The underlying filesystem may truncate or round the values to a
    18  // less precise time unit.
    19  // If there is an error, it will be of type *PathError.
    20  func lChtimes(name string, atime time.Time, mtime time.Time) error {
    21  	var utimes [2]unix.Timespec
    22  	utimes[0] = unix.NsecToTimespec(atime.UnixNano())
    23  	utimes[1] = unix.NsecToTimespec(mtime.UnixNano())
    24  	if e := unix.UtimesNanoAt(unix.AT_FDCWD, name, utimes[0:], unix.AT_SYMLINK_NOFOLLOW); e != nil {
    25  		return &os.PathError{Op: "lchtimes", Path: name, Err: e}
    26  	}
    27  	return nil
    28  }