Skip to content

Commit

Permalink
Filesystem: rm(; recursive=true) should ignore UV_EACCES (#47668)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
staticfloat authored and KristofferC committed Nov 28, 2022
1 parent fb6cf73 commit f44bba8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion base/file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ function rm(path::AbstractString; force::Bool=false, recursive::Bool=false)
rm(joinpath(path, p), force=force, recursive=true)
end
catch err
if !(force && isa(err, IOError) && err.code==Base.UV_EACCES)
if !(isa(err, IOError) && err.code==Base.UV_EACCES)
rethrow(err)
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1519,11 +1519,11 @@ if !Sys.iswindows()
chmod(joinpath(d, "empty_outer", "empty_inner"), 0o333)

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

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

0 comments on commit f44bba8

Please sign in to comment.