brew/Library/Homebrew/cmd/reinstall.rb

78 lines
2.0 KiB
Ruby
Raw Normal View History

2016-04-08 16:28:43 +02:00
#: * `reinstall` <formula>:
#: 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"
require "development_tools"
2013-02-17 13:23:41 +00:00
module Homebrew
2016-09-26 01:44:51 +02:00
module_function
2013-02-17 13:23:41 +00:00
def reinstall
FormulaInstaller.prevent_build_flags unless DevelopmentTools.installed?
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
Migrator.migrate_if_needed(f)
2016-09-05 22:40:08 +03:00
reinstall_formula(f)
end
end
def reinstall_formula(f)
if f.opt_prefix.directory?
keg = Keg.new(f.opt_prefix.resolved_path)
keg_had_linked_opt = true
keg_was_linked = keg.linked?
backup keg
end
build_options = BuildOptions.new(Options.create(ARGV.flags_only), f.options)
options = build_options.used_options
options |= f.build.used_options
options &= f.options
fi = FormulaInstaller.new(f)
fi.options = options
fi.invalid_option_names = build_options.invalid_option_names
fi.build_bottle = ARGV.build_bottle? || (!f.bottled? && f.build.bottle?)
fi.interactive = ARGV.interactive?
fi.git = ARGV.git?
fi.link_keg = keg_was_linked if keg_had_linked_opt
fi.prelude
oh1 "Reinstalling #{f.full_name} #{options.to_a.join " "}"
fi.install
fi.finish
rescue FormulaInstallationAlreadyAttemptedError
return
rescue Exception # rubocop:disable Lint/RescueException
ignore_interrupts { restore_backup(keg, keg_was_linked) }
raise
else
backup_path(keg).rmtree if backup_path(keg).exist?
end
def backup(keg)
keg.unlink
2013-09-05 14:59:33 +02:00
keg.rename backup_path(keg)
end
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
keg.link if keg_was_linked
2013-02-17 13:23:41 +00:00
end
def backup_path(path)
2013-09-05 14:59:33 +02:00
Pathname.new "#{path}.reinstall"
end
2013-02-17 13:23:41 +00:00
end