Merge pull request #5638 from MikeMcQuaid/cleanup-fixes
cleanup: better handle edge cases.
This commit is contained in:
commit
cbb62a34f5
@ -178,13 +178,13 @@ module Homebrew
|
|||||||
return false unless periodic_clean_due?
|
return false unless periodic_clean_due?
|
||||||
|
|
||||||
ohai "`brew cleanup` has not been run in #{CLEANUP_DEFAULT_DAYS} days, running now..."
|
ohai "`brew cleanup` has not been run in #{CLEANUP_DEFAULT_DAYS} days, running now..."
|
||||||
clean!
|
clean!(quiet: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
def clean!
|
def clean!(quiet: false)
|
||||||
if args.empty?
|
if args.empty?
|
||||||
Formula.installed.sort_by(&:name).each do |formula|
|
Formula.installed.sort_by(&:name).each do |formula|
|
||||||
cleanup_formula(formula)
|
cleanup_formula(formula, quiet: quiet)
|
||||||
end
|
end
|
||||||
cleanup_cache
|
cleanup_cache
|
||||||
cleanup_logs
|
cleanup_logs
|
||||||
@ -221,8 +221,9 @@ module Homebrew
|
|||||||
@unremovable_kegs ||= []
|
@unremovable_kegs ||= []
|
||||||
end
|
end
|
||||||
|
|
||||||
def cleanup_formula(formula)
|
def cleanup_formula(formula, quiet: false)
|
||||||
formula.eligible_kegs_for_cleanup.each(&method(:cleanup_keg))
|
formula.eligible_kegs_for_cleanup(quiet: quiet)
|
||||||
|
.each(&method(:cleanup_keg))
|
||||||
cleanup_cache(Pathname.glob(cache/"#{formula.name}--*"))
|
cleanup_cache(Pathname.glob(cache/"#{formula.name}--*"))
|
||||||
rm_ds_store([formula.rack])
|
rm_ds_store([formula.rack])
|
||||||
cleanup_lockfiles(FormulaLock.new(formula.name).path)
|
cleanup_lockfiles(FormulaLock.new(formula.name).path)
|
||||||
@ -275,6 +276,8 @@ module Homebrew
|
|||||||
# Skip incomplete downloads which are still in progress.
|
# Skip incomplete downloads which are still in progress.
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
elsif download.directory?
|
||||||
|
FileUtils.rm_rf download
|
||||||
else
|
else
|
||||||
download.unlink
|
download.unlink
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1924,7 +1924,7 @@ class Formula
|
|||||||
end
|
end
|
||||||
|
|
||||||
# @private
|
# @private
|
||||||
def eligible_kegs_for_cleanup
|
def eligible_kegs_for_cleanup(quiet: false)
|
||||||
eligible_for_cleanup = []
|
eligible_for_cleanup = []
|
||||||
if installed?
|
if installed?
|
||||||
eligible_kegs = if head? && (head_prefix = latest_head_prefix)
|
eligible_kegs = if head? && (head_prefix = latest_head_prefix)
|
||||||
@ -1945,9 +1945,9 @@ class Formula
|
|||||||
unless eligible_kegs.empty?
|
unless eligible_kegs.empty?
|
||||||
eligible_kegs.each do |keg|
|
eligible_kegs.each do |keg|
|
||||||
if keg.linked?
|
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)
|
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
|
else
|
||||||
eligible_for_cleanup << keg
|
eligible_for_cleanup << keg
|
||||||
end
|
end
|
||||||
@ -1957,7 +1957,9 @@ class Formula
|
|||||||
# If the cellar only has one version installed, don't complain
|
# 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
|
# that we can't tell which one to keep. Don't complain at all if the
|
||||||
# only installed version is a pinned formula.
|
# 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
|
end
|
||||||
eligible_for_cleanup
|
eligible_for_cleanup
|
||||||
end
|
end
|
||||||
|
|||||||
@ -310,6 +310,8 @@ class Keg
|
|||||||
remove_opt_record if optlinked?
|
remove_opt_record if optlinked?
|
||||||
remove_old_aliases
|
remove_old_aliases
|
||||||
remove_oldname_opt_record
|
remove_oldname_opt_record
|
||||||
|
rescue Errno::ENOTEMPTY
|
||||||
|
ofail "Could not remove #{path}! Check its permissions."
|
||||||
end
|
end
|
||||||
|
|
||||||
def unlink(mode = OpenStruct.new)
|
def unlink(mode = OpenStruct.new)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user