Don't cleanup the wrong things

This still isn't perfect, but it will handle hyphens in formula-names better now. A proper solution is not easy or maybe even possible unless we ban hyphens in versions AND formula names, or use a different character as a separate in downloaded cache files which we then ban from formula-name and version strings.

Refs Homebrew/homebrew#2923.
This commit is contained in:
Max Howell 2012-03-09 15:24:58 +00:00
parent fc2cc57ce8
commit 981605d199

View File

@ -51,10 +51,11 @@ module Homebrew extend self
def clean_cache def clean_cache
HOMEBREW_CACHE.children.each do |pn| HOMEBREW_CACHE.children.each do |pn|
next unless pn.file? next unless pn.file?
pn.stem =~ /^(.+)-(.+)$/ # greedy so works even if formula-name has hyphens in it version = pn.version
if $1 and $2 name = pn.basename.to_s.match(/(.*)-(#{version})/).captures.first rescue nil
f = Formula.factory($1) rescue nil if name and version
if not f or (f.version != $2 or ARGV.switch? "s" and not f.installed?) f = Formula.factory(name) rescue nil
if not f or (f.version != version or ARGV.switch? "s" and not f.installed?)
puts "Removing #{pn}..." puts "Removing #{pn}..."
rm pn unless ARGV.switch? 'n' rm pn unless ARGV.switch? 'n'
end end