Skip to content
Snippets Groups Projects
Commit eab90dcb authored by Jack Nagel's avatar Jack Nagel
Browse files

Rewrite `brew reinstall`

Fixes Homebrew/homebrew#23928.
parent d441d7b9
No related branches found
No related tags found
No related merge requests found
......@@ -36,14 +36,9 @@ module Homebrew extend self
end unless ARGV.force?
perform_preinstall_checks
begin
ARGV.formulae.each do |f|
begin
install_formula(f)
rescue CannotInstallFormulaError => e
ofail e.message
end
end
ARGV.formulae.each { |f| install_formula(f) }
rescue FormulaUnavailableError => e
ofail e.message
require 'cmd/search'
......@@ -124,6 +119,7 @@ module Homebrew extend self
# another formula. In that case, don't generate an error, just move on.
rescue FormulaAlreadyInstalledError => e
opoo e.message
# Ignore CannotInstallFormulaError and let caller handle it.
rescue CannotInstallFormulaError => e
ofail e.message
end
end
......@@ -2,39 +2,43 @@ require 'cmd/install'
module Homebrew extend self
def reinstall
# At first save the named formulae and remove them from ARGV
named = ARGV.named
ARGV.delete_if { |arg| named.include? arg }
clean_ARGV = ARGV.clone
# Add the used_options for each named formula separately so
# that the options apply to the right formula.
named.each do |name|
ARGV.replace(clean_ARGV)
ARGV << name
tab = Tab.for_name(name)
tab.used_options.each { |option| ARGV << option.to_s }
if tab.built_as_bottle and not tab.poured_from_bottle
ARGV << '--build-bottle'
end
formula = Formulary.factory(name)
begin
oh1 "Reinstalling #{name} #{ARGV.options_only*' '}"
opt_link = formula.opt_prefix
if opt_link.exist?
keg = Keg.new(opt_link.realpath)
backup keg
end
self.install_formula formula
rescue Exception
ignore_interrupts { restore_backup(keg, formula) }
raise
else
backup_path(keg).rmtree if backup_path(keg).exist?
end
ARGV.formulae.each { |f| reinstall_formula(f) }
end
def reinstall_formula f
tab = Tab.for_formula(f)
options = tab.used_options | f.build.used_options
notice = "Reinstalling #{f.name}"
notice += " with #{options * ", "}" unless options.empty?
oh1 notice
if (opt_link = f.opt_prefix).exist?
keg = Keg.new(opt_link.realpath)
backup keg
end
fi = FormulaInstaller.new(f)
fi.options = options
fi.build_bottle = ARGV.build_bottle?
fi.build_bottle ||= tab.built_as_bottle && !tab.poured_from_bottle
fi.build_from_source = ARGV.build_from_source?
fi.force_bottle = ARGV.force_bottle?
fi.verbose = ARGV.verbose?
fi.debug = ARGV.debug?
fi.prelude
fi.install
fi.caveats
fi.finish
rescue FormulaInstallationAlreadyAttemptedError
# next
rescue FormulaAlreadyInstalledError => e
opoo e.message
rescue Exception
ignore_interrupts { restore_backup(keg, f) }
raise
else
backup_path(keg).rmtree if backup_path(keg).exist?
end
def backup keg
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment