mirror of
https://github.com/golang/go
synced 2024-11-18 02:04:45 -07:00
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: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
87cc56718a
commit
c74659290a
@ -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) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user