diff --git a/Library/Homebrew/cmd/uninstall.rb b/Library/Homebrew/cmd/uninstall.rb index 8a5c4baba4..0dbdc08c4b 100644 --- a/Library/Homebrew/cmd/uninstall.rb +++ b/Library/Homebrew/cmd/uninstall.rb @@ -6,23 +6,10 @@ module Homebrew def uninstall raise KegUnspecifiedError if ARGV.named.empty? - # Find symlinks that can point to keg.rack - links = HOMEBREW_CELLAR.subdirs.select(&:symlink?) - if !ARGV.force? ARGV.kegs.each do |keg| keg.lock do puts "Uninstalling #{keg}... (#{keg.abv})" - - old_cellars = [] - # Remove every symlink that links to keg, because it can - # be left by migrator - links.each do |link| - if link.exist? && link.realpath == keg.rack.realpath - old_cellars << link - end - end - keg.unlink keg.uninstall rack = keg.rack @@ -33,10 +20,6 @@ module Homebrew verb = versions.length == 1 ? "is" : "are" puts "#{keg.name} #{versions.join(", ")} #{verb} still installed." puts "Remove them all with `brew uninstall --force #{keg.name}`." - else - # If we delete Cellar/newname, then Cellar/oldname symlink - # can become broken and we have to remove it. - old_cellars.each(&:unlink) end end end @@ -45,10 +28,6 @@ module Homebrew rack = Formulary.to_rack(name) name = rack.basename - links.each do |link| - link.unlink if link.exist? && link.realpath == rack.realpath - end - if rack.directory? puts "Uninstalling #{name}... (#{rack.abv})" rack.subdirs.each do |d| @@ -64,6 +43,12 @@ module Homebrew rescue MultipleVersionsInstalledError => e ofail e puts "Use `brew uninstall --force #{e.name}` to remove all versions." + ensure + # If we delete Cellar/newname, then Cellar/oldname symlink + # can become broken and we have to remove it. + HOMEBREW_CELLAR.children.each do |rack| + rack.unlink if rack.symlink? && !rack.resolved_path_exists? + end end def rm_pin(rack)