mirror of
https://github.com/rclone/rclone.git
synced 2024-11-22 00:13:49 +01:00
Remove custom nS precision Chtimes as now in Go >= 1.1
This commit is contained in:
parent
eefe789fc2
commit
8fd43a52e7
14
chtimes.go
14
chtimes.go
@ -1,14 +0,0 @@
|
||||
// Default implementation of Chtimes
|
||||
|
||||
// +build !linux
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
func Chtimes(name string, atime time.Time, mtime time.Time) error {
|
||||
return os.Chtimes(name, atime, mtime)
|
||||
}
|
@ -1,78 +0,0 @@
|
||||
// An implementation of Chtimes which preserves nanosecond precision under linux
|
||||
//
|
||||
// Is now in the standard library - https://codereview.appspot.com/6905057/
|
||||
|
||||
// +build linux !go1.1
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"syscall"
|
||||
"time"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// COPIED from syscall
|
||||
// byteSliceFromString returns a NUL-terminated slice of bytes
|
||||
// containing the text of s. If s contains a NUL byte at any
|
||||
// location, it returns (nil, EINVAL).
|
||||
func byteSliceFromString(s string) ([]byte, error) {
|
||||
for i := 0; i < len(s); i++ {
|
||||
if s[i] == 0 {
|
||||
return nil, syscall.EINVAL
|
||||
}
|
||||
}
|
||||
a := make([]byte, len(s)+1)
|
||||
copy(a, s)
|
||||
return a, nil
|
||||
}
|
||||
|
||||
// COPIED from syscall
|
||||
// bytePtrFromString returns a pointer to a NUL-terminated array of
|
||||
// bytes containing the text of s. If s contains a NUL byte at any
|
||||
// location, it returns (nil, EINVAL).
|
||||
func bytePtrFromString(s string) (*byte, error) {
|
||||
a, err := byteSliceFromString(s)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &a[0], nil
|
||||
}
|
||||
|
||||
// COPIED from syscall auto generated code modified from utimes
|
||||
func utimensat(dirfd int, path string, times *[2]syscall.Timespec) (err error) {
|
||||
var _p0 *byte
|
||||
_p0, err = bytePtrFromString(path)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
_, _, e1 := syscall.Syscall(syscall.SYS_UTIMENSAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(times)))
|
||||
if e1 != 0 {
|
||||
err = e1
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// FIXME needs defining properly!
|
||||
const AT_FDCWD = -100
|
||||
|
||||
// COPIED from syscall and modified
|
||||
//sys utimes(path string, times *[2]Timeval) (err error)
|
||||
func Utimensat(dirfd int, path string, ts []syscall.Timespec) (err error) {
|
||||
if len(ts) != 2 {
|
||||
return syscall.EINVAL
|
||||
}
|
||||
return utimensat(dirfd, path, (*[2]syscall.Timespec)(unsafe.Pointer(&ts[0])))
|
||||
}
|
||||
|
||||
// COPIED from syscall and modified
|
||||
func Chtimes(name string, atime time.Time, mtime time.Time) error {
|
||||
var utimes [2]syscall.Timespec
|
||||
utimes[0] = syscall.NsecToTimespec(atime.UnixNano())
|
||||
utimes[1] = syscall.NsecToTimespec(mtime.UnixNano())
|
||||
if e := Utimensat(AT_FDCWD, name, utimes[0:]); e != nil {
|
||||
return &os.PathError{Op: "chtimes", Path: name, Err: e}
|
||||
}
|
||||
return nil
|
||||
}
|
Loading…
Reference in New Issue
Block a user