aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorDesmond Brand2013-04-27 15:21:17 -0700
committerMisty De Meo2013-05-09 09:21:34 -0500
commitba93e6d3630c6007290567f160a9a16bc17253c5 (patch)
tree453bc109808e02270c4330cf0608da4aad0e7421 /Library
parent4312f94013ccafbd2d6cbda0cf5fec5b7e30d72c (diff)
downloadbrew-ba93e6d3630c6007290567f160a9a16bc17253c5.tar.bz2
Overwrite broken symlinks with --overwrite
Closes Homebrew/homebrew#19480. Signed-off-by: Misty De Meo <mistydemeo@gmail.com>
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/extend/pathname.rb15
-rw-r--r--Library/Homebrew/keg.rb4
-rw-r--r--Library/Homebrew/test/test_keg.rb9
3 files changed, 25 insertions, 3 deletions
diff --git a/Library/Homebrew/extend/pathname.rb b/Library/Homebrew/extend/pathname.rb
index ef7dcea99..25bb1e537 100644
--- a/Library/Homebrew/extend/pathname.rb
+++ b/Library/Homebrew/extend/pathname.rb
@@ -264,7 +264,20 @@ class Pathname
raise <<-EOS.undent
Could not symlink file: #{src.expand_path}
Target #{self} already exists. You may need to delete it.
- To force the link and delete this file, do:
+ To force the link and overwrite all other conflicting files, do:
+ brew link --overwrite formula_name
+
+ To list all files that would be deleted:
+ brew link --overwrite --dry-run formula_name
+ EOS
+ # #exist? will return false for symlinks whose target doesn't exist
+ elsif self.symlink?
+ raise <<-EOS.undent
+ Could not symlink file: #{src.expand_path}
+ Target #{self} already exists as a symlink to #{readlink}.
+ If this file is from another formula, you may need to
+ `brew unlink` it. Otherwise, you may want to delete it.
+ To force the link and overwrite all other conflicting files, do:
brew link --overwrite formula_name
To list all files that would be deleted:
diff --git a/Library/Homebrew/keg.rb b/Library/Homebrew/keg.rb
index 8e774ba85..a63af419d 100644
--- a/Library/Homebrew/keg.rb
+++ b/Library/Homebrew/keg.rb
@@ -194,14 +194,14 @@ class Keg < Pathname
puts "Skipping; already exists: #{dst}" if ARGV.verbose?
# cf. git-clean -n: list files to delete, don't really link or delete
elsif mode.dry_run and mode.overwrite
- puts dst if dst.exist?
+ puts dst if dst.exist? or dst.symlink?
return
# list all link targets
elsif mode.dry_run
puts dst
return
else
- dst.delete if mode.overwrite && dst.exist?
+ dst.delete if mode.overwrite && (dst.exist? or dst.symlink?)
dst.make_relative_symlink src
end
end
diff --git a/Library/Homebrew/test/test_keg.rb b/Library/Homebrew/test/test_keg.rb
index 3081381aa..208d62683 100644
--- a/Library/Homebrew/test/test_keg.rb
+++ b/Library/Homebrew/test/test_keg.rb
@@ -61,6 +61,15 @@ class LinkTests < Test::Unit::TestCase
assert_equal 3, @keg.link(mode)
end
+ def test_link_overwrite_broken_symlinks
+ FileUtils.cd HOMEBREW_PREFIX/"bin" do
+ FileUtils.ln_s "nowhere", "helloworld"
+ end
+ mode = OpenStruct.new
+ mode.overwrite = true
+ assert_equal 3, @keg.link(mode)
+ end
+
def test_link_overwrite_dryrun
FileUtils.touch HOMEBREW_PREFIX/"bin/helloworld"
mode = OpenStruct.new