diff options
Diffstat (limited to 'libgo/go/os/removeall_test.go')
-rw-r--r-- | libgo/go/os/removeall_test.go | 52 |
1 files changed, 34 insertions, 18 deletions
diff --git a/libgo/go/os/removeall_test.go b/libgo/go/os/removeall_test.go index 4d556f977e4..8a71f687ed0 100644 --- a/libgo/go/os/removeall_test.go +++ b/libgo/go/os/removeall_test.go @@ -5,7 +5,6 @@ package os_test import ( - "errors" "fmt" "io/ioutil" . "os" @@ -289,7 +288,7 @@ func TestRemoveReadOnlyDir(t *testing.T) { // Issue #29983. func TestRemoveAllButReadOnlyAndPathError(t *testing.T) { switch runtime.GOOS { - case "nacl", "js", "windows": + case "js", "windows": t.Skipf("skipping test on %s", runtime.GOOS) } @@ -379,7 +378,7 @@ func TestRemoveAllButReadOnlyAndPathError(t *testing.T) { func TestRemoveUnreadableDir(t *testing.T) { switch runtime.GOOS { - case "nacl", "js", "windows": + case "js": t.Skipf("skipping test on %s", runtime.GOOS) } @@ -413,14 +412,6 @@ func TestRemoveAllWithMoreErrorThanReqSize(t *testing.T) { t.Skip("skipping in short mode") } - defer func(oldHook func(error) error) { - *RemoveAllTestHook = oldHook - }(*RemoveAllTestHook) - - *RemoveAllTestHook = func(err error) error { - return errors.New("error from RemoveAllTestHook") - } - tmpDir, err := ioutil.TempDir("", "TestRemoveAll-") if err != nil { t.Fatal(err) @@ -429,7 +420,7 @@ func TestRemoveAllWithMoreErrorThanReqSize(t *testing.T) { path := filepath.Join(tmpDir, "_TestRemoveAllWithMoreErrorThanReqSize_") - // Make directory with 1025 files and remove. + // Make directory with 1025 read-only files. if err := MkdirAll(path, 0777); err != nil { t.Fatalf("MkdirAll %q: %s", path, err) } @@ -442,13 +433,38 @@ func TestRemoveAllWithMoreErrorThanReqSize(t *testing.T) { fd.Close() } - // This call should not hang - if err := RemoveAll(path); err == nil { - t.Fatal("Want error from RemoveAllTestHook, got nil") + // Make the parent directory read-only. On some platforms, this is what + // prevents os.Remove from removing the files within that directory. + if err := Chmod(path, 0555); err != nil { + t.Fatal(err) } + defer Chmod(path, 0755) - // We hook to inject error, but the actual files must be deleted - if _, err := Lstat(path); err == nil { - t.Fatal("directory must be deleted even with removeAllTetHook run") + // This call should not hang, even on a platform that disallows file deletion + // from read-only directories. + err = RemoveAll(path) + + if Getuid() == 0 { + // On many platforms, root can remove files from read-only directories. + return + } + if err == nil { + if runtime.GOOS == "windows" { + // Marking a directory as read-only in Windows does not prevent the RemoveAll + // from creating or removing files within it. + return + } + t.Fatal("RemoveAll(<read-only directory>) = nil; want error") + } + + dir, err := Open(path) + if err != nil { + t.Fatal(err) + } + defer dir.Close() + + names, _ := dir.Readdirnames(1025) + if len(names) < 1025 { + t.Fatalf("RemoveAll(<read-only directory>) unexpectedly removed %d read-only files from that directory", 1025-len(names)) } } |