Keg#unlink: check file comes from the right keg

For real this time.

This makes sure that files won't be unlinked if they resolve into 
other kegs. For example: if fish and fishfish are both installed, 
with fishfish linked and fish unlinked, `brew unlink fish` would 
unlink some files that resolve into fishfish's keg.
This commit is contained in:
Misty De Meo 2012-10-04 08:52:48 -05:00
parent 736717cf24
commit a1f6f590d2

View File

@ -34,7 +34,12 @@ class Keg < Pathname
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 != dst.resolved_path
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
@ -79,6 +84,8 @@ class Keg < Pathname
def link mode=nil def link mode=nil
raise "Cannot link #{fname}\nAnother version is already linked: #{linked_keg_record.realpath}" if linked_keg_record.directory? raise "Cannot link #{fname}\nAnother version is already linked: #{linked_keg_record.realpath}" if linked_keg_record.directory?
# these are used by the ObserverPathnameExtension to count the number
# of files and directories linked
$n=0 $n=0
$d=0 $d=0