summaryrefslogtreecommitdiff
path: root/internal/syscallcompat/sys_common_test.go
diff options
context:
space:
mode:
authorSebastian Lackner2019-01-14 02:38:34 +0100
committerrfjakob2019-01-14 21:27:28 +0100
commit229a9da74bc0839e2cd481f701c877708b080ede (patch)
treea1eed605271537ce53b76038b51bc0decf9ddf0b /internal/syscallcompat/sys_common_test.go
parent42bf6d1c68700a0d5d910c1be42088cc14125fec (diff)
syscallcompat: Drop Unlinkat emulation on macOS.
Diffstat (limited to 'internal/syscallcompat/sys_common_test.go')
-rw-r--r--internal/syscallcompat/sys_common_test.go55
1 files changed, 55 insertions, 0 deletions
diff --git a/internal/syscallcompat/sys_common_test.go b/internal/syscallcompat/sys_common_test.go
index 3e38eb2..4556279 100644
--- a/internal/syscallcompat/sys_common_test.go
+++ b/internal/syscallcompat/sys_common_test.go
@@ -5,6 +5,8 @@ import (
"os"
"syscall"
"testing"
+
+ "golang.org/x/sys/unix"
)
func TestReadlinkat(t *testing.T) {
@@ -100,6 +102,59 @@ func TestRenameat(t *testing.T) {
}
}
+func TestUnlinkat(t *testing.T) {
+ os.Mkdir(tmpDir+"/unlink1", 0700)
+ dirfd, err := os.Open(tmpDir + "/unlink1")
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer dirfd.Close()
+ // Try to delete file
+ fd, err := os.Create(tmpDir + "/unlink1/f1")
+ if err != nil {
+ t.Fatal(err)
+ }
+ fd.Close()
+ err = Unlinkat(int(dirfd.Fd()), "f1", 0)
+ if err != nil {
+ t.Fatal(err)
+ }
+ _, err = os.Stat(tmpDir + "/unlink1/f1")
+ if err == nil {
+ t.Fatalf("file not deleted!")
+ }
+ // Try to delete dir
+ err = os.Mkdir(tmpDir+"/unlink1/d1", 0700)
+ if err != nil {
+ t.Fatal(err)
+ }
+ err = Unlinkat(int(dirfd.Fd()), "d1", 0)
+ if err == nil {
+ t.Fatalf("this should fail due to missing AT_REMOVEDIR flag")
+ }
+ err = Unlinkat(int(dirfd.Fd()), "d1", unix.AT_REMOVEDIR)
+ if err != nil {
+ t.Fatal(err)
+ }
+ _, err = os.Stat(tmpDir + "/unlink1/d1")
+ if err == nil {
+ t.Fatalf("dir not deleted!")
+ }
+ // Test with absolute path
+ err = os.Mkdir(tmpDir+"/unlink1/d1", 0700)
+ if err != nil {
+ t.Fatal(err)
+ }
+ err = Unlinkat(-1, tmpDir+"/unlink1/d1", unix.AT_REMOVEDIR)
+ if err != nil {
+ t.Fatal(err)
+ }
+ _, err = os.Stat(tmpDir + "/unlink1/d1")
+ if err == nil {
+ t.Fatalf("dir not deleted!")
+ }
+}
+
func TestFchmodat(t *testing.T) {
regular := "TestFchmodat_Regular"
f, err := os.OpenFile(tmpDir+"/"+regular, os.O_CREATE|os.O_WRONLY, 0000)