Skip to content
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 Atomic File Operations rule #898

Merged
merged 1 commit into from Jul 26, 2022

Commits on Jun 28, 2022

  1. Add new "Atomic File Operations" rule

    When doing file operations after confirming the existence check of a file,
    frequent parallel file operations may cause problems that are difficult to reproduce.
    Therefore, it is preferable to use atomic file operations.
    
    ```ruby
    # bad - race condition with another process may result in an error in `mkdir`
    unless Dir.exist?(path)
      FileUtils.mkdir(path)
    end
    
    # good - atomic and idempotent creation
    FileUtils.mkdir_p(path)
    
    # bad - race condition with another process may result in an error in `remove`
    if File.exist?(path)
      FileUtils.remove(path)
    end
    
    # good - atomic and idempotent removal
    FileUtils.rm_f(path)
    ```
    ydah committed Jun 28, 2022
    Configuration menu
    Copy the full SHA
    67cbf7f View commit details
    Browse the repository at this point in the history