reinstall: move to submodule

This commit is contained in:
Bo Anderson 2024-08-20 03:58:01 +01:00
parent 561cc17a74
commit 77204e01da
No known key found for this signature in database
3 changed files with 91 additions and 88 deletions

View File

@ -134,7 +134,7 @@ module Homebrew
next
end
Migrator.migrate_if_needed(formula, force: args.force?)
Homebrew.reinstall_formula(
Homebrew::Reinstall.reinstall_formula(
formula,
flags: args.flags_only,
installed_on_request: args.named.present?,

View File

@ -6,103 +6,106 @@ require "development_tools"
require "messages"
module Homebrew
module_function
def reinstall_formula(
formula,
flags:,
installed_on_request: false,
force_bottle: false,
build_from_source_formulae: [],
interactive: false,
keep_tmp: false,
debug_symbols: false,
force: false,
debug: false,
quiet: false,
verbose: false,
git: false
)
if formula.opt_prefix.directory?
keg = Keg.new(formula.opt_prefix.resolved_path)
tab = keg.tab
keg_had_linked_opt = true
keg_was_linked = keg.linked?
backup keg
end
build_options = BuildOptions.new(Options.create(flags), formula.options)
options = build_options.used_options
options |= formula.build.used_options
options &= formula.options
fi = FormulaInstaller.new(
module Reinstall
def self.reinstall_formula(
formula,
**{
options:,
link_keg: keg_had_linked_opt ? keg_was_linked : nil,
installed_as_dependency: tab&.installed_as_dependency,
installed_on_request: installed_on_request || tab&.installed_on_request,
build_bottle: tab&.built_bottle?,
force_bottle:,
build_from_source_formulae:,
git:,
interactive:,
keep_tmp:,
debug_symbols:,
force:,
debug:,
quiet:,
verbose:,
}.compact,
flags:,
installed_on_request: false,
force_bottle: false,
build_from_source_formulae: [],
interactive: false,
keep_tmp: false,
debug_symbols: false,
force: false,
debug: false,
quiet: false,
verbose: false,
git: false
)
fi.prelude
fi.fetch
if formula.opt_prefix.directory?
keg = Keg.new(formula.opt_prefix.resolved_path)
tab = keg.tab
keg_had_linked_opt = true
keg_was_linked = keg.linked?
backup keg
end
oh1 "Reinstalling #{Formatter.identifier(formula.full_name)} #{options.to_a.join " "}"
build_options = BuildOptions.new(Options.create(flags), formula.options)
options = build_options.used_options
options |= formula.build.used_options
options &= formula.options
fi.install
fi.finish
rescue FormulaInstallationAlreadyAttemptedError
nil
rescue Exception # rubocop:disable Lint/RescueException
ignore_interrupts { restore_backup(keg, keg_was_linked, verbose:) }
raise
else
begin
backup_path(keg).rmtree if backup_path(keg).exist?
rescue Errno::EACCES, Errno::ENOTEMPTY
odie <<~EOS
Could not remove #{backup_path(keg).parent.basename} backup keg! Do so manually:
sudo rm -rf #{backup_path(keg)}
EOS
fi = FormulaInstaller.new(
formula,
**{
options:,
link_keg: keg_had_linked_opt ? keg_was_linked : nil,
installed_as_dependency: tab&.installed_as_dependency,
installed_on_request: installed_on_request || tab&.installed_on_request,
build_bottle: tab&.built_bottle?,
force_bottle:,
build_from_source_formulae:,
git:,
interactive:,
keep_tmp:,
debug_symbols:,
force:,
debug:,
quiet:,
verbose:,
}.compact,
)
fi.prelude
fi.fetch
oh1 "Reinstalling #{Formatter.identifier(formula.full_name)} #{options.to_a.join " "}"
fi.install
fi.finish
rescue FormulaInstallationAlreadyAttemptedError
nil
rescue Exception # rubocop:disable Lint/RescueException
ignore_interrupts { restore_backup(keg, keg_was_linked, verbose:) }
raise
else
begin
backup_path(keg).rmtree if backup_path(keg).exist?
rescue Errno::EACCES, Errno::ENOTEMPTY
odie <<~EOS
Could not remove #{backup_path(keg).parent.basename} backup keg! Do so manually:
sudo rm -rf #{backup_path(keg)}
EOS
end
end
end
def backup(keg)
keg.unlink
begin
keg.rename backup_path(keg)
rescue Errno::EACCES, Errno::ENOTEMPTY
odie <<~EOS
Could not rename #{keg.name} keg! Check/fix its permissions:
sudo chown -R #{ENV.fetch("USER", "$(whoami)")} #{keg}
EOS
def self.backup(keg)
keg.unlink
begin
keg.rename backup_path(keg)
rescue Errno::EACCES, Errno::ENOTEMPTY
odie <<~EOS
Could not rename #{keg.name} keg! Check/fix its permissions:
sudo chown -R #{ENV.fetch("USER", "$(whoami)")} #{keg}
EOS
end
end
end
private_class_method :backup
def restore_backup(keg, keg_was_linked, verbose:)
path = backup_path(keg)
def self.restore_backup(keg, keg_was_linked, verbose:)
path = backup_path(keg)
return unless path.directory?
return unless path.directory?
Pathname.new(keg).rmtree if keg.exist?
Pathname.new(keg).rmtree if keg.exist?
path.rename keg
keg.link(verbose:) if keg_was_linked
end
path.rename keg
keg.link(verbose:) if keg_was_linked
end
private_class_method :restore_backup
def backup_path(path)
Pathname.new "#{path}.reinstall"
def self.backup_path(path)
Pathname.new "#{path}.reinstall"
end
private_class_method :backup_path
end
end

View File

@ -409,7 +409,7 @@ module Homebrew
return if dry_run
reinstallable_broken_dependents.each do |formula|
Homebrew.reinstall_formula(
Reinstall.reinstall_formula(
formula,
flags:,
force_bottle:,