Skip to content

Commit f44bba8

Browse files
staticfloatKristofferC
authored andcommitted
Filesystem: rm(; recursive=true) should ignore UV_EACCES (#47668)
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 ``` (cherry picked from commit d0a211a)
1 parent fb6cf73 commit f44bba8

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
@@ -1519,11 +1519,11 @@ if !Sys.iswindows()
15191519
chmod(joinpath(d, "empty_outer", "empty_inner"), 0o333)
15201520

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

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

0 commit comments

Comments
 (0)