]> Cypherpunks repositories - gostls13.git/commitdiff
os: remove read-only directories in RemoveAll on Windows
authorConstantin Konstantinidis <constantinkonstantinidis@gmail.com>
Sat, 26 Oct 2019 18:01:47 +0000 (20:01 +0200)
committerIan Lance Taylor <iant@golang.org>
Mon, 28 Oct 2019 22:00:19 +0000 (22:00 +0000)
Remove skipping of TestRemoveUnreadableDir on Windows.

Fixes #26295

Change-Id: I364a3caa55406c855ece807759f6298f7e4ddf1e
Reviewed-on: https://go-review.googlesource.com/c/go/+/203599
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/os/removeall_noat.go
src/os/removeall_test.go

index 32673c0ab003a70a416762107c766c874cba55d3..953c4a27153b6fecbd8d6216ce8153323c335582 100644 (file)
@@ -8,6 +8,7 @@ package os
 
 import (
        "io"
+       "runtime"
        "syscall"
 )
 
@@ -127,6 +128,13 @@ func removeAll(path string) error {
        if err1 == nil || IsNotExist(err1) {
                return nil
        }
+       if runtime.GOOS == "windows" && IsPermission(err1) {
+               if fs, err := Stat(path); err == nil {
+                       if err = Chmod(path, FileMode(0200 | int(fs.Mode()))); err == nil {
+                               err1 = Remove(path)
+                       }
+               }
+       }
        if err == nil {
                err = err1
        }
index 1fa0dcdd33a7e5c825b99be50a9404d58a36316b..0bf35751ce71931a91213ce53e17e1a6ad1c6735 100644 (file)
@@ -378,7 +378,7 @@ func TestRemoveAllButReadOnlyAndPathError(t *testing.T) {
 
 func TestRemoveUnreadableDir(t *testing.T) {
        switch runtime.GOOS {
-       case "js", "windows":
+       case "js":
                t.Skipf("skipping test on %s", runtime.GOOS)
        }