mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Handle broken symlinks in resolve_any_conflicts
Fixes Homebrew/homebrew#33328.
This commit is contained in:
parent
05ba3f0e34
commit
55e0f40d02
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user