2010-09-11 20:22:54 +01:00
|
|
|
require 'formula'
|
|
|
|
require 'cmd/prune'
|
|
|
|
|
|
|
|
module Homebrew extend self
|
|
|
|
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
|
|
|
|
# seems like a good time to do some additional cleanup
|
|
|
|
Homebrew.prune
|
|
|
|
else
|
|
|
|
ARGV.formulae.each do |f|
|
|
|
|
cleanup_formula f
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def cleanup_formula f
|
|
|
|
f = Formula.factory f
|
|
|
|
rack = f.prefix.parent
|
|
|
|
|
|
|
|
if f.installed? and rack.directory?
|
|
|
|
rack.children.each do |keg|
|
|
|
|
if f.installed_prefix != keg
|
|
|
|
print "Uninstalling #{keg}..."
|
|
|
|
rm_rf keg
|
|
|
|
puts
|
|
|
|
end
|
|
|
|
end
|
|
|
|
elsif rack.children.length > 1
|
|
|
|
# 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
|
|
|
|
|
|
|
|
end
|