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.
This commit is contained in:
parent
d2a8df71ce
commit
17953f2b83
@ -3,7 +3,6 @@ module Homebrew extend self
|
|||||||
raise KegUnspecifiedError if ARGV.named.empty?
|
raise KegUnspecifiedError if ARGV.named.empty?
|
||||||
|
|
||||||
ARGV.kegs.each do |keg|
|
ARGV.kegs.each do |keg|
|
||||||
return if !keg.linked?
|
|
||||||
print "Unlinking #{keg}... "
|
print "Unlinking #{keg}... "
|
||||||
puts "#{keg.unlink} links removed"
|
puts "#{keg.unlink} links removed"
|
||||||
end
|
end
|
||||||
|
|||||||
@ -29,14 +29,18 @@ class Keg < Pathname
|
|||||||
|
|
||||||
def unlink
|
def unlink
|
||||||
n=0
|
n=0
|
||||||
return n if !linked?
|
|
||||||
|
|
||||||
%w[bin etc lib include sbin share var].map{ |d| self/d }.each do |src|
|
%w[bin etc lib include sbin share var].map{ |d| self/d }.each do |src|
|
||||||
next unless src.exist?
|
next unless src.exist?
|
||||||
src.find do |src|
|
src.find do |src|
|
||||||
next if src == self
|
next if src == self
|
||||||
dst=HOMEBREW_PREFIX+src.relative_path_from(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.uninstall_info if dst.to_s =~ INFOFILE_RX and ENV['HOMEBREW_KEEP_INFO']
|
||||||
dst.unlink
|
dst.unlink
|
||||||
dst.parent.rmdir_if_possible
|
dst.parent.rmdir_if_possible
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user