2013-02-17 13:23:41 +00:00
|
|
|
require 'cmd/install'
|
|
|
|
|
|
|
|
module Homebrew extend self
|
|
|
|
def reinstall
|
2013-07-23 10:55:07 +02:00
|
|
|
# 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 }
|
2013-09-01 13:54:21 +01:00
|
|
|
if tab.built_as_bottle and not tab.poured_from_bottle
|
|
|
|
ARGV << '--build-bottle'
|
|
|
|
end
|
2013-08-28 04:51:24 -07:00
|
|
|
|
2014-03-01 18:22:35 -06:00
|
|
|
formula = Formulary.factory(name)
|
2013-08-28 04:51:24 -07:00
|
|
|
|
|
|
|
begin
|
|
|
|
oh1 "Reinstalling #{name} #{ARGV.options_only*' '}"
|
2014-03-01 18:22:35 -06:00
|
|
|
opt_link = formula.opt_prefix
|
2013-09-05 14:59:33 +02:00
|
|
|
if opt_link.exist?
|
|
|
|
keg = Keg.new(opt_link.realpath)
|
|
|
|
backup keg
|
|
|
|
end
|
2013-08-28 04:51:24 -07:00
|
|
|
self.install_formula formula
|
2014-03-01 18:27:30 -06:00
|
|
|
rescue Exception
|
|
|
|
ignore_interrupts { restore_backup(keg, formula) }
|
|
|
|
raise
|
2013-08-28 04:51:24 -07:00
|
|
|
else
|
2013-09-05 14:59:33 +02:00
|
|
|
backup_path(keg).rmtree if backup_path(keg).exist?
|
2013-08-28 04:51:24 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-09-05 14:59:33 +02:00
|
|
|
def backup keg
|
2013-08-28 04:51:24 -07:00
|
|
|
keg.unlink
|
2013-09-05 14:59:33 +02:00
|
|
|
keg.rename backup_path(keg)
|
2013-08-28 04:51:24 -07:00
|
|
|
end
|
|
|
|
|
2013-09-05 14:59:33 +02:00
|
|
|
def restore_backup keg, formula
|
|
|
|
path = backup_path(keg)
|
2013-08-28 04:51:24 -07:00
|
|
|
if path.directory?
|
2013-09-05 14:59:33 +02:00
|
|
|
path.rename keg
|
2013-08-28 04:51:24 -07:00
|
|
|
keg.link unless formula.keg_only?
|
2013-07-23 10:55:07 +02:00
|
|
|
end
|
2013-02-17 13:23:41 +00:00
|
|
|
end
|
2013-08-28 04:51:24 -07:00
|
|
|
|
2013-09-05 14:59:33 +02:00
|
|
|
def backup_path path
|
|
|
|
Pathname.new "#{path}.reinstall"
|
2013-08-28 04:51:24 -07:00
|
|
|
end
|
2013-02-17 13:23:41 +00:00
|
|
|
end
|