mirror of
https://github.com/rwinkhart/sys.git
synced 2026-09-06 00:57:18 -04:00
unix: add symlink-safe *xattr functions on darwin
Updates golang/go#14456 Change-Id: I04632ef1d302e938a2cc373eb90f600f01404380 Reviewed-on: https://go-review.googlesource.com/114198 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
committed by
Tobias Klauser
parent
f3b0f5faf5
commit
77b0e43150
@@ -7,6 +7,7 @@
|
||||
package unix_test
|
||||
|
||||
import (
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -89,4 +90,29 @@ func TestXattr(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Removexattr: %v", err)
|
||||
}
|
||||
|
||||
n := "nonexistent"
|
||||
err = unix.Lsetxattr(n, xattrName, []byte(xattrDataSet), 0)
|
||||
if err != unix.ENOENT {
|
||||
t.Errorf("Lsetxattr: expected %v on non-existent file, got %v", unix.ENOENT, err)
|
||||
}
|
||||
|
||||
_, err = unix.Lgetxattr(n, xattrName, nil)
|
||||
if err != unix.ENOENT {
|
||||
t.Errorf("Lgetxattr: %v", err)
|
||||
}
|
||||
|
||||
s := "symlink1"
|
||||
err = os.Symlink(n, s)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Linux doesn't support xattrs on symlink according to xattr(7), so
|
||||
// just test that we get the proper errors.
|
||||
|
||||
err = unix.Lsetxattr(s, xattrName, []byte(xattrDataSet), 0)
|
||||
if err != nil && (runtime.GOOS != "linux" || err != unix.EPERM) {
|
||||
t.Fatalf("Lsetxattr: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user