File tree 2 files changed +34
-0
lines changed 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,12 @@ func RemoveAll(path string) error {
25
25
return & PathError {"RemoveAll" , path , syscall .EINVAL }
26
26
}
27
27
28
+ // Simple case: if Remove works, we're done.
29
+ err := Remove (path )
30
+ if err == nil || IsNotExist (err ) {
31
+ return nil
32
+ }
33
+
28
34
// RemoveAll recurses by deleting the path base from
29
35
// its parent directory
30
36
parentDir , base := splitPath (path )
Original file line number Diff line number Diff line change @@ -264,3 +264,31 @@ func TestRemoveAllDotDot(t *testing.T) {
264
264
}
265
265
}
266
266
}
267
+
268
+ // Issue #29178.
269
+ func TestRemoveReadOnlyDir (t * testing.T ) {
270
+ t .Parallel ()
271
+
272
+ tempDir , err := ioutil .TempDir ("" , "TestRemoveReadOnlyDir-" )
273
+ if err != nil {
274
+ t .Fatal (err )
275
+ }
276
+ defer RemoveAll (tempDir )
277
+
278
+ subdir := filepath .Join (tempDir , "x" )
279
+ if err := Mkdir (subdir , 0 ); err != nil {
280
+ t .Fatal (err )
281
+ }
282
+
283
+ // If an error occurs make it more likely that removing the
284
+ // temporary directory will succeed.
285
+ defer Chmod (subdir , 0777 )
286
+
287
+ if err := RemoveAll (subdir ); err != nil {
288
+ t .Fatal (err )
289
+ }
290
+
291
+ if _ , err := Stat (subdir ); err == nil {
292
+ t .Error ("subdirectory was not removed" )
293
+ }
294
+ }
You can’t perform that action at this time.
0 commit comments