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
Add new Lint/NonAtomicFileOperation
cop
#10696
Conversation
c2a3cf2
to
270ed56
Compare
Lint/UnnecessaryFileCheck
copLint/RedundantFileExistenceCheck
cop
2dfe2da
to
870f5c6
Compare
Lint/RedundantFileExistenceCheck
copLint/RedundantFileExistenceCheck
cop
Lint/RedundantFileExistenceCheck
copLint/RedundantFileExistenceCheck
cop
In this case the P.S. Naming is still hard! :D |
870f5c6
to
5226c6f
Compare
Lint/RedundantFileExistenceCheck
copLint/NonAtomicFileOperation
cop
Naming always annoys me for a long time... |
It's fine by me, but I'll leave this open for a couple of days to see if some of the other maintainers comes up with a better name. It'd be nice if we also mention this in the Ruby style guide, as I doubt many people are aware of this problem. |
5226c6f
to
b4e768f
Compare
Checks for non-atomic file operation. And then replace it with a nearly equivalent and atomic method. These can cause problems that are difficult to reproduce, especially in cases of frequent file operations in parallel, such as test runs with parallel_rspec. For examples: creating a directory if there is none, has the following problems An exception occurs when the directory didn't exist at the time of `exist?`, but someone else created it before `mkdir` was executed. Subsequent processes are executed without the directory that should be there when the directory existed at the time of `exist?`, but someone else deleted it shortly afterwards. ## @safety This cop is unsafe, because autocorrection change to atomic processing. The atomic processing of the replacement destination is not guaranteed to be strictly equivalent to that before the replacement. ## @example ```ruby # bad unless FileTest.exist?(path) FileUtils.makedirs(path) end if FileTest.exist?(path) FileUtils.remove(path) end # good FileUtils.mkdir_p(path) FileUtils.rm_rf(path) ```
b4e768f
to
857709b
Compare
@mathieujobin Can you open a new issue with the bug report template? |
This PR is add new
Lint/NonAtomicFileOperation
copChecks for non-atomic file operations.
And then replace it with a nearly equivalent and atomic method.
These can cause problems that are difficult to reproduce, especially in cases of frequent file operations in parallel, such as test runs with parallel_rspec.
For examples: creating a directory if there is none, has the following problems
An exception occurs when the directory didn't exist at the time of
exist?
, but someone else created it beforemkdir
was executed.Subsequent processes are executed without the directory that should be there when the directory existed at the time of
exist?
, but someone else deleted it shortly afterwards.@safety
This cop is unsafe, because autocorrection change to atomic processing.
The atomic processing of the replacement destination is not guaranteed to be strictly equivalent to that before the replacement.
@example
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).bundle exec rake default
. It executes all tests and runs RuboCop on its own code.{change_type}_{change_description}.md
if the new code introduces user-observable changes. See changelog entry format for details.