Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup: better handle edge cases. #5638

Merged
merged 1 commit into from
Jan 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 8 additions & 5 deletions Library/Homebrew/cleanup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,13 @@ def periodic_clean!
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
Expand Down Expand Up @@ -221,8 +221,9 @@ def unremovable_kegs
@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)
Expand Down Expand Up @@ -275,6 +276,8 @@ def cleanup_unreferenced_downloads
# Skip incomplete downloads which are still in progress.
next
end
elsif download.directory?
FileUtils.rm_rf download
else
download.unlink
end
Expand Down
10 changes: 6 additions & 4 deletions Library/Homebrew/formula.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1924,7 +1924,7 @@ def system(cmd, *args)
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)
Expand All @@ -1945,9 +1945,9 @@ def eligible_kegs_for_cleanup
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
Expand All @@ -1957,7 +1957,9 @@ def eligible_kegs_for_cleanup
# 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
Expand Down
2 changes: 2 additions & 0 deletions Library/Homebrew/keg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@ def uninstall
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)
Expand Down