Don't abort upgrade if one formula won't build

Also, unlink previous keg before installing to prevent issues when existing installed brews cause build problems for the newer installed brew.

If the build fails the active keg is relinked before aborting.

Fixes #10341.
This commit is contained in:
Max Howell 2012-03-07 11:17:36 +00:00
parent 76aa0a62f3
commit a13ff43886

View File

@ -14,9 +14,12 @@ module Homebrew extend self
outdated = if ARGV.named.empty? outdated = if ARGV.named.empty?
Homebrew.outdated_brews Homebrew.outdated_brews
else else
ARGV.formulae.each do |f| ARGV.formulae.select do |f|
raise "#{f} already upgraded" if f.installed? unless f.rack.exist? and not f.rack.children.empty?
raise "#{f} not installed" unless f.rack.exist? and not f.rack.children.empty? onoe "#{f} not installed"
else
true
end
end end
end end
@ -35,13 +38,34 @@ module Homebrew extend self
end end
outdated.each do |f| outdated.each do |f|
installer = FormulaInstaller.new f upgrade_formula f
installer.show_header = false
oh1 "Upgrading #{f.name}"
installer.install
Keg.new(f.linked_keg.realpath).unlink if f.linked_keg.directory?
installer.caveats
installer.finish # includes link step
end end
end end
def upgrade_formula f
outdated_keg = Keg.new(f.linked_keg.realpath) rescue nil
installer = FormulaInstaller.new f
installer.show_header = false
oh1 "Upgrading #{f.name}"
# first we unlink the currently active keg for this formula otherwise it is
# possible for the existing build to interfere with the build we are about to
# do! Seriously, it happens!
outdated_keg.unlink if outdated_keg
installer.install
installer.caveats
installer.finish # includes link step
rescue CannotInstallFormulaError => e
onoe e
rescue BuildError => e
e.dump
puts
ensure
# restore previous installation state if build failed
outdated_keg.link if outdated_keg and not f.linked_keg.directory?
end
end end