From 88118b51b263ff32a0c18dc59e72b9b5ff265a28 Mon Sep 17 00:00:00 2001 From: Max Howell Date: Mon, 19 Mar 2012 12:24:13 +0000 Subject: [PATCH] Don't error if exact link already exists If the link already exists exactly (well almost exactly) as we are about to correct it, then it's okay. Otherwise we error out. This is a safe choice, and really, the correct choice too. This will prevent the tickets like Homebrew/homebrew#11050 from occurring. --- Library/Homebrew/cmd/link.rb | 5 +++++ Library/Homebrew/keg.rb | 18 +++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/Library/Homebrew/cmd/link.rb b/Library/Homebrew/cmd/link.rb index 09d16c7824..8885d01557 100644 --- a/Library/Homebrew/cmd/link.rb +++ b/Library/Homebrew/cmd/link.rb @@ -10,6 +10,11 @@ module Homebrew extend self end ARGV.kegs.each do |keg| + if keg.linked_keg_record.directory? and keg.linked_keg_record.realpath == keg + opoo "Already linked: #{keg}" + next + end + print "Linking #{keg}... " do puts if ARGV.verbose? puts "#{keg.link} symlinks created" diff --git a/Library/Homebrew/keg.rb b/Library/Homebrew/keg.rb index 19e756f8f8..6a217e90b9 100644 --- a/Library/Homebrew/keg.rb +++ b/Library/Homebrew/keg.rb @@ -102,9 +102,9 @@ class Keg < Pathname end end - (HOMEBREW_REPOSITORY/"Library/LinkedKegs"/fname).make_relative_symlink(self) + linked_keg_record.make_relative_symlink(self) - return $n+$d + return $n + $d end protected @@ -123,6 +123,14 @@ protected puts "Won't resolve conflicts for symlink #{dst} as it doesn't resolve into the Cellar" if ARGV.verbose? end + def make_relative_symlink dst, src + if dst.exist? and dst.realpath == src.realpath + puts "Skipping; already exists: #{dst}" if ARGV.verbose? + else + dst.make_relative_symlink src + end + end + # symlinks the contents of self+foo recursively into /usr/local/foo def link_dir foo root = self+foo @@ -141,10 +149,10 @@ protected when :skip_file Find.prune when :info - dst.make_relative_symlink(src) + make_relative_symlink dst, src dst.install_info else - dst.make_relative_symlink(src) + make_relative_symlink dst, src end elsif src.directory? # if the dst dir already exists, then great! walk the rest of the tree tho @@ -161,7 +169,7 @@ protected dst.mkpath unless resolve_any_conflicts(dst) else unless resolve_any_conflicts(dst) - dst.make_relative_symlink(src) + make_relative_symlink dst, src Find.prune end end