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
```
  • Loading branch information
staticfloat authored Nov 24, 2022
1 parent 726bbd7 commit d0a211a
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 @@ -1520,11 +1520,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

3 comments on commit d0a211a

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the daily package evaluation, I will reply here when finished:

@nanosoldier runtests(ALL, isdaily = true)

@maleadt
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nanosoldier runtests(isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your package evaluation job has completed - possible new issues were detected. A full report can be found here.

Please sign in to comment.