Skip to content
Snippets Groups Projects
Commit 55e0f40d authored by Jack Nagel's avatar Jack Nagel
Browse files

Handle broken symlinks in resolve_any_conflicts

Fixes Homebrew/homebrew#33328.
parent 05ba3f0e
No related branches found
No related tags found
No related merge requests found
......@@ -328,11 +328,20 @@ class Keg
return unless dst.symlink?
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 only want to resolve one symlink.
# If it isn't a directory, make_relative_symlink will raise an exception.
if src.lstat.directory?
begin
stat = src.lstat
rescue Errno::ENOENT
# dst is a broken symlink, so remove it.
dst.unlink unless mode.dry_run
return
end
if stat.directory?
keg = Keg.for(src)
dst.unlink unless mode.dry_run
keg.link_dir(src, mode) { :mkpath }
......
......@@ -239,4 +239,20 @@ class LinkTests < Homebrew::TestCase
a.uninstall
b.uninstall
end
def test_removes_broken_symlinks_that_conflict_with_directories
a = HOMEBREW_CELLAR.join("a", "1.0")
a.join("lib", "foo").mkpath
keg = Keg.new(a)
link = HOMEBREW_PREFIX.join("lib", "foo")
link.parent.mkpath
link.make_symlink(@nonexistent)
keg.link
ensure
keg.unlink
keg.uninstall
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment