Skip to content

Commit

Permalink
Merge pull request #10841 from ChrisBr/cbruckmayer/fix-cache
Browse files Browse the repository at this point in the history
Don't hash shared libraries for cache key
  • Loading branch information
koic committed Aug 4, 2022
2 parents 982159c + 1839d17 commit 382761c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
@@ -0,0 +1 @@
* [#10841](https://github.com/rubocop/rubocop/pull/10841): Don't hash shared libraries for cache key. ([@ChrisBr][])
20 changes: 18 additions & 2 deletions lib/rubocop/result_cache.rb
Expand Up @@ -14,6 +14,12 @@ class ResultCache
fix_layout autocorrect safe_autocorrect autocorrect_all
cache fail_fast stdin parallel].freeze

DL_EXTENSIONS = ::RbConfig::CONFIG
.values_at('DLEXT', 'DLEXT2')
.reject { |ext| !ext || ext.empty? }
.map { |ext| ".#{ext}" }
.freeze

# Remove old files so that the cache doesn't grow too big. When the
# threshold MaxFilesInCache has been exceeded, the oldest 50% of all the
# files in the cache are removed. The reason for removing so much is that
Expand Down Expand Up @@ -174,14 +180,24 @@ def rubocop_checksum
.select { |path| File.file?(path) }
.sort!
.each do |path|
content = File.binread(path)
digest << Zlib.crc32(content).to_s # mtime not reliable
digest << digest(path)
end
digest << RuboCop::Version::STRING << RuboCop::AST::Version::STRING
digest.hexdigest
end
end

def digest(path)
content = if path.end_with?(*DL_EXTENSIONS)
# Shared libraries often contain timestamps of when
# they were compiled and other non-stable data.
File.basename(path)
else
File.binread(path) # mtime not reliable
end
Zlib.crc32(content).to_s
end

def rubocop_extra_features
lib_root = File.join(File.dirname(__FILE__), '..')
exe_root = File.join(lib_root, '..', 'exe')
Expand Down

0 comments on commit 382761c

Please sign in to comment.