brew cleanup: don't remove higher version kegs.

* Use version compare to only remove kegs with lower version than the
  current one, not higher version which might be from someone's
  branch.
* Do the same for cache cleanup.
  - Be conservative so that if a name detected from cache file is not
    the same as its formula then don't clean it.

Closes Homebrew/homebrew#15914.

Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
This commit is contained in:
Xiyue Deng 2012-11-08 02:19:05 -08:00 committed by Mike McQuaid
parent 9c294364c6
commit 2a1ec18ff9

View File

@ -33,7 +33,7 @@ module Homebrew extend self
if f.installed? and f.rack.directory?
f.rack.children.each do |keg|
if f.installed_prefix != keg
if f.version > Keg.new(keg).version
if f.can_cleanup?
if ARGV.dry_run?
puts "Would remove: #{keg}"
@ -61,7 +61,7 @@ module Homebrew extend self
if name and version
f = Formula.factory(name) rescue nil
old_bottle = bottle_file_outdated? f, pn
if not f or (f.version != version or ARGV.switch? "s" and not f.installed?) or old_bottle
if (f and f.version > version) or (ARGV.switch? "s" and (f and (not f.installed?))) or old_bottle
if ARGV.dry_run?
puts "Would remove: #{pn}"
else