2017-06-15 18:54:58 +00:00
|
|
|
// +build linux
|
|
|
|
|
|
|
|
package mtree
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/base64"
|
|
|
|
"os"
|
2017-06-26 19:12:31 +00:00
|
|
|
"syscall"
|
|
|
|
"time"
|
|
|
|
"unsafe"
|
2017-06-15 18:54:58 +00:00
|
|
|
|
|
|
|
"github.com/vbatts/go-mtree/xattr"
|
|
|
|
)
|
|
|
|
|
2017-06-26 18:24:10 +00:00
|
|
|
func xattrUpdateKeywordFunc(path string, kv KeyVal) (os.FileInfo, error) {
|
|
|
|
buf, err := base64.StdEncoding.DecodeString(kv.Value())
|
2017-06-15 18:54:58 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2017-06-26 18:24:10 +00:00
|
|
|
if err := xattr.Set(path, kv.Keyword().Suffix(), buf); err != nil {
|
2017-06-15 18:54:58 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return os.Lstat(path)
|
|
|
|
}
|
2017-06-26 19:12:31 +00:00
|
|
|
|
|
|
|
func lchtimes(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(atFdCwd, name, (*[2]syscall.Timespec)(unsafe.Pointer(&utimes[0])), atSymlinkNofollow); e != nil {
|
|
|
|
return &os.PathError{Op: "chtimes", Path: name, Err: e}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// from uapi/linux/fcntl.h
|
|
|
|
// don't follow symlinks
|
|
|
|
const atSymlinkNofollow = 0x100
|
|
|
|
|
|
|
|
// special value for utimes as the FD for the current working directory
|
|
|
|
const atFdCwd = -0x64
|
|
|
|
|
|
|
|
func utimensat(dirfd int, path string, times *[2]syscall.Timespec, flags int) (err error) {
|
|
|
|
if len(times) != 2 {
|
|
|
|
return syscall.EINVAL
|
|
|
|
}
|
|
|
|
var _p0 *byte
|
|
|
|
_p0, err = syscall.BytePtrFromString(path)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
_, _, e1 := syscall.Syscall6(syscall.SYS_UTIMENSAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(times)), uintptr(flags), 0, 0)
|
|
|
|
if e1 != 0 {
|
|
|
|
err = syscall.Errno(e1)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|