aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/os/removeall_at.go11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/os/removeall_at.go b/src/os/removeall_at.go
index a613aeeb91..5ddc1ade61 100644
--- a/src/os/removeall_at.go
+++ b/src/os/removeall_at.go
@@ -8,6 +8,7 @@ package os
import (
"io"
+ "runtime"
"syscall"
)
@@ -34,7 +35,15 @@ func removeAll(path string) error {
// its parent directory
parentDir, base := splitPath(path)
- parent, err := Open(parentDir)
+ flag := O_RDONLY
+ if runtime.GOOS == "windows" {
+ // On Windows, the process might not have read permission on the parent directory,
+ // but still can delete files in it. See https://go.dev/issue/74134.
+ // We can open a file even if we don't have read permission by passing the
+ // O_WRONLY | O_RDWR flag, which is mapped to FILE_READ_ATTRIBUTES.
+ flag = O_WRONLY | O_RDWR
+ }
+ parent, err := OpenFile(parentDir, flag, 0)
if IsNotExist(err) {
// If parent does not exist, base cannot exist. Fail silently
return nil