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
|
|
|
|
|
|
|
canonical_name = Formula.canonical_name(name)
|
|
|
|
formula = Formula.factory(canonical_name)
|
|
|
|
|
|
|
|
if not formula.installed?
|
|
|
|
if force_new_install?
|
|
|
|
oh1 "Force installing new formula: #{name}"
|
|
|
|
self.install_formula formula
|
|
|
|
next
|
|
|
|
else
|
|
|
|
raise <<-EOS.undent
|
|
|
|
#{formula} is not installed. Please install it first or use
|
|
|
|
"--force-new-install" flag.
|
|
|
|
EOS
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
linked_keg_ref = HOMEBREW_REPOSITORY/'opt'/canonical_name
|
|
|
|
keg = Keg.new(linked_keg_ref.realpath)
|
|
|
|
|
|
|
|
begin
|
|
|
|
oh1 "Reinstalling #{name} #{ARGV.options_only*' '}"
|
|
|
|
quarantine keg
|
|
|
|
self.install_formula formula
|
|
|
|
rescue Exception => e
|
|
|
|
ofail e.message unless e.message.empty?
|
|
|
|
restore_quarantine keg, formula
|
|
|
|
raise 'Reinstallation abort.'
|
|
|
|
else
|
|
|
|
remove_quarantine keg
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def force_new_install?
|
|
|
|
ARGV.include? '--force-new-install'
|
|
|
|
end
|
|
|
|
|
|
|
|
def quarantine keg
|
|
|
|
keg.unlink
|
|
|
|
|
|
|
|
path = Pathname.new(keg.to_s)
|
|
|
|
path.rename quarantine_path(path)
|
|
|
|
end
|
|
|
|
|
|
|
|
def restore_quarantine keg, formula
|
|
|
|
path = Pathname.new(quarantine_path(keg))
|
|
|
|
if path.directory?
|
|
|
|
path.rename keg.to_s
|
|
|
|
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
|
|
|
|
|
|
|
def remove_quarantine keg
|
|
|
|
path = Pathname.new(quarantine_path(keg))
|
|
|
|
path.rmtree
|
|
|
|
end
|
|
|
|
|
|
|
|
def quarantine_path path
|
|
|
|
path.to_s + '.reinstall'
|
|
|
|
end
|
2013-02-17 13:23:41 +00:00
|
|
|
end
|