2013-02-17 13:23:41 +00:00
|
|
|
require 'cmd/install'
|
|
|
|
|
|
|
|
module Homebrew extend self
|
|
|
|
def reinstall
|
2014-03-15 10:40:18 -05:00
|
|
|
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
|
2013-08-28 04:51:24 -07:00
|
|
|
end
|
2014-03-15 10:40:18 -05:00
|
|
|
|
|
|
|
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?
|
2013-08-28 04:51:24 -07:00
|
|
|
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
|