Merge pull request #12024 from FnControlOption/install-upgrade
install, upgrade: check if formula can be installed before fetching
This commit is contained in:
commit
97036d689b
@ -218,8 +218,12 @@ class FormulaInstaller
|
|||||||
raise
|
raise
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_install_sanity
|
def check_installation_already_attempted
|
||||||
raise FormulaInstallationAlreadyAttemptedError, formula if self.class.attempted.include?(formula)
|
raise FormulaInstallationAlreadyAttemptedError, formula if self.class.attempted.include?(formula)
|
||||||
|
end
|
||||||
|
|
||||||
|
def check_install_sanity
|
||||||
|
check_installation_already_attempted
|
||||||
|
|
||||||
if force_bottle? && !pour_bottle?
|
if force_bottle? && !pour_bottle?
|
||||||
raise CannotInstallFormulaError, "--force-bottle passed but #{formula.full_name} has no bottle!"
|
raise CannotInstallFormulaError, "--force-bottle passed but #{formula.full_name} has no bottle!"
|
||||||
|
|||||||
@ -209,6 +209,28 @@ module Homebrew
|
|||||||
Or to force-install it, run:
|
Or to force-install it, run:
|
||||||
brew install #{f} --force
|
brew install #{f} --force
|
||||||
EOS
|
EOS
|
||||||
|
elsif f.linked?
|
||||||
|
message = "#{f.name} #{f.linked_version} is already installed"
|
||||||
|
if f.outdated? && !head
|
||||||
|
unless Homebrew::EnvConfig.no_install_upgrade?
|
||||||
|
puts "#{message} but outdated"
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
onoe <<~EOS
|
||||||
|
#{message}
|
||||||
|
To upgrade to #{f.pkg_version}, run:
|
||||||
|
brew upgrade #{f.full_name}
|
||||||
|
EOS
|
||||||
|
elsif only_dependencies
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
onoe <<~EOS
|
||||||
|
#{message}
|
||||||
|
To install #{f.pkg_version}, first run:
|
||||||
|
brew unlink #{f.name}
|
||||||
|
EOS
|
||||||
|
end
|
||||||
else
|
else
|
||||||
# If none of the above is true and the formula is linked, then
|
# If none of the above is true and the formula is linked, then
|
||||||
# FormulaInstaller will handle this case.
|
# FormulaInstaller will handle this case.
|
||||||
@ -272,8 +294,11 @@ module Homebrew
|
|||||||
)
|
)
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
fi.prelude
|
||||||
fi.fetch
|
fi.fetch
|
||||||
fi
|
fi
|
||||||
|
rescue CannotInstallFormulaError => e
|
||||||
|
ofail e.message
|
||||||
rescue UnsatisfiedRequirements, DownloadError, ChecksumMismatchError => e
|
rescue UnsatisfiedRequirements, DownloadError, ChecksumMismatchError => e
|
||||||
ofail "#{f}: #{e}"
|
ofail "#{f}: #{e}"
|
||||||
nil
|
nil
|
||||||
@ -281,60 +306,21 @@ module Homebrew
|
|||||||
end.compact
|
end.compact
|
||||||
|
|
||||||
formula_installers.each do |fi|
|
formula_installers.each do |fi|
|
||||||
install_formula(fi, only_deps: only_deps)
|
install_formula(fi)
|
||||||
Cleanup.install_formula_clean!(fi.formula)
|
Cleanup.install_formula_clean!(fi.formula)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def install_formula(formula_installer, only_deps: false)
|
def install_formula(formula_installer)
|
||||||
f = formula_installer.formula
|
f = formula_installer.formula
|
||||||
|
|
||||||
formula_installer.prelude
|
formula_installer.check_installation_already_attempted
|
||||||
|
|
||||||
f.print_tap_action
|
f.print_tap_action
|
||||||
|
|
||||||
if f.linked_keg.directory?
|
upgrade = f.linked? && f.outdated? && !f.head? && !Homebrew::EnvConfig.no_install_upgrade?
|
||||||
if Homebrew::EnvConfig.no_install_upgrade?
|
|
||||||
message = <<~EOS
|
|
||||||
#{f.name} #{f.linked_version} is already installed
|
|
||||||
EOS
|
|
||||||
message += if f.outdated? && !f.head?
|
|
||||||
<<~EOS
|
|
||||||
To upgrade to #{f.pkg_version}, run:
|
|
||||||
brew upgrade #{f.full_name}
|
|
||||||
EOS
|
|
||||||
else
|
|
||||||
<<~EOS
|
|
||||||
To install #{f.pkg_version}, first run:
|
|
||||||
brew unlink #{f.name}
|
|
||||||
EOS
|
|
||||||
end
|
|
||||||
raise CannotInstallFormulaError, message unless only_deps
|
|
||||||
elsif f.outdated? && !f.head?
|
|
||||||
puts "#{f.name} #{f.linked_version} is installed but outdated"
|
|
||||||
kegs = Upgrade.outdated_kegs(f)
|
|
||||||
linked_kegs = kegs.select(&:linked?)
|
|
||||||
Upgrade.print_upgrade_message(f, formula_installer.options)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
kegs.each(&:unlink) if kegs.present?
|
Upgrade.install_formula(formula_installer, upgrade: upgrade)
|
||||||
|
|
||||||
formula_installer.install
|
|
||||||
formula_installer.finish
|
|
||||||
rescue FormulaInstallationAlreadyAttemptedError
|
|
||||||
# We already attempted to install f as part of the dependency tree of
|
|
||||||
# another formula. In that case, don't generate an error, just move on.
|
|
||||||
nil
|
|
||||||
rescue CannotInstallFormulaError => e
|
|
||||||
ofail e.message
|
|
||||||
ensure
|
|
||||||
# Re-link kegs if upgrade fails
|
|
||||||
begin
|
|
||||||
linked_kegs.each(&:link) if linked_kegs.present? && !f.latest_version_installed?
|
|
||||||
rescue
|
|
||||||
nil
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
private_class_method :install_formula
|
private_class_method :install_formula
|
||||||
end
|
end
|
||||||
|
|||||||
@ -58,8 +58,13 @@ module Homebrew
|
|||||||
quiet: quiet,
|
quiet: quiet,
|
||||||
verbose: verbose,
|
verbose: verbose,
|
||||||
)
|
)
|
||||||
fi.fetch unless dry_run
|
unless dry_run
|
||||||
|
fi.prelude
|
||||||
|
fi.fetch
|
||||||
|
end
|
||||||
fi
|
fi
|
||||||
|
rescue CannotInstallFormulaError => e
|
||||||
|
ofail e
|
||||||
rescue UnsatisfiedRequirements, DownloadError => e
|
rescue UnsatisfiedRequirements, DownloadError => e
|
||||||
ofail "#{formula}: #{e}"
|
ofail "#{formula}: #{e}"
|
||||||
nil
|
nil
|
||||||
@ -159,22 +164,35 @@ module Homebrew
|
|||||||
def upgrade_formula(formula_installer, dry_run: false, verbose: false)
|
def upgrade_formula(formula_installer, dry_run: false, verbose: false)
|
||||||
formula = formula_installer.formula
|
formula = formula_installer.formula
|
||||||
|
|
||||||
kegs = outdated_kegs(formula)
|
|
||||||
linked_kegs = kegs.select(&:linked?)
|
|
||||||
|
|
||||||
if dry_run
|
if dry_run
|
||||||
print_dry_run_dependencies(formula, formula_installer.compute_dependencies)
|
print_dry_run_dependencies(formula, formula_installer.compute_dependencies)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
formula_installer.prelude
|
formula_installer.check_installation_already_attempted
|
||||||
|
|
||||||
print_upgrade_message(formula, formula_installer.options)
|
install_formula(formula_installer, upgrade: true)
|
||||||
|
rescue BuildError => e
|
||||||
|
e.dump(verbose: verbose)
|
||||||
|
puts
|
||||||
|
Homebrew.failed = true
|
||||||
|
end
|
||||||
|
private_class_method :upgrade_formula
|
||||||
|
|
||||||
|
def install_formula(formula_installer, upgrade:)
|
||||||
|
formula = formula_installer.formula
|
||||||
|
|
||||||
|
if upgrade
|
||||||
|
print_upgrade_message(formula, formula_installer.options)
|
||||||
|
|
||||||
|
kegs = outdated_kegs(formula)
|
||||||
|
linked_kegs = kegs.select(&:linked?)
|
||||||
|
end
|
||||||
|
|
||||||
# first we unlink the currently active keg for this formula otherwise it is
|
# 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
|
# possible for the existing build to interfere with the build we are about to
|
||||||
# do! Seriously, it happens!
|
# do! Seriously, it happens!
|
||||||
kegs.each(&:unlink)
|
kegs.each(&:unlink) if kegs.present?
|
||||||
|
|
||||||
formula_installer.install
|
formula_installer.install
|
||||||
formula_installer.finish
|
formula_installer.finish
|
||||||
@ -182,21 +200,14 @@ module Homebrew
|
|||||||
# We already attempted to upgrade f as part of the dependency tree of
|
# 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.
|
# another formula. In that case, don't generate an error, just move on.
|
||||||
nil
|
nil
|
||||||
rescue CannotInstallFormulaError => e
|
|
||||||
ofail e
|
|
||||||
rescue BuildError => e
|
|
||||||
e.dump(verbose: verbose)
|
|
||||||
puts
|
|
||||||
Homebrew.failed = true
|
|
||||||
ensure
|
ensure
|
||||||
# restore previous installation state if build failed
|
# restore previous installation state if build failed
|
||||||
begin
|
begin
|
||||||
linked_kegs.each(&:link) unless formula.latest_version_installed?
|
linked_kegs.each(&:link) if linked_kegs.present? && !f.latest_version_installed?
|
||||||
rescue
|
rescue
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
private_class_method :upgrade_formula
|
|
||||||
|
|
||||||
def check_broken_dependents(installed_formulae)
|
def check_broken_dependents(installed_formulae)
|
||||||
CacheStoreDatabase.use(:linkage) do |db|
|
CacheStoreDatabase.use(:linkage) do |db|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user