Don't let broken symlinks halt linking

This commit is contained in:
Jack Nagel 2014-03-27 09:35:10 -05:00
parent f6b5c83482
commit e9ee640024
2 changed files with 9 additions and 1 deletions

View File

@ -298,7 +298,7 @@ class Pathname
# NOTE only system ln -s will create RELATIVE symlinks # NOTE only system ln -s will create RELATIVE symlinks
quiet_system 'ln', '-s', src.relative_path_from(self.dirname), self.basename quiet_system 'ln', '-s', src.relative_path_from(self.dirname), self.basename
if not $?.success? if not $?.success?
if symlink? && exist? || symlink? if symlink? && exist?
raise <<-EOS.undent raise <<-EOS.undent
Could not symlink file: #{src.expand_path} Could not symlink file: #{src.expand_path}
Target #{self} already exists as a symlink to #{readlink}. Target #{self} already exists as a symlink to #{readlink}.
@ -320,6 +320,9 @@ class Pathname
To list all files that would be deleted: To list all files that would be deleted:
brew link --overwrite --dry-run formula_name brew link --overwrite --dry-run formula_name
EOS EOS
elsif symlink?
unlink
make_relative_symlink(src)
elsif !dirname.writable_real? elsif !dirname.writable_real?
raise <<-EOS.undent raise <<-EOS.undent
Could not symlink file: #{src.expand_path} Could not symlink file: #{src.expand_path}

View File

@ -60,6 +60,11 @@ class LinkTests < Test::Unit::TestCase
end end
end end
def test_link_ignores_broken_symlinks_at_target
ln_s "/some/nonexistent/path", HOMEBREW_PREFIX/"bin/helloworld"
shutup { @keg.link }
end
def test_link_overwrite def test_link_overwrite
touch HOMEBREW_PREFIX/"bin/helloworld" touch HOMEBREW_PREFIX/"bin/helloworld"
@mode.overwrite = true @mode.overwrite = true