Skip to content

Commit

Permalink
[Fix rubocop#3242] Ignore cache files disappearing during cleanup eve…
Browse files Browse the repository at this point in the history
…n more (rubocop#3975)

We already ignore `Errno::ENOENT` during the removal, but `File.mtime`
might raise too.
  • Loading branch information
mikegee authored and bbatsov committed Jan 28, 2017
1 parent bfd9be5 commit 1c0cf57
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* [#2643](https://github.com/bbatsov/rubocop/issues/2643): Allow uppercase and dashes in `MagicComment`. ([@mikegee][])
* [#3959](https://github.com/bbatsov/rubocop/issues/3959): Don't wrap "percent arrays" with extra brackets when autocorrecting `Style/MutableConstant`. ([@mikegee][])
* [#3978](https://github.com/bbatsov/rubocop/pull/3978): Fix false positive in `Performance/RegexpMatch` with `English` module. ([@pocke][])
* [#3242](https://github.com/bbatsov/rubocop/issues/3242): Ignore `Errno::ENOENT` during cache cleanup from `File.mtime` too. ([@mikegee][])

## 0.47.1 (2017-01-18)

Expand Down
12 changes: 6 additions & 6 deletions lib/rubocop/result_cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,20 @@ def remove_oldest_files(files, dirs, cache_root, verbose)
puts "Removing the #{remove_count} oldest files from #{cache_root}"
end
sorted = files.sort_by { |path| File.mtime(path) }
remove_files(sorted, dirs, remove_count, verbose)
remove_files(sorted, dirs, remove_count)
rescue Errno::ENOENT
# This can happen if parallel RuboCop invocations try to remove the
# same files. No problem.
puts $ERROR_INFO if verbose
end

def remove_files(files, dirs, remove_count, verbose)
def remove_files(files, dirs, remove_count)
# Batch file deletions, deleting over 130,000+ files will crash
# File.delete.
files[0, remove_count].each_slice(10_000).each do |files_slice|
File.delete(*files_slice)
end
dirs.each { |dir| Dir.rmdir(dir) if Dir["#{dir}/*"].empty? }
rescue Errno::ENOENT
# This can happen if parallel RuboCop invocations try to remove the
# same files. No problem.
puts $ERROR_INFO if verbose
end
end

Expand Down

0 comments on commit 1c0cf57

Please sign in to comment.