aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMisty De Meo2012-07-22 10:49:50 -0500
committerMisty De Meo2012-07-22 10:58:19 -0500
commit66a4ea1c80fa36fe348b3d5ad6d2f6c61cf21c05 (patch)
tree74a860d9bab38e87f31d13153c8c3c1b6bd12122
parent0f73d4227f809345c4d0b202ed6f2bfa5e5c3d21 (diff)
downloadhomebrew-66a4ea1c80fa36fe348b3d5ad6d2f6c61cf21c05.tar.bz2
Keg#unlink: check destination before unlinking
Rather than skip unlinking if there's no linked keg record, check to see whether the destination's realpath is the same as the source file in the keg being unlinked.
-rw-r--r--Library/Homebrew/cmd/unlink.rb1
-rw-r--r--Library/Homebrew/keg.rb8
2 files changed, 6 insertions, 3 deletions
diff --git a/Library/Homebrew/cmd/unlink.rb b/Library/Homebrew/cmd/unlink.rb
index 692278fb0..12b037781 100644
--- a/Library/Homebrew/cmd/unlink.rb
+++ b/Library/Homebrew/cmd/unlink.rb
@@ -3,7 +3,6 @@ module Homebrew extend self
raise KegUnspecifiedError if ARGV.named.empty?
ARGV.kegs.each do |keg|
- return if !keg.linked?
print "Unlinking #{keg}... "
puts "#{keg.unlink} links removed"
end
diff --git a/Library/Homebrew/keg.rb b/Library/Homebrew/keg.rb
index 1e12d712e..0d9a12cc6 100644
--- a/Library/Homebrew/keg.rb
+++ b/Library/Homebrew/keg.rb
@@ -29,14 +29,18 @@ class Keg < Pathname
def unlink
n=0
- return n if !linked?
%w[bin etc lib include sbin share var].map{ |d| self/d }.each do |src|
next unless src.exist?
src.find do |src|
next if src == self
dst=HOMEBREW_PREFIX+src.relative_path_from(self)
- next unless dst.symlink?
+
+ # check whether the file to be unlinked is from the current keg first
+ if !dst.symlink? || !dst.exist? || src.expand_path != dst.realpath
+ next
+ end
+
dst.uninstall_info if dst.to_s =~ INFOFILE_RX and ENV['HOMEBREW_KEEP_INFO']
dst.unlink
dst.parent.rmdir_if_possible