2016-04-08 16:28:43 +02:00
|
|
|
#: * `reinstall` <formula>:
|
2016-08-17 01:19:40 +02:00
|
|
|
#: Uninstall and then install <formula>.
|
2016-04-08 16:28:43 +02:00
|
|
|
|
2014-10-31 20:10:08 -05:00
|
|
|
require "formula_installer"
|
2016-07-29 20:31:32 -06:00
|
|
|
require "development_tools"
|
2013-02-17 13:23:41 +00:00
|
|
|
|
2014-06-18 22:41:47 -05:00
|
|
|
module Homebrew
|
2016-09-26 01:44:51 +02:00
|
|
|
module_function
|
|
|
|
|
2013-02-17 13:23:41 +00:00
|
|
|
def reinstall
|
2016-07-06 11:07:24 +01:00
|
|
|
FormulaInstaller.prevent_build_flags unless DevelopmentTools.installed?
|
2015-06-29 14:09:57 -04:00
|
|
|
|
2016-09-05 22:40:08 +03:00
|
|
|
ARGV.resolved_formulae.each do |f|
|
|
|
|
if f.pinned?
|
|
|
|
onoe "#{f.full_name} is pinned. You must unpin it to reinstall."
|
|
|
|
next
|
|
|
|
end
|
|
|
|
reinstall_formula(f)
|
|
|
|
end
|
2014-03-15 10:40:18 -05:00
|
|
|
end
|
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
def reinstall_formula(f)
|
2014-04-05 12:17:19 -05:00
|
|
|
if f.opt_prefix.directory?
|
|
|
|
keg = Keg.new(f.opt_prefix.resolved_path)
|
2014-03-15 10:40:18 -05:00
|
|
|
backup keg
|
2013-08-28 04:51:24 -07:00
|
|
|
end
|
2014-03-15 10:40:18 -05:00
|
|
|
|
2016-12-10 13:07:03 +00:00
|
|
|
options = BuildOptions.new(Options.create(ARGV.flags_only), f.options).used_options
|
|
|
|
options |= f.build.used_options
|
|
|
|
options &= f.options
|
|
|
|
|
2014-03-15 10:40:18 -05:00
|
|
|
fi = FormulaInstaller.new(f)
|
|
|
|
fi.options = options
|
2016-07-17 18:18:41 +08:00
|
|
|
fi.build_bottle = ARGV.build_bottle? || (!f.bottled? && f.build.build_bottle?)
|
2016-05-06 12:02:13 -07:00
|
|
|
fi.build_from_source = ARGV.build_from_source? || ARGV.build_all_from_source?
|
2014-03-15 10:40:18 -05:00
|
|
|
fi.force_bottle = ARGV.force_bottle?
|
2016-01-03 14:46:29 -08:00
|
|
|
fi.interactive = ARGV.interactive?
|
|
|
|
fi.git = ARGV.git?
|
2014-03-15 10:40:18 -05:00
|
|
|
fi.verbose = ARGV.verbose?
|
|
|
|
fi.debug = ARGV.debug?
|
|
|
|
fi.prelude
|
2016-12-10 13:07:03 +00:00
|
|
|
|
|
|
|
oh1 "Reinstalling #{f.full_name} #{options.to_a.join " "}"
|
|
|
|
|
2014-03-15 10:40:18 -05:00
|
|
|
fi.install
|
|
|
|
fi.finish
|
|
|
|
rescue FormulaInstallationAlreadyAttemptedError
|
|
|
|
# next
|
|
|
|
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
|
|
|
|
|
2015-08-03 13:09:07 +01: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
|
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
def restore_backup(keg, formula)
|
2013-09-05 14:59:33 +02:00
|
|
|
path = backup_path(keg)
|
2016-09-22 20:12:28 +02:00
|
|
|
|
|
|
|
return unless path.directory?
|
|
|
|
|
|
|
|
path.rename keg
|
|
|
|
keg.link unless formula.keg_only?
|
2013-02-17 13:23:41 +00:00
|
|
|
end
|
2013-08-28 04:51:24 -07:00
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
def backup_path(path)
|
2013-09-05 14:59:33 +02:00
|
|
|
Pathname.new "#{path}.reinstall"
|
2013-08-28 04:51:24 -07:00
|
|
|
end
|
2013-02-17 13:23:41 +00:00
|
|
|
end
|