2016-04-08 16:28:43 +02:00
|
|
|
#: * `reinstall` <formula>:
|
2017-12-30 21:23:33 +00:00
|
|
|
#: Uninstall and then install <formula> (with existing install options).
|
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
|
2017-03-29 11:25:27 +01:00
|
|
|
Migrator.migrate_if_needed(f)
|
2016-09-05 22:40:08 +03:00
|
|
|
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)
|
2017-07-30 21:44:43 +01:00
|
|
|
keg_had_linked_opt = true
|
2017-07-28 17:47:10 +01:00
|
|
|
keg_was_linked = keg.linked?
|
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
|
|
|
|
2017-02-04 18:10:37 +01:00
|
|
|
build_options = BuildOptions.new(Options.create(ARGV.flags_only), f.options)
|
|
|
|
options = build_options.used_options
|
2016-12-10 13:07:03 +00:00
|
|
|
options |= f.build.used_options
|
|
|
|
options &= f.options
|
|
|
|
|
2014-03-15 10:40:18 -05:00
|
|
|
fi = FormulaInstaller.new(f)
|
2017-02-04 18:10:37 +01:00
|
|
|
fi.options = options
|
|
|
|
fi.invalid_option_names = build_options.invalid_option_names
|
2017-06-05 18:35:43 -07:00
|
|
|
fi.build_bottle = ARGV.build_bottle? || (!f.bottled? && f.build.bottle?)
|
2017-02-04 18:10:37 +01:00
|
|
|
fi.interactive = ARGV.interactive?
|
|
|
|
fi.git = ARGV.git?
|
2018-01-10 16:43:21 +00:00
|
|
|
fi.link_keg ||= keg_was_linked if keg_had_linked_opt
|
2014-03-15 10:40:18 -05:00
|
|
|
fi.prelude
|
2016-12-10 13:07:03 +00:00
|
|
|
|
2018-02-09 11:31:51 +09:00
|
|
|
oh1 "Reinstalling #{Formatter.identifier(f.full_name)} #{options.to_a.join " "}"
|
2016-12-10 13:07:03 +00:00
|
|
|
|
2014-03-15 10:40:18 -05:00
|
|
|
fi.install
|
|
|
|
fi.finish
|
|
|
|
rescue FormulaInstallationAlreadyAttemptedError
|
2018-03-06 09:36:49 +00:00
|
|
|
nil
|
2017-10-07 00:31:28 +02:00
|
|
|
rescue Exception # rubocop:disable Lint/RescueException
|
2017-07-28 17:47:10 +01:00
|
|
|
ignore_interrupts { restore_backup(keg, keg_was_linked) }
|
2014-03-15 10:40:18 -05:00
|
|
|
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
|
|
|
|
|
2017-07-28 17:47:10 +01:00
|
|
|
def restore_backup(keg, keg_was_linked)
|
2013-09-05 14:59:33 +02:00
|
|
|
path = backup_path(keg)
|
2016-09-22 20:12:28 +02:00
|
|
|
|
|
|
|
return unless path.directory?
|
|
|
|
|
2017-06-08 16:24:46 +03:00
|
|
|
Pathname.new(keg).rmtree if keg.exist?
|
|
|
|
|
2016-09-22 20:12:28 +02:00
|
|
|
path.rename keg
|
2017-07-28 17:47:10 +01:00
|
|
|
keg.link if keg_was_linked
|
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
|