Skip to content

Commit a408b7b

Browse files
committed
sysx/xattr: unify implementation
1. Remove sysx/xattr_darwin* as it's now available from x/sys/unix. 2. Merge xattr_{freebsd,openbsd,solaris}.go into xattr_unsupported.go. 3. Merge xattr_linux.go into xattr.go. 4. Add proper build tags (linux and darwin are supported, others are not). 5. Remove some unused files. Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent 363bb7e commit a408b7b

11 files changed

Lines changed: 53 additions & 418 deletions

sysx/asm.s

Lines changed: 0 additions & 10 deletions
This file was deleted.

sysx/sys.go

Lines changed: 0 additions & 37 deletions
This file was deleted.

sysx/xattr.go

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,56 @@
1+
// +build linux darwin
2+
13
package sysx
24

35
import (
46
"bytes"
5-
"fmt"
67
"syscall"
8+
9+
"golang.org/x/sys/unix"
710
)
811

9-
const defaultXattrBufferSize = 5
12+
// Listxattr calls syscall listxattr and reads all content
13+
// and returns a string array
14+
func Listxattr(path string) ([]string, error) {
15+
return listxattrAll(path, unix.Listxattr)
16+
}
17+
18+
// Removexattr calls syscall removexattr
19+
func Removexattr(path string, attr string) (err error) {
20+
return unix.Removexattr(path, attr)
21+
}
22+
23+
// Setxattr calls syscall setxattr
24+
func Setxattr(path string, attr string, data []byte, flags int) (err error) {
25+
return unix.Setxattr(path, attr, data, flags)
26+
}
27+
28+
// Getxattr calls syscall getxattr
29+
func Getxattr(path, attr string) ([]byte, error) {
30+
return getxattrAll(path, attr, unix.Getxattr)
31+
}
1032

11-
var ErrNotSupported = fmt.Errorf("not supported")
33+
// LListxattr lists xattrs, not following symlinks
34+
func LListxattr(path string) ([]string, error) {
35+
return listxattrAll(path, unix.Llistxattr)
36+
}
37+
38+
// LRemovexattr removes an xattr, not following symlinks
39+
func LRemovexattr(path string, attr string) (err error) {
40+
return unix.Lremovexattr(path, attr)
41+
}
42+
43+
// LSetxattr sets an xattr, not following symlinks
44+
func LSetxattr(path string, attr string, data []byte, flags int) (err error) {
45+
return unix.Lsetxattr(path, attr, data, flags)
46+
}
47+
48+
// LGetxattr gets an xattr, not following symlinks
49+
func LGetxattr(path, attr string) ([]byte, error) {
50+
return getxattrAll(path, attr, unix.Lgetxattr)
51+
}
52+
53+
const defaultXattrBufferSize = 5
1254

1355
type listxattrFunc func(path string, dest []byte) (int, error)
1456

sysx/xattr_darwin.go

Lines changed: 0 additions & 70 deletions
This file was deleted.

sysx/xattr_darwin_386.go

Lines changed: 0 additions & 111 deletions
This file was deleted.

0 commit comments

Comments
 (0)