Skip to content

Commit

Permalink
Reduce output of pruning process
Browse files Browse the repository at this point in the history
  • Loading branch information
zachfeldman committed Oct 18, 2022
1 parent a32816d commit e082855
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
11 changes: 1 addition & 10 deletions lib/erb_lint/cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,17 @@ def close
end

def prune_cache
puts "File names pruned from the cache will be logged"
if hits.empty?
puts "Cache being created for the first time, skipping prune"
return
end

cache_files = Dir.new(CACHE_DIRECTORY).children
cache_files.each do |cache_file|
next if hits.include?(cache_file)
next if hits.include?(cache_file) || new_results.include?(cache_file)

if new_results.include?(cache_file)
puts "Skipping deletion of new cache result #{cache_file}"
next
end

puts "Cleaning deleted cached file with checksum #{cache_file}"
File.delete(File.join(CACHE_DIRECTORY, cache_file))
end

@hits = []
end

def cache_dir_exists?
Expand Down
4 changes: 2 additions & 2 deletions spec/erb_lint/cache_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
allow(fakefs_dir).to(receive(:children).and_return([checksum]))
allow(FakeFS::Dir).to(receive(:new).and_return(fakefs_dir))

expect { cache.prune_cache }.to(output(/.*Skipping deletion of new cache result #{checksum}/).to_stdout)
cache.prune_cache

expect(File.exist?(
File.join(
Expand All @@ -132,7 +132,7 @@
f.write(cache_file_content)
end

expect { cache.prune_cache }.to(output(/Cleaning deleted cached file with checksum fake-checksum/).to_stdout)
cache.prune_cache

expect(File.exist?(
File.join(
Expand Down

0 comments on commit e082855

Please sign in to comment.