2013-11-27 21:22:47 -05:00
|
|
|
package archive
|
|
|
|
|
2013-12-13 09:43:50 -05:00
|
|
|
import (
|
|
|
|
"syscall"
|
|
|
|
"unsafe"
|
|
|
|
)
|
2013-11-27 21:22:47 -05:00
|
|
|
|
|
|
|
func getLastAccess(stat *syscall.Stat_t) syscall.Timespec {
|
|
|
|
return stat.Atim
|
|
|
|
}
|
|
|
|
|
|
|
|
func getLastModification(stat *syscall.Stat_t) syscall.Timespec {
|
|
|
|
return stat.Mtim
|
|
|
|
}
|
2013-12-13 09:43:50 -05:00
|
|
|
|
|
|
|
func LUtimesNano(path string, ts []syscall.Timespec) error {
|
2013-12-24 19:37:00 -05:00
|
|
|
// These are not currently available in syscall
|
2013-12-13 09:43:50 -05:00
|
|
|
AT_FDCWD := -100
|
|
|
|
AT_SYMLINK_NOFOLLOW := 0x100
|
|
|
|
|
|
|
|
var _path *byte
|
|
|
|
_path, err := syscall.BytePtrFromString(path)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, _, err := syscall.Syscall6(syscall.SYS_UTIMENSAT, uintptr(AT_FDCWD), uintptr(unsafe.Pointer(_path)), uintptr(unsafe.Pointer(&ts[0])), uintptr(AT_SYMLINK_NOFOLLOW), 0, 0); err != 0 && err != syscall.ENOSYS {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2014-02-06 17:13:03 -05:00
|
|
|
|
|
|
|
func UtimesNano(path string, ts []syscall.Timespec) error {
|
|
|
|
if err := syscall.UtimesNano(path, ts); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2014-02-14 08:24:37 -05:00
|
|
|
|
|
|
|
// Returns a nil slice and nil error if the xattr is not set
|
|
|
|
func Lgetxattr(path string, attr string) ([]byte, error) {
|
|
|
|
pathBytes, err := syscall.BytePtrFromString(path)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
attrBytes, err := syscall.BytePtrFromString(attr)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
dest := make([]byte, 128)
|
|
|
|
destBytes := unsafe.Pointer(&dest[0])
|
|
|
|
sz, _, errno := syscall.Syscall6(syscall.SYS_LGETXATTR, uintptr(unsafe.Pointer(pathBytes)), uintptr(unsafe.Pointer(attrBytes)), uintptr(destBytes), uintptr(len(dest)), 0, 0)
|
|
|
|
if errno == syscall.ENODATA {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
if errno == syscall.ERANGE {
|
|
|
|
dest = make([]byte, sz)
|
|
|
|
destBytes := unsafe.Pointer(&dest[0])
|
|
|
|
sz, _, errno = syscall.Syscall6(syscall.SYS_LGETXATTR, uintptr(unsafe.Pointer(pathBytes)), uintptr(unsafe.Pointer(attrBytes)), uintptr(destBytes), uintptr(len(dest)), 0, 0)
|
|
|
|
}
|
|
|
|
if errno != 0 {
|
|
|
|
return nil, errno
|
|
|
|
}
|
|
|
|
|
|
|
|
return dest[:sz], nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var _zero uintptr
|
|
|
|
|
|
|
|
func Lsetxattr(path string, attr string, data []byte, flags int) error {
|
|
|
|
pathBytes, err := syscall.BytePtrFromString(path)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
attrBytes, err := syscall.BytePtrFromString(attr)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
var dataBytes unsafe.Pointer
|
|
|
|
if len(data) > 0 {
|
|
|
|
dataBytes = unsafe.Pointer(&data[0])
|
|
|
|
} else {
|
|
|
|
dataBytes = unsafe.Pointer(&_zero)
|
|
|
|
}
|
|
|
|
_, _, errno := syscall.Syscall6(syscall.SYS_LSETXATTR, uintptr(unsafe.Pointer(pathBytes)), uintptr(unsafe.Pointer(attrBytes)), uintptr(dataBytes), uintptr(len(data)), uintptr(flags), 0)
|
|
|
|
if errno != 0 {
|
|
|
|
return errno
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|