Code review changes

This commit is contained in:
Douglas Eichelberger 2023-03-27 09:28:27 -07:00
parent eaeceda31e
commit a7b80532bf
2 changed files with 121 additions and 122 deletions

View File

@ -15,7 +15,6 @@ module Homebrew
CLEANUP_DEFAULT_DAYS = Homebrew::EnvConfig.cleanup_periodic_full_days.to_i.freeze
private_constant :CLEANUP_DEFAULT_DAYS
module PathnameUtils
class << self
extend T::Sig
@ -139,7 +138,6 @@ module Homebrew
false
end
end
end
extend Predicable
@ -192,9 +190,10 @@ module Homebrew
end
def self.skip_clean_formula?(formula)
return false if Homebrew::EnvConfig.no_cleanup_formulae.blank?
no_cleanup_formula = Homebrew::EnvConfig.no_cleanup_formulae
return false if no_cleanup_formula.blank?
@skip_clean_formulae ||= T.must(Homebrew::EnvConfig.no_cleanup_formulae).split(",")
@skip_clean_formulae ||= no_cleanup_formula.split(",")
@skip_clean_formulae.include?(formula.name) || (@skip_clean_formulae & formula.aliases).present?
end
@ -315,7 +314,7 @@ module Homebrew
logs_days = [days, CLEANUP_DEFAULT_DAYS].min
HOMEBREW_LOGS.subdirs.each do |dir|
cleanup_path(dir) { dir.rmtree } if PathnameUtils.prune?(dir, logs_days)
cleanup_path(dir) { dir.rmtree } if self.class.prune?(dir, logs_days)
end
end
@ -331,7 +330,7 @@ module Homebrew
.map(&:resolved_path)
(downloads - referenced_downloads).each do |download|
if PathnameUtils.incomplete?(download)
if self.class.incomplete?(download)
begin
LockFile.new(download.basename).with_lock do
download.unlink
@ -354,11 +353,11 @@ module Homebrew
entries.each do |path|
next if path == PERIODIC_CLEAN_FILE
FileUtils.chmod_R 0755, path if PathnameUtils.go_cache_directory?(path) && !dry_run?
next cleanup_path(path) { path.unlink } if PathnameUtils.incomplete?(path)
next cleanup_path(path) { FileUtils.rm_rf path } if PathnameUtils.nested_cache?(path)
FileUtils.chmod_R 0755, path if self.class.go_cache_directory?(path) && !dry_run?
next cleanup_path(path) { path.unlink } if self.class.incomplete?(path)
next cleanup_path(path) { FileUtils.rm_rf path } if self.class.nested_cache?(path)
if PathnameUtils.prune?(path, days)
if self.class.prune?(path, days)
if path.file? || path.symlink?
cleanup_path(path) { path.unlink }
elsif path.directory? && path.to_s.include?("--")
@ -368,7 +367,7 @@ module Homebrew
end
# If we've specified --prune don't do the (expensive) .stale? check.
cleanup_path(path) { path.unlink } if !prune? && PathnameUtils.stale?(path, scrub: scrub?)
cleanup_path(path) { path.unlink } if !prune? && self.class.stale?(path, scrub: scrub?)
end
cleanup_unreferenced_downloads
@ -489,7 +488,7 @@ module Homebrew
if child.basename.to_s == "__pycache__"
child.find do |path|
next unless path.extname == ".pyc"
next unless PathnameUtils.prune?(path, days)
next unless self.class.prune?(path, days)
unused_pyc_files << path
end

View File

@ -25,7 +25,7 @@ describe Homebrew::Cleanup do
FileUtils.rm_rf HOMEBREW_LIBRARY/"Homebrew"
end
describe "::PathnameUtils.prune?" do
describe "::prune?" do
subject(:path) { HOMEBREW_CACHE/"foo" }
before do
@ -35,11 +35,11 @@ describe Homebrew::Cleanup do
it "returns true when ctime and mtime < days_default" do
allow_any_instance_of(Pathname).to receive(:ctime).and_return((DateTime.now - 2).to_time)
allow_any_instance_of(Pathname).to receive(:mtime).and_return((DateTime.now - 2).to_time)
expect(described_class::PathnameUtils.prune?(path, 1)).to be true
expect(described_class.prune?(path, 1)).to be true
end
it "returns false when ctime and mtime >= days_default" do
expect(described_class::PathnameUtils.prune?(path, 2)).to be false
expect(described_class.prune?(path, 2)).to be false
end
end