Handle conflicts where links point at symlinks

Fixes Homebrew/homebrew#30664.
This commit is contained in:
Jack Nagel 2014-07-12 19:56:58 -05:00
parent 7b26c885bd
commit 1eafe3bc35
2 changed files with 22 additions and 5 deletions

View File

@ -322,11 +322,12 @@ class Keg
private
def resolve_any_conflicts dst, mode
# if it isn't a directory then a severe conflict is about to happen. Let
# it, and the exception that is generated will message to the user about
# the situation
if dst.symlink? and dst.directory?
src = dst.resolved_path
src = dst.resolved_path
# src itself may be a symlink, so check lstat to ensure we are dealing with
# a directory, and not a symlink pointing at a directory (which needs to be
# treated as a file). In other words, we onlly want to resolve one symlink.
# If it isn't a directory, make_relative_symlink will raise an exception.
if dst.symlink? && src.lstat.directory?
keg = Keg.for(src)
dst.unlink unless mode.dry_run
keg.link_dir(src, mode) { :mkpath }

View File

@ -217,4 +217,20 @@ class LinkTests < Homebrew::TestCase
assert_predicate link.resolved_path, :symlink?
assert_predicate link.lstat, :symlink?
end
def test_links_to_symlinks_are_not_removed
a = HOMEBREW_CELLAR.join("a", "1.0")
b = HOMEBREW_CELLAR.join("b", "1.0")
a.join("lib", "example").mkpath
a.join("lib", "example2").make_symlink "example"
b.join("lib", "example2").mkpath
Keg.new(a).link
lib = HOMEBREW_PREFIX.join("lib")
assert_equal 2, lib.children.length
assert_raises(Keg::ConflictError) { Keg.new(b).link }
assert_equal 2, lib.children.length
end
end