Skip to content

Commit 18e4e13

Browse files
committed
[Filesystem]: rm(; recursive=true) should ignore UV_EACCES
The command-line program `rm` has no problem deleting an empty directory that we do not have listing permissions on, so we should follow suit. Example: ``` mktempdir() do dir mkpath("$(dir)/foo") chmod("$(dir)/foo", 0o200) rm(dir; recursive=true) end ```
1 parent 83592cf commit 18e4e13

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

base/file.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ function rm(path::AbstractString; force::Bool=false, recursive::Bool=false)
294294
rm(joinpath(path, p), force=force, recursive=true)
295295
end
296296
catch err
297-
if !(force && isa(err, IOError) && err.code==Base.UV_EACCES)
297+
if !(isa(err, IOError) && err.code==Base.UV_EACCES)
298298
rethrow(err)
299299
end
300300
end

test/file.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,11 +1520,11 @@ if !Sys.iswindows()
15201520
chmod(joinpath(d, "empty_outer", "empty_inner"), 0o333)
15211521

15221522
# Test that an empty directory, even when we can't read its contents, is deletable
1523-
rm(joinpath(d, "empty_outer"); recursive=true, force=true)
1523+
rm(joinpath(d, "empty_outer"); recursive=true)
15241524
@test !isdir(joinpath(d, "empty_outer"))
15251525

15261526
# But a non-empty directory is not
1527-
@test_throws Base.IOError rm(joinpath(d, "nonempty"); recursive=true, force=true)
1527+
@test_throws Base.IOError rm(joinpath(d, "nonempty"); recursive=true)
15281528
chmod(joinpath(d, "nonempty"), 0o777)
15291529
rm(joinpath(d, "nonempty"); recursive=true, force=true)
15301530
@test !isdir(joinpath(d, "nonempty"))

0 commit comments

Comments
 (0)