From 6a0dcc83240d51f3f8473031cea6c571c5021130 Mon Sep 17 00:00:00 2001 From: Vlad Shablinsky Date: Sun, 9 Aug 2015 14:56:01 +0300 Subject: [PATCH] don't use new name rack if old name rack is a dir Everything that used HOMEBREW_CELLAR/canonical_name could point to something that doesn't exist because loader_for tries to load new name formula if no old name found. However there can be software installed from path with the same name that renamed formulae had and we still need to link/unlink/uninstall etc that software. The solution is Formulary#to_rack method that returns rack for given name. - Add Formulary#to_rack - Update ARGV.kegs - Update cmd/switch --- Library/Homebrew/cmd/switch.rb | 3 +-- Library/Homebrew/extend/ARGV.rb | 12 ++++++------ Library/Homebrew/formulary.rb | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/Library/Homebrew/cmd/switch.rb b/Library/Homebrew/cmd/switch.rb index 5efebd7e5e..b4c3c43d9c 100644 --- a/Library/Homebrew/cmd/switch.rb +++ b/Library/Homebrew/cmd/switch.rb @@ -12,8 +12,7 @@ module Homebrew name = ARGV.shift version = ARGV.shift - canonical_name = Formulary.canonical_name(name) - rack = HOMEBREW_CELLAR.join(canonical_name) + rack = Formulary.to_rack(name) unless rack.directory? onoe "#{name} not found in the Cellar." diff --git a/Library/Homebrew/extend/ARGV.rb b/Library/Homebrew/extend/ARGV.rb index 5a13230ac9..66ff3dfd5a 100644 --- a/Library/Homebrew/extend/ARGV.rb +++ b/Library/Homebrew/extend/ARGV.rb @@ -47,14 +47,14 @@ module HomebrewArgvExtension require "keg" require "formula" @kegs ||= downcased_unique_named.collect do |name| - canonical_name = Formulary.canonical_name(name) - rack = HOMEBREW_CELLAR/canonical_name + rack = Formulary.to_rack(name) + dirs = rack.directory? ? rack.subdirs : [] - raise NoSuchKegError.new(canonical_name) if dirs.empty? + raise NoSuchKegError.new(rack.basename) if dirs.empty? - linked_keg_ref = HOMEBREW_LIBRARY.join("LinkedKegs", canonical_name) - opt_prefix = HOMEBREW_PREFIX.join("opt", canonical_name) + linked_keg_ref = HOMEBREW_LIBRARY.join("LinkedKegs", rack.basename) + opt_prefix = HOMEBREW_PREFIX.join("opt", rack.basename) begin if opt_prefix.symlink? && opt_prefix.directory? @@ -66,7 +66,7 @@ module HomebrewArgvExtension elsif (prefix = (name.include?("/") ? Formulary.factory(name) : Formulary.from_rack(rack)).prefix).directory? Keg.new(prefix) else - raise MultipleVersionsInstalledError.new(canonical_name) + raise MultipleVersionsInstalledError.new(rack.basename) end rescue FormulaUnavailableError raise <<-EOS.undent diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index 4a31b3121e..8fcffb59e0 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -195,6 +195,24 @@ class Formulary end end + def self.to_rack(ref) + name = canonical_name(ref) + rack = HOMEBREW_CELLAR/name + + # Handle the case when ref is an old name and the installation + # hasn't been migrated or when it's a package installed from + # path but same name formula was renamed. + unless rack.directory? + if ref =~ HOMEBREW_TAP_FORMULA_REGEX + rack = HOMEBREW_CELLAR/$3 + elsif !ref.include?("/") + rack = HOMEBREW_CELLAR/ref + end + end + + rack + end + def self.canonical_name(ref) loader_for(ref).name rescue TapFormulaAmbiguityError