Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade: fetch all formulae before installing #11940

Merged
merged 3 commits into from
Aug 31, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 26 additions & 14 deletions Library/Homebrew/upgrade.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ def upgrade_formulae(
end
end

formulae_to_install.each do |formula|
formula_installers = formulae_to_install.map do |formula|
Migrator.migrate_if_needed(formula, force: force)
begin
upgrade_formula(
fetch_formula_installer(
formula,
flags: flags,
installed_on_request: installed_on_request,
Expand All @@ -57,10 +57,15 @@ def upgrade_formulae(
quiet: quiet,
verbose: verbose,
)
Cleanup.install_formula_clean!(formula)
rescue UnsatisfiedRequirements => e
rescue UnsatisfiedRequirements, DownloadError => e
ofail "#{formula}: #{e}"
nil
end
end.compact

formula_installers.each do |fi|
upgrade_formula(fi, verbose: verbose)
Cleanup.install_formula_clean!(fi.formula)
end
end

Expand All @@ -82,7 +87,7 @@ def print_upgrade_message(formula, fi_options)
EOS
end

def upgrade_formula(
def fetch_formula_installer(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def fetch_formula_installer(
def fetched_formula_installer(

or

Suggested change
def fetch_formula_installer(
def fetch_and_return_formula_installer(

formula,
flags:,
installed_on_request: false,
Expand All @@ -101,9 +106,6 @@ def upgrade_formula(
keg_was_linked = keg.linked?
end

kegs = outdated_kegs(formula)
linked_kegs = kegs.select(&:linked?)

if formula.opt_prefix.directory?
keg = Keg.new(formula.opt_prefix.resolved_path)
tab = Tab.for_keg(keg)
Expand Down Expand Up @@ -133,23 +135,33 @@ def upgrade_formula(
}.compact,
)

print_upgrade_message(formula, fi.options)

fi.prelude
fi.fetch
fi
end
private_class_method :fetch_formula_installer

def upgrade_formula(formula_installer, verbose: false)
formula = formula_installer.formula

kegs = outdated_kegs(formula)
linked_kegs = kegs.select(&:linked?)

print_upgrade_message(formula, formula_installer.options)

formula_installer.prelude

# first we unlink the currently active keg for this formula otherwise it is
# possible for the existing build to interfere with the build we are about to
# do! Seriously, it happens!
kegs.each(&:unlink)

fi.install
fi.finish
formula_installer.install
formula_installer.finish
rescue FormulaInstallationAlreadyAttemptedError
# We already attempted to upgrade f as part of the dependency tree of
# another formula. In that case, don't generate an error, just move on.
nil
rescue CannotInstallFormulaError, DownloadError => e
rescue CannotInstallFormulaError => e
ofail e
rescue BuildError => e
e.dump(verbose: verbose)
Expand Down