Skip to content

Commit

Permalink
[Fix #10766] Use the path given by --cache-root to be the parent fo…
Browse files Browse the repository at this point in the history
…r `rubocop_cache` dir like other ways to specify it
  • Loading branch information
nobuyo committed Apr 1, 2023
1 parent a677975 commit a822fee
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#10766](https://github.com/rubocop/rubocop/issues/10766): Use the path given by `--cache-root` to be the parent for `rubocop_cache` dir like other ways to specify it. ([@nobuyo][])
2 changes: 1 addition & 1 deletion lib/rubocop/result_cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def self.allow_symlinks_in_cache_location?(config_store)
attr :path

def initialize(file, team, options, config_store, cache_root = nil)
cache_root ||= options[:cache_root]
cache_root ||= File.join(options[:cache_root], 'rubocop_cache') if options[:cache_root]
cache_root ||= ResultCache.cache_root(config_store)
@allow_symlinks_in_cache_location =
ResultCache.allow_symlinks_in_cache_location?(config_store)
Expand Down
28 changes: 27 additions & 1 deletion spec/rubocop/result_cache_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def abs(path)
it 'takes the cache_root from the options' do
cache2 = described_class.new(file, team, { cache_root: 'some/path' }, config_store)

expect(cache2.path).to start_with('some/path')
expect(cache2.path).to start_with('some/path/rubocop_cache')
end
end

Expand Down Expand Up @@ -362,6 +362,14 @@ def abs(path)
cacheroot = described_class.cache_root(config_store)
expect(cacheroot).to eq(File.join(Dir.home, '.cache', 'rubocop_cache'))
end

it 'contains the root in path only once' do
cache = described_class.new(file, team, options, config_store)
expect(cache.path).to start_with(File.join(Dir.home, '.cache', 'rubocop_cache'))

count = cache.path.scan(/rubocop_cache/).count
expect(count).to eq(1)
end
end

context 'and XDG_CACHE_HOME is set' do
Expand All @@ -378,6 +386,16 @@ def abs(path)
cacheroot = described_class.cache_root(config_store)
expect(cacheroot).to eq(File.join(ENV.fetch('XDG_CACHE_HOME'), puid, 'rubocop_cache'))
end

it 'contains the root in path only once' do
cache = described_class.new(file, team, options, config_store)
expect(cache.path).to start_with(
File.join(ENV.fetch('XDG_CACHE_HOME'), puid, 'rubocop_cache')
)

count = cache.path.scan(/rubocop_cache/).count
expect(count).to eq(1)
end
end
end

Expand All @@ -403,6 +421,14 @@ def abs(path)
cacheroot = described_class.cache_root(config_store)
expect(cacheroot).to eq(File.join('/tmp/cache-from-env', 'rubocop_cache'))
end

it 'contains the root in path only once' do
cache = described_class.new(file, team, options, config_store)
expect(cache.path).to start_with(File.join('/tmp/cache-from-env', 'rubocop_cache'))

count = cache.path.scan(/rubocop_cache/).count
expect(count).to eq(1)
end
end
end
end
Expand Down

0 comments on commit a822fee

Please sign in to comment.