Merge pull request #14943 from MikeMcQuaid/api_auto_update_less_often

This commit is contained in:
Mike McQuaid 2023-03-11 07:54:23 +00:00 committed by GitHub
commit 84c59e5ceb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 12 deletions

View File

@ -58,7 +58,8 @@ module Homebrew
skip_download = target.exist? && skip_download = target.exist? &&
!target.empty? && !target.empty? &&
(Homebrew::EnvConfig.no_auto_update? || (!Homebrew.auto_update_command? ||
Homebrew::EnvConfig.no_auto_update? ||
((Time.now - Homebrew::EnvConfig.api_auto_update_secs.to_i) < target.mtime)) ((Time.now - Homebrew::EnvConfig.api_auto_update_secs.to_i) < target.mtime))
skip_download ||= Homebrew.running_as_root_but_not_owned_by_root? skip_download ||= Homebrew.running_as_root_but_not_owned_by_root?

View File

@ -269,17 +269,7 @@ auto-update() {
# If we've checked for updates, we don't need to check again. # If we've checked for updates, we don't need to check again.
export HOMEBREW_AUTO_UPDATE_CHECKED="1" export HOMEBREW_AUTO_UPDATE_CHECKED="1"
AUTO_UPDATE_COMMANDS=( if [[ -n "${HOMEBREW_AUTO_UPDATE_COMMAND}" ]]
install
upgrade
bump-formula-pr
bump-cask-pr
bundle
release
)
if check-array-membership "${HOMEBREW_COMMAND}" "${AUTO_UPDATE_COMMANDS[@]}" ||
[[ "${HOMEBREW_COMMAND}" == "tap" && "${HOMEBREW_ARG_COUNT}" -gt 1 ]]
then then
export HOMEBREW_AUTO_UPDATING="1" export HOMEBREW_AUTO_UPDATING="1"
@ -816,6 +806,22 @@ then
unset HOMEBREW_RUBY_WARNINGS unset HOMEBREW_RUBY_WARNINGS
fi fi
# Check for commands that should call `brew update --auto-update` first.
AUTO_UPDATE_COMMANDS=(
install
outdated
upgrade
bump-formula-pr
bump-cask-pr
bundle
release
)
if check-array-membership "${HOMEBREW_COMMAND}" "${AUTO_UPDATE_COMMANDS[@]}" ||
[[ "${HOMEBREW_COMMAND}" == "tap" && "${HOMEBREW_ARG_COUNT}" -gt 1 ]]
then
export HOMEBREW_AUTO_UPDATE_COMMAND="1"
fi
# Disable Ruby options we don't need. # Disable Ruby options we don't need.
export HOMEBREW_RUBY_DISABLE_OPTIONS="--disable=gems,rubyopt" export HOMEBREW_RUBY_DISABLE_OPTIONS="--disable=gems,rubyopt"

View File

@ -124,6 +124,10 @@ module Homebrew
def running_as_root_but_not_owned_by_root? def running_as_root_but_not_owned_by_root?
running_as_root? && !owner_uid.zero? running_as_root? && !owner_uid.zero?
end end
def auto_update_command?
ENV.fetch("HOMEBREW_AUTO_UPDATE_COMMAND", false).present?
end
end end
end end