From 981605d199d8ed0b83c2c19aea7e3839c56cca9b Mon Sep 17 00:00:00 2001 From: Max Howell Date: Fri, 9 Mar 2012 15:24:58 +0000 Subject: [PATCH] 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. --- Library/Homebrew/cmd/cleanup.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/cmd/cleanup.rb b/Library/Homebrew/cmd/cleanup.rb index ba9745f1aa..3f6471af98 100644 --- a/Library/Homebrew/cmd/cleanup.rb +++ b/Library/Homebrew/cmd/cleanup.rb @@ -51,10 +51,11 @@ module Homebrew extend self def clean_cache HOMEBREW_CACHE.children.each do |pn| next unless pn.file? - 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?) + version = pn.version + name = pn.basename.to_s.match(/(.*)-(#{version})/).captures.first rescue nil + if name and version + f = Formula.factory(name) rescue nil + if not f or (f.version != version or ARGV.switch? "s" and not f.installed?) puts "Removing #{pn}..." rm pn unless ARGV.switch? 'n' end