brew/Library/Homebrew/cmd/reinstall.rb

64 lines
1.6 KiB
Ruby
Raw Normal View History

2016-04-08 16:28:43 +02:00
#: * `reinstall` <formula>:
#: Uninstall then install <formula>
2014-10-31 20:10:08 -05:00
require "formula_installer"
2013-02-17 13:23:41 +00:00
module Homebrew
2013-02-17 13:23:41 +00:00
def reinstall
FormulaInstaller.prevent_build_flags unless DevelopmentTools.installed?
2015-05-17 21:10:28 +08:00
ARGV.resolved_formulae.each { |f| reinstall_formula(f) }
end
def reinstall_formula(f)
tab = Tab.for_formula(f)
options = tab.used_options | f.build.used_options
2015-05-27 21:12:07 +08:00
notice = "Reinstalling #{f.full_name}"
notice += " with #{options * ", "}" unless options.empty?
oh1 notice
if f.opt_prefix.directory?
keg = Keg.new(f.opt_prefix.resolved_path)
backup keg
end
fi = FormulaInstaller.new(f)
fi.options = options
fi.build_bottle = ARGV.build_bottle? || (!f.bottled? && tab.build_bottle?)
fi.build_from_source = ARGV.build_from_source? || ARGV.build_all_from_source?
fi.force_bottle = ARGV.force_bottle?
fi.interactive = ARGV.interactive?
fi.git = ARGV.git?
fi.verbose = ARGV.verbose?
fi.debug = ARGV.debug?
fi.prelude
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?
end
def backup(keg)
keg.unlink
2013-09-05 14:59:33 +02:00
keg.rename backup_path(keg)
end
def restore_backup(keg, formula)
2013-09-05 14:59:33 +02:00
path = backup_path(keg)
if path.directory?
2013-09-05 14:59:33 +02:00
path.rename keg
keg.link unless formula.keg_only?
end
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