Skip to content

Commit 6ab007a

Browse files
authored
Current definition of ENOATTR isn't helpful on Solaris (#75)
1 parent 74a35a9 commit 6ab007a

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

xattr_solaris.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
package xattr
55

66
import (
7+
"errors"
78
"os"
8-
"syscall"
99

1010
"golang.org/x/sys/unix"
1111
)
@@ -17,10 +17,11 @@ const (
1717
XATTR_CREATE = 0x1
1818
XATTR_REPLACE = 0x2
1919

20-
// ENOATTR is not exported by the syscall package on Linux, because it is
21-
// an alias for ENODATA. We export it here so it is available on all
22-
// our supported platforms.
23-
ENOATTR = syscall.ENODATA
20+
// ENOATTR is not defined on Solaris. When attempting to open an
21+
// extended attribute that doesn't exist, we'll get ENOENT. For
22+
// compatibility with other platforms, we make ENOATTR available as
23+
// an alias of unix.ENOENT.
24+
ENOATTR = unix.ENOENT
2425
)
2526

2627
func getxattr(path string, name string, data []byte) (int, error) {
@@ -132,7 +133,13 @@ func llistxattr(path string, data []byte) (int, error) {
132133
func flistxattr(f *os.File, data []byte) (int, error) {
133134
fd, err := unix.Openat(int(f.Fd()), ".", unix.O_RDONLY|unix.O_XATTR, 0)
134135
if err != nil {
135-
return 0, unix.ENOTSUP
136+
// When attempting to list extended attributes on a filesystem
137+
// that doesn't support them (like as UFS and tmpfs), we'll get
138+
// EINVAL. Translate this error to the more conventional ENOTSUP.
139+
if errors.Is(err, unix.EINVAL) {
140+
return 0, unix.ENOTSUP
141+
}
142+
return 0, err
136143
}
137144
xf := os.NewFile(uintptr(fd), f.Name())
138145
defer func() {

0 commit comments

Comments
 (0)