New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
False positive of NonAtomicFileOperation
for FileUtils.rm_r
#10813
Comments
The offense message is confusing, so we improved the message at #10781 For the following code: # frozen_string_literal: true
FileUtils.rm_r gem_name if Dir.exist? gem_name The following message is output: :
test.rb:3:1: W: Lint/NonAtomicFileOperation: Use atomic file operation method FileUtils.rm_rf.
FileUtils.rm_r gem_name if Dir.exist? gem_name
^^^^^^^^^^^^^^^^^^^^^^^
test.rb:3:25: W: [Correctable] Lint/NonAtomicFileOperation: Remove unnecessary existence check Dir.exist?.
FileUtils.rm_r gem_name if Dir.exist? gem_name
^^^^^^^^^^^^^^^^^^^^^^ Expected changes: # frozen_string_literal: true
- FileUtils.rm_r gem_name if Dir.exist? gem_name
+ FileUtils.rm_rf gem_name |
@ydah thank you, it's a good change. But… |
@AlexWayfer Yes, I also certainly don't think they are strictly equivalent. The reason for adding this cop is that these can cause problems that are difficult to reproduce, especially when frequent file operations are performed in parallel, as in test runs using |
Maybe I'd even preffer a cop which will offense if I have There are just different approaches. And the current default behavior I consider as very agressive and inaccurate. |
…nAtomicFileOperation` Fixes: rubocop#10813 This PR is suppress offense in case of recursive deletion in `Lint/NonAtomicFileOperation`.
From this discussion: #10760 (comment)
Expected behavior
No offenses or no exceptions for
FileUtils.rm_r
.Actual behavior
If I have the code:
it causes offenses by
NonAtomicFileOperation
cop.If I remove the condition — it causes the exception:
Even with
require 'fileutils'
.Steps to reproduce the problem
The code is above.
RuboCop version
The text was updated successfully, but these errors were encountered: