mxcl/homebrew — Issue #10296: `brew upgrade` unlinks incorrect keg
Author: jacknagel
Created: 2012-02-18 05:30:39+00:00
State: open
Labels: bugs

Here's a patch with extra context to illustrate:

```diff
diff --git a/Library/Homebrew/cmd/upgrade.rb b/Library/Homebrew/cmd/upgrade.rb
index f068226..6348caf 100644
--- a/Library/Homebrew/cmd/upgrade.rb
+++ b/Library/Homebrew/cmd/upgrade.rb
@@ -32,12 +32,13 @@ module Homebrew extend self
if outdated.length > 1
oh1 "Upgrading #{outdated.length} outdated package#{outdated.length.plural_s}, with result:"
puts outdated.map{ |f| "#{f.name} #{f.version}" } * ", "
end

outdated.each do |f|
+ puts "The keg that will be unlinked is: #{f.rack}/#{f.version}"
installer = FormulaInstaller.new f
installer.show_header = false
oh1 "Upgrading #{f.name}"
installer.install
Keg.new("#{f.rack}/#{f.version}").unlink
installer.caveats
```

Now

```
$ brew outdated
bash-completion (1.99 < 1.3)
openvpn (2.2.1 < 2.2.2)
poppler (0.18.3 < 0.18.4)

$ brew upgrade openvpn

$ brew upgrade openvpn
The keg that will be unlinked is: /usr/local/Cellar/openvpn/2.2.2
==> Upgrading openvpn
...
```

So we're performing the unlink relative to the new keg (2.2.2) instead of the old keg (2.2.1). For most things this is sufficient as there are usually only a small number of added or removed files between versions, but this should be fixed.

We probably need to resolve the LinkedKegs entry to determine the correct keg to unlink, similar to the fix in FormulaInstaller#install_dependency.