Skip to content

Commit

Permalink
unix: fix Test{Fd,}Xattr failure on NetBSD
Browse files Browse the repository at this point in the history
On NetBSD the namespace of an xattr is stored separately from the name
and isn't returned by Listxattr and Flistxattr. Like on FreeBSD, strip
the namespace before checking the returned xattrs.

Fixes golang/go#69313
Fixes golang/go#69314

Change-Id: I7f2393cc63f9860332c0e07a51f3b9d32911e892
Cq-Include-Trybots: luci.golang.try:x_sys-gotip-netbsd-arm64
Reviewed-on: https://go-review.googlesource.com/c/sys/+/611695
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Commit-Queue: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
  • Loading branch information
tklauser authored and gopherbot committed Sep 9, 2024
1 parent 68ed59b commit 30de352
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions unix/xattr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,22 @@ func TestXattr(t *testing.T) {
xattrs := stringsFromByteSlice(buf[:read])

xattrWant := xattrName
if runtime.GOOS == "freebsd" {
// On FreeBSD, the namespace is stored separately from the xattr
switch runtime.GOOS {
case "freebsd", "netbsd":
// On FreeBSD and NetBSD, the namespace is stored separately from the xattr
// name and Listxattr doesn't return the namespace prefix.
xattrWant = strings.TrimPrefix(xattrWant, "user.")
}
found := false
for _, name := range xattrs {
if name == xattrWant {
found = true
break
}
}

if !found {
t.Errorf("Listxattr did not return previously set attribute '%s'", xattrName)
t.Errorf("Listxattr did not return previously set attribute %q in attributes %v", xattrName, xattrs)
}

// find size
Expand Down Expand Up @@ -162,20 +164,22 @@ func TestFdXattr(t *testing.T) {
xattrs := stringsFromByteSlice(buf[:read])

xattrWant := xattrName
if runtime.GOOS == "freebsd" {
// On FreeBSD, the namespace is stored separately from the xattr
switch runtime.GOOS {
case "freebsd", "netbsd":
// On FreeBSD and NetBSD, the namespace is stored separately from the xattr
// name and Listxattr doesn't return the namespace prefix.
xattrWant = strings.TrimPrefix(xattrWant, "user.")
}
found := false
for _, name := range xattrs {
if name == xattrWant {
found = true
break
}
}

if !found {
t.Errorf("Flistxattr did not return previously set attribute '%s'", xattrName)
t.Errorf("Flistxattr did not return previously set attribute %q in attributes %v", xattrName, xattrs)
}

// find size
Expand Down

0 comments on commit 30de352

Please sign in to comment.