FileUtils.rm_rf should ignore only Errno::ENOENT, not StandardError#99
Merged
mame merged 3 commits intoruby:masterfrom Aug 23, 2022
Merged
Conversation
The test was added for [Bug #6756]. The ticket insisted `FileUtils.rm_rf` should delete an empty directory even if its permission is 000. However, the test tried to delete a directory with permission 700.
The ensure in postorder_traverse was added for [Bug #6756].
The intention was to try to delete the parent directory if it failed to
get the children. (It may be possible to delete the directory if it is
empty.)
However, the ensure region rescue'ed not only "failure to get children"
but also "failure to delete each child". Thus, the following raised
Errno::ENOTEMPTY, but we expect it to raise Errno::EACCES.
```
$ mkdir foo
$ touch foo/bar
$ chmod 555 foo
$ ruby -rfileutils -e 'FileUtils.rm_rf("foo")'
```
This changeset narrows the ensure region so that it rescues only
"failure to get children".
... instead of any StandardError. To behave like the standard `rm` command, it should only ignore exceptions about not existing files, not every exception. This should make debugging some errors easier, because the expectation is that `rm -rf` will succeed if and only if, all given files (previously existent or not) are removed. However, due to this exception swallowing, this is not always the case. From the `rm` man page > COMPATIBILITY > > The rm utility differs from historical implementations in that the -f > option only masks attempts to remove non-existent files instead of > masking a large variety of errors. Co-Authored-By: David Rodríguez <deivid.rodriguez@riseup.net>
Contributor
|
Thanks a lot for this @mame! This change is very useful for me. Not only fa65d67, but also ec5d3b8. With ec5d3b8, an error like the one I got reported at ruby/rubygems#5274 will go from a error to an |
This was referenced Aug 9, 2022
Member
Author
|
I talked with @aamine, the original author of fileutils, about this change. He was a little concerned about the incompatibility but did not seem to strongly object. https://twitter.com/mineroaoki/status/1555181426722881537 Please let me try this change once. If anyone reports practical problems with this change, I will be responsive to address them (including revert) on a best-effort basis. |
Member
|
Great, thank you! |
|
Great work, thanks! |
k0kubun
added a commit
to ruby/ruby
that referenced
this pull request
Aug 27, 2022
FileUtils.rm_rf started to randomly fail on http://ci.rvm.jp/results/trunk-mjit@phosphorus-docker since around ruby/fileutils#99.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
[Bug #18784]