File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -181,11 +181,13 @@ add_php() {
181181 fi
182182 if [[ " $existing_version " != " false" && -z " $suffix " ]]; then
183183 if [ " $action " = " upgrade" ]; then
184+ brew_retry 3 install --only-dependencies " $php_formula " 2> /dev/null || true
184185 brew upgrade -f --overwrite " $php_formula "
185186 else
186187 brew unlink " $php_keg "
187188 fi
188189 else
190+ brew_retry 3 install --only-dependencies " $php_formula " 2> /dev/null || true
189191 brew install -f --overwrite " $php_formula " || brew upgrade -f --overwrite " $php_formula "
190192 fi
191193 sudo chown -R " $( id -un) " :" $( id -gn) " " $brew_prefix "
Original file line number Diff line number Diff line change @@ -55,6 +55,39 @@ add_brew() {
5555 add_brew_bins_to_path " $brew_prefix "
5656}
5757
58+ # Function to run brew with retries and timeout.
59+ brew_retry () {
60+ local timeout=300
61+ local max_tries=${1:- 5}
62+ shift
63+ local tries=0
64+ while : ; do
65+ tries=$(( tries + 1 ))
66+ sudo rm -rf " $brew_prefix " /var/homebrew/locks/*
67+ brew " $@ " &
68+ local cmd_pid=$!
69+ (
70+ sleep " $timeout "
71+ if kill -0 " $cmd_pid " 2> /dev/null; then
72+ echo " Timed out after ${timeout} s, killing brew (pid $cmd_pid )"
73+ kill -TERM " $cmd_pid " 2> /dev/null
74+ fi
75+ ) &
76+ local killer_pid=$!
77+ wait " $cmd_pid "
78+ local status=$?
79+ kill -TERM " $killer_pid " 2> /dev/null
80+ if [[ $status -eq 0 ]]; then
81+ return 0
82+ fi
83+ if (( tries >= max_tries )) ; then
84+ echo " brew command failed after $tries tries (last status $status )"
85+ return " $status "
86+ fi
87+ echo " brew exited with status $status , retrying..."
88+ done
89+ }
90+
5891# Function to configure brew constants.
5992configure_brew () {
6093 brew_path=" $( command -v brew) "
You can’t perform that action at this time.
0 commit comments