2010-09-11 20:22:54 +01:00
|
|
|
require 'formula'
|
|
|
|
require 'cmd/prune'
|
|
|
|
|
|
|
|
module Homebrew extend self
|
2012-03-06 20:12:42 +00:00
|
|
|
|
2010-09-11 20:22:54 +01:00
|
|
|
def cleanup
|
|
|
|
if ARGV.named.empty?
|
|
|
|
HOMEBREW_CELLAR.children.each do |rack|
|
|
|
|
begin
|
|
|
|
cleanup_formula rack.basename.to_s if rack.directory?
|
|
|
|
rescue FormulaUnavailableError => e
|
2011-03-11 13:36:26 -08:00
|
|
|
# Don't complain about Cellar folders that are from DIY installs
|
|
|
|
# instead of core formulae.
|
2010-09-11 20:22:54 +01:00
|
|
|
end
|
|
|
|
end
|
2012-03-06 20:12:42 +00:00
|
|
|
clean_cache
|
2010-09-11 20:22:54 +01:00
|
|
|
# seems like a good time to do some additional cleanup
|
2012-03-06 20:12:42 +00:00
|
|
|
Homebrew.prune unless ARGV.switch? 'n'
|
2010-09-11 20:22:54 +01:00
|
|
|
else
|
|
|
|
ARGV.formulae.each do |f|
|
|
|
|
cleanup_formula f
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def cleanup_formula f
|
|
|
|
f = Formula.factory f
|
|
|
|
|
2011-03-11 13:36:37 -08:00
|
|
|
# Don't clean up keg-only brews for now.
|
|
|
|
# Formulae link directly to them, so cleaning up old
|
|
|
|
# ones will break already compiled software.
|
2011-04-18 21:11:08 -07:00
|
|
|
if f.keg_only? and not ARGV.force?
|
2011-09-11 12:57:53 -07:00
|
|
|
opoo "Skipping keg-only #{f.name}" if f.rack.children.length > 1
|
2011-03-11 13:36:37 -08:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2011-09-11 12:57:53 -07:00
|
|
|
if f.installed? and f.rack.directory?
|
|
|
|
f.rack.children.each do |keg|
|
2010-09-11 20:22:54 +01:00
|
|
|
if f.installed_prefix != keg
|
2012-03-06 20:12:42 +00:00
|
|
|
puts "Removing #{keg}..."
|
|
|
|
rm_rf keg unless ARGV.switch? 'n'
|
2010-09-11 20:22:54 +01:00
|
|
|
end
|
|
|
|
end
|
2011-09-11 12:57:53 -07:00
|
|
|
elsif f.rack.children.length > 1
|
2010-09-11 20:22:54 +01:00
|
|
|
# If the cellar only has one version installed, don't complain
|
|
|
|
# that we can't tell which one to keep.
|
2011-03-11 13:36:26 -08:00
|
|
|
opoo "Skipping #{f.name}: most recent version #{f.version} not installed"
|
2010-09-11 20:22:54 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-03-06 20:12:42 +00:00
|
|
|
def clean_cache
|
|
|
|
HOMEBREW_CACHE.children.each do |pn|
|
2012-03-07 17:13:37 +00:00
|
|
|
next unless pn.file?
|
2012-03-06 20:12:42 +00:00
|
|
|
pn.stem =~ /^(.+)-(.+)$/ # greedy so works even if formula-name has hyphens in it
|
|
|
|
if $1 and $2
|
|
|
|
f = Formula.factory($1) rescue nil
|
|
|
|
if not f or (f.version != $2 or ARGV.switch? "s" and not f.installed?)
|
|
|
|
puts "Removing #{pn}..."
|
|
|
|
rm pn unless ARGV.switch? 'n'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-09-11 20:22:54 +01:00
|
|
|
end
|