From 81d6ec204fcfbcbb617f38b8ee5183080669c066 Mon Sep 17 00:00:00 2001 From: Constantin Konstantinidis Date: Sat, 26 Oct 2019 20:01:47 +0200 Subject: [PATCH] os: remove read-only directories in RemoveAll on Windows 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 TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/os/removeall_noat.go | 8 ++++++++ src/os/removeall_test.go | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/os/removeall_noat.go b/src/os/removeall_noat.go index 32673c0ab0..953c4a2715 100644 --- a/src/os/removeall_noat.go +++ b/src/os/removeall_noat.go @@ -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 } diff --git a/src/os/removeall_test.go b/src/os/removeall_test.go index 1fa0dcdd33..0bf35751ce 100644 --- a/src/os/removeall_test.go +++ b/src/os/removeall_test.go @@ -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) }