aboutsummaryrefslogtreecommitdiff
path: root/src/os
diff options
context:
space:
mode:
authorqmuntal <quimmuntal@gmail.com>2025-10-21 16:14:03 +0200
committerGopher Robot <gobot@golang.org>2025-10-21 08:45:19 -0700
commitb31dc77ceab962c0f4f5e4a9fc5e1a403fbd2d7c (patch)
tree97656db1b9df385442a3f041e5f2205b9a6d7495 /src/os
parent46cc53290003340877413b8a53511b4f3685d213 (diff)
downloadgo-b31dc77ceab962c0f4f5e4a9fc5e1a403fbd2d7c.tar.xz
os: support deleting read-only files in RemoveAll on older Windows versions
The Windows implementation of RemoveAll supports deleting read-only files only on file systems that supports POSIX semantics and on newer Windows versions (Windows 10 RS5 and latter). For all the other cases, the read-only bit was not clearer before deleting read-only files, so they fail to delete. Note that this case was supported prior to CL 75922, which landed on Go 1.25. Fixes #75922 Change-Id: Id6e6477f42e1952d08318ca3e4ab7c1648969f66 Reviewed-on: https://go-review.googlesource.com/c/go/+/713480 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Damien Neil <dneil@google.com> Auto-Submit: Damien Neil <dneil@google.com>
Diffstat (limited to 'src/os')
-rw-r--r--src/os/path_windows_test.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/os/path_windows_test.go b/src/os/path_windows_test.go
index 3fa02e2a65..eea2b58ee0 100644
--- a/src/os/path_windows_test.go
+++ b/src/os/path_windows_test.go
@@ -236,6 +236,23 @@ func TestRemoveAllLongPathRelative(t *testing.T) {
}
}
+func TestRemoveAllFallback(t *testing.T) {
+ windows.TestDeleteatFallback = true
+ t.Cleanup(func() { windows.TestDeleteatFallback = false })
+
+ dir := t.TempDir()
+ if err := os.WriteFile(filepath.Join(dir, "file1"), []byte{}, 0700); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.WriteFile(filepath.Join(dir, "file2"), []byte{}, 0400); err != nil { // read-only file
+ t.Fatal(err)
+ }
+
+ if err := os.RemoveAll(dir); err != nil {
+ t.Fatal(err)
+ }
+}
+
func testLongPathAbs(t *testing.T, target string) {
t.Helper()
testWalkFn := func(path string, info os.FileInfo, err error) error {