From 765ae9618050e415c039edabce02671581c1ffb1 Mon Sep 17 00:00:00 2001 From: Max Howell Date: Tue, 6 Mar 2012 13:02:10 +0000 Subject: [PATCH] Leave kegs keg-only if linking step fails Rationale: well, it should always have been like this! However now we are opening ourselves up to more-mixed installations of formula not maintained by us, it's important that --- Library/Homebrew/cmd/link.rb | 7 +------ Library/Homebrew/extend/pathname.rb | 13 ++++--------- Library/Homebrew/formula_installer.rb | 5 ++++- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/Library/Homebrew/cmd/link.rb b/Library/Homebrew/cmd/link.rb index df3445aa50..d882ee7ec6 100644 --- a/Library/Homebrew/cmd/link.rb +++ b/Library/Homebrew/cmd/link.rb @@ -11,12 +11,7 @@ module Homebrew extend self ARGV.kegs.each do |keg| print "Linking #{keg}... " puts if ARGV.verbose? - begin - puts "#{keg.link} symlinks created" - rescue Exception - puts - raise - end + puts "#{keg.link} symlinks created" end end end diff --git a/Library/Homebrew/extend/pathname.rb b/Library/Homebrew/extend/pathname.rb index d0ed3108bf..bc58c885fd 100644 --- a/Library/Homebrew/extend/pathname.rb +++ b/Library/Homebrew/extend/pathname.rb @@ -273,15 +273,10 @@ class Pathname self.dirname.mkpath Dir.chdir self.dirname do - # TODO use Ruby function so we get exceptions - # NOTE Ruby functions may work, but I had a lot of problems - rv = system 'ln', '-sf', src.relative_path_from(self.dirname), self.basename - unless rv and $? == 0 - raise <<-EOS.undent - Could not create symlink #{to_s}. - Check that you have permissions on #{self.dirname} - EOS - end + # NOTE only system ln -s will create RELATIVE symlinks + system 'ln', '-s', src.relative_path_from(self.dirname), self.basename + # ln outputs useful error message for us + raise "Could not create symlink: #{to_s}." unless $?.success? end end diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index 479232cd17..96dae5bac7 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -214,11 +214,14 @@ class FormulaInstaller f.linked_keg.unlink end - Keg.new(f.prefix).link + keg = Keg.new(f.prefix) + keg.link rescue Exception => e onoe "The linking step did not complete successfully" puts "The formula built, but is not symlinked into #{HOMEBREW_PREFIX}" puts "You can try again using `brew link #{f.name}'" + keg.unlink + ohai e, e.backtrace if ARGV.debug? @show_summary_heading = true end