Fix FileUtils.rm_rf to only mask exceptions about non existent files#58
Conversation
|
Apparently my changes broke the JRuby CI, I'll have a look. |
|
I'm thinking maybe an alternative fix would be to try give the folder executable permissions before trying to remove it? |
baedd10 to
dd8b954
Compare
FileUtils.rm_rf fail when it doesn't remove the folderFileUtils.rm_rf when target folder is not empty and has no executable permission set
dd8b954 to
2860e88
Compare
|
Alright, I changed the approach to automatically try fixing permissions in this particular case, because:
|
|
For JRuby I had to add some special code, because it raises a different error from CRuby. Issue is already reported upstream: jruby/jruby#5617. |
74d957d to
e53e336
Compare
e53e336 to
5649416
Compare
|
Alright, I changed my mind again on this. I think The bug reported still stands, and I think my original approach would be best, so I'll go back to that. |
ff13121 to
c702105
Compare
FileUtils.rm_rf when target folder is not empty and has no executable permission setFileUtils.rm_rf to only mask exceptions about non existent files
|
I reencountered an issue related to this. I was debugging a dependabot spec failure on Bundler 1.x + Ruby 3.1, and it was very hard to debug because the underlying issue ended up being a So a
was being raised, but then swallowed, and the error was happening later on on a completely unrelated place, due to the spec assuming removal had happened successfully. So, I changed this PR to only mask the errors about non existent files when the force flag is given. This matches exactly
|
Luckily the bad permissions were not having any effect in the test because empty directories can always be removed, but 700 is a decimal number which is 1274 in octal, which means no executable permissions for the user, which is unintended here.
c702105 to
2f0a8c3
Compare
2f0a8c3 to
27a88c0
Compare
|
Sorry for the ping, this patch still has some issues. I'll ping you back once it's ready! |
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.
27a88c0 to
1fb73bf
Compare
|
Ok, so I run this code with RubyGems tests and it detected a couple of issues in the tests. See ruby/rubygems#5475. I also run this changeset against So, this change could break some tests, but in my opinion, it will be for good because it will help detect issues. Given that, I see a couple of options:
I haven't get any feedback at all so far, so I will wait a few days and then bring it to ruby-core. |
|
Looks good to me, indeed swallowing exceptions in gems/libraries leads to nasty hard-to-debug bugs and I think hurts more than help. |
|
I found a better alternative to be able to see the original exception that does not require any changes in So I'm closing this PR given it has been ignored for a long time. |
| end | ||
| end | ||
| end | ||
| ensure |
There was a problem hiding this comment.
I realized this ensure might have been intentional.
The current behavior is, even if an exception happen, still try to remove the given folder (and most likely get a Errno::ENOTEMPTY exception, because the original exception probably prevented some of the files inside to be removed). In that case, the original exception is still reported as the exception cause.
In Bundler, I was not seeing the original error because we're failing to report the cause if it exists in a couple of places, but I will fix this in Bundler.
This is all to say that, if the behavior I proposed is to be implemented, we might still want to restore this ensure.
|
One issue with |
|
Yeah, when I said "better alternative" I meant to what I'm doing now (rechecking whether the folder still exists after |
|
I do agree that It seems like it would be more useful, if it ignored does not exist errors (and warned about I wonder why this issue has went ignored, as it seems like a high value thing to fix. Sure |
|
It didn't go ignored, it just took a lot to discuss it because people are busy. But as I said somewhere else, it actually got some traction, see #99. |
This is one idea to fix #57.
I think this is a bug, so I didn't care about backwards compatibility. In my opinion, any code forcefully removing a folder expects the folder to be removed, and if not, it will fail later on, like it happened in
bundler.