Use the symlink xattr syscall wrappers Lgetxattr and Lsetxattr from
x/sys/unix (introduced in golang/sys@b90f89a) instead of providing own
wrappers. Leave the functionality of system.Lgetxattr intact with
respect to the retry with a larger buffer, but switch it to use
unix.Lgetxattr. Also leave system.Lsetxattr intact (even though it's
just a wrapper around the corresponding function from unix) in order to
keep moby building for !linux.
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
| ... | ... |
@@ -1,64 +1,29 @@ |
| 1 | 1 |
package system |
| 2 | 2 |
|
| 3 |
-import ( |
|
| 4 |
- "unsafe" |
|
| 5 |
- |
|
| 6 |
- "golang.org/x/sys/unix" |
|
| 7 |
-) |
|
| 3 |
+import "golang.org/x/sys/unix" |
|
| 8 | 4 |
|
| 9 | 5 |
// Lgetxattr retrieves the value of the extended attribute identified by attr |
| 10 | 6 |
// and associated with the given path in the file system. |
| 11 | 7 |
// It will returns a nil slice and nil error if the xattr is not set. |
| 12 | 8 |
func Lgetxattr(path string, attr string) ([]byte, error) {
|
| 13 |
- pathBytes, err := unix.BytePtrFromString(path) |
|
| 14 |
- if err != nil {
|
|
| 15 |
- return nil, err |
|
| 16 |
- } |
|
| 17 |
- attrBytes, err := unix.BytePtrFromString(attr) |
|
| 18 |
- if err != nil {
|
|
| 19 |
- return nil, err |
|
| 20 |
- } |
|
| 21 |
- |
|
| 22 | 9 |
dest := make([]byte, 128) |
| 23 |
- destBytes := unsafe.Pointer(&dest[0]) |
|
| 24 |
- sz, _, errno := unix.Syscall6(unix.SYS_LGETXATTR, uintptr(unsafe.Pointer(pathBytes)), uintptr(unsafe.Pointer(attrBytes)), uintptr(destBytes), uintptr(len(dest)), 0, 0) |
|
| 10 |
+ sz, errno := unix.Lgetxattr(path, attr, dest) |
|
| 25 | 11 |
if errno == unix.ENODATA {
|
| 26 | 12 |
return nil, nil |
| 27 | 13 |
} |
| 28 | 14 |
if errno == unix.ERANGE {
|
| 29 | 15 |
dest = make([]byte, sz) |
| 30 |
- destBytes := unsafe.Pointer(&dest[0]) |
|
| 31 |
- sz, _, errno = unix.Syscall6(unix.SYS_LGETXATTR, uintptr(unsafe.Pointer(pathBytes)), uintptr(unsafe.Pointer(attrBytes)), uintptr(destBytes), uintptr(len(dest)), 0, 0) |
|
| 16 |
+ sz, errno = unix.Lgetxattr(path, attr, dest) |
|
| 32 | 17 |
} |
| 33 |
- if errno != 0 {
|
|
| 18 |
+ if errno != nil {
|
|
| 34 | 19 |
return nil, errno |
| 35 | 20 |
} |
| 36 | 21 |
|
| 37 | 22 |
return dest[:sz], nil |
| 38 | 23 |
} |
| 39 | 24 |
|
| 40 |
-var _zero uintptr |
|
| 41 |
- |
|
| 42 | 25 |
// Lsetxattr sets the value of the extended attribute identified by attr |
| 43 | 26 |
// and associated with the given path in the file system. |
| 44 | 27 |
func Lsetxattr(path string, attr string, data []byte, flags int) error {
|
| 45 |
- pathBytes, err := unix.BytePtrFromString(path) |
|
| 46 |
- if err != nil {
|
|
| 47 |
- return err |
|
| 48 |
- } |
|
| 49 |
- attrBytes, err := unix.BytePtrFromString(attr) |
|
| 50 |
- if err != nil {
|
|
| 51 |
- return err |
|
| 52 |
- } |
|
| 53 |
- var dataBytes unsafe.Pointer |
|
| 54 |
- if len(data) > 0 {
|
|
| 55 |
- dataBytes = unsafe.Pointer(&data[0]) |
|
| 56 |
- } else {
|
|
| 57 |
- dataBytes = unsafe.Pointer(&_zero) |
|
| 58 |
- } |
|
| 59 |
- _, _, errno := unix.Syscall6(unix.SYS_LSETXATTR, uintptr(unsafe.Pointer(pathBytes)), uintptr(unsafe.Pointer(attrBytes)), uintptr(dataBytes), uintptr(len(data)), uintptr(flags), 0) |
|
| 60 |
- if errno != 0 {
|
|
| 61 |
- return errno |
|
| 62 |
- } |
|
| 63 |
- return nil |
|
| 28 |
+ return unix.Lsetxattr(path, attr, data, flags) |
|
| 64 | 29 |
} |