Commit c7465929 authored by Baokun Lee's avatar Baokun Lee Committed by Ian Lance Taylor

os: remove unreadable directories in RemoveAll

Fixes #30555

Change-Id: Ib894b4f3cdba23a18a69c9470cf69ceb83591a4d
Reviewed-on: https://go-review.googlesource.com/c/go/+/165057
Run-TryBot: Baokun Lee <nototon@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent 87cc5671
...@@ -92,7 +92,8 @@ func removeAllFrom(parent *File, path string) error { ...@@ -92,7 +92,8 @@ func removeAllFrom(parent *File, path string) error {
if IsNotExist(err) { if IsNotExist(err) {
return nil return nil
} }
return err recurseErr = err
break
} }
names, readErr := file.Readdirnames(request) names, readErr := file.Readdirnames(request)
......
...@@ -372,3 +372,33 @@ func TestRemoveAllButReadOnly(t *testing.T) { ...@@ -372,3 +372,33 @@ func TestRemoveAllButReadOnly(t *testing.T) {
} }
} }
} }
func TestRemoveUnreadableDir(t *testing.T) {
switch runtime.GOOS {
case "nacl", "js", "windows":
t.Skipf("skipping test on %s", runtime.GOOS)
}
if Getuid() == 0 {
t.Skip("skipping test when running as root")
}
t.Parallel()
tempDir, err := ioutil.TempDir("", "TestRemoveAllButReadOnly-")
if err != nil {
t.Fatal(err)
}
defer RemoveAll(tempDir)
target := filepath.Join(tempDir, "d0", "d1", "d2")
if err := MkdirAll(target, 0755); err != nil {
t.Fatal(err)
}
if err := Chmod(target, 0300); err != nil {
t.Fatal(err)
}
if err := RemoveAll(filepath.Join(tempDir, "d0")); err != nil {
t.Fatal(err)
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment