Merge pull request #5638 from MikeMcQuaid/cleanup-fixes

cleanup: better handle edge cases.
This commit is contained in:
Mike McQuaid 2019-01-28 17:07:35 +00:00 committed by GitHub
commit cbb62a34f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 9 deletions

View File

@ -178,13 +178,13 @@ module Homebrew
return false unless periodic_clean_due?
ohai "`brew cleanup` has not been run in #{CLEANUP_DEFAULT_DAYS} days, running now..."
clean!
clean!(quiet: true)
end
def clean!
def clean!(quiet: false)
if args.empty?
Formula.installed.sort_by(&:name).each do |formula|
cleanup_formula(formula)
cleanup_formula(formula, quiet: quiet)
end
cleanup_cache
cleanup_logs
@ -221,8 +221,9 @@ module Homebrew
@unremovable_kegs ||= []
end
def cleanup_formula(formula)
formula.eligible_kegs_for_cleanup.each(&method(:cleanup_keg))
def cleanup_formula(formula, quiet: false)
formula.eligible_kegs_for_cleanup(quiet: quiet)
.each(&method(:cleanup_keg))
cleanup_cache(Pathname.glob(cache/"#{formula.name}--*"))
rm_ds_store([formula.rack])
cleanup_lockfiles(FormulaLock.new(formula.name).path)
@ -275,6 +276,8 @@ module Homebrew
# Skip incomplete downloads which are still in progress.
next
end
elsif download.directory?
FileUtils.rm_rf download
else
download.unlink
end

View File

@ -1924,7 +1924,7 @@ class Formula
end
# @private
def eligible_kegs_for_cleanup
def eligible_kegs_for_cleanup(quiet: false)
eligible_for_cleanup = []
if installed?
eligible_kegs = if head? && (head_prefix = latest_head_prefix)
@ -1945,9 +1945,9 @@ class Formula
unless eligible_kegs.empty?
eligible_kegs.each do |keg|
if keg.linked?
opoo "Skipping (old) #{keg} due to it being linked"
opoo "Skipping (old) #{keg} due to it being linked" unless quiet
elsif pinned? && keg == Keg.new(@pin.path.resolved_path)
opoo "Skipping (old) #{keg} due to it being pinned"
opoo "Skipping (old) #{keg} due to it being pinned" unless quiet
else
eligible_for_cleanup << keg
end
@ -1957,7 +1957,9 @@ class Formula
# If the cellar only has one version installed, don't complain
# that we can't tell which one to keep. Don't complain at all if the
# only installed version is a pinned formula.
opoo "Skipping #{full_name}: most recent version #{pkg_version} not installed"
unless quiet
opoo "Skipping #{full_name}: most recent version #{pkg_version} not installed"
end
end
eligible_for_cleanup
end

View File

@ -310,6 +310,8 @@ class Keg
remove_opt_record if optlinked?
remove_old_aliases
remove_oldname_opt_record
rescue Errno::ENOTEMPTY
ofail "Could not remove #{path}! Check its permissions."
end
def unlink(mode = OpenStruct.new)