mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
4d966409bc
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>
29 lines
862 B
Go
29 lines
862 B
Go
package system
|
|
|
|
import "golang.org/x/sys/unix"
|
|
|
|
// Lgetxattr retrieves the value of the extended attribute identified by attr
|
|
// and associated with the given path in the file system.
|
|
// It will returns a nil slice and nil error if the xattr is not set.
|
|
func Lgetxattr(path string, attr string) ([]byte, error) {
|
|
dest := make([]byte, 128)
|
|
sz, errno := unix.Lgetxattr(path, attr, dest)
|
|
if errno == unix.ENODATA {
|
|
return nil, nil
|
|
}
|
|
if errno == unix.ERANGE {
|
|
dest = make([]byte, sz)
|
|
sz, errno = unix.Lgetxattr(path, attr, dest)
|
|
}
|
|
if errno != nil {
|
|
return nil, errno
|
|
}
|
|
|
|
return dest[:sz], nil
|
|
}
|
|
|
|
// Lsetxattr sets the value of the extended attribute identified by attr
|
|
// and associated with the given path in the file system.
|
|
func Lsetxattr(path string, attr string, data []byte, flags int) error {
|
|
return unix.Lsetxattr(path, attr, data, flags)
|
|
}
|