Skip to content

Commit c9e5e27

Browse files
committed
Add retry to .sh script
1 parent 1ebb108 commit c9e5e27

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

src/dotnet-install.sh

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -744,13 +744,29 @@ download() {
744744
fi
745745
746746
local failed=false
747-
if machine_has "curl"; then
748-
downloadcurl "$remote_path" "$out_path" || failed=true
749-
elif machine_has "wget"; then
750-
downloadwget "$remote_path" "$out_path" || failed=true
751-
else
752-
failed=true
753-
fi
747+
local attempts=0
748+
while [ $attempts -lt 3 ]; do
749+
attempts=$((attempts+1))
750+
failed=false
751+
if machine_has "curl"; then
752+
downloadcurl "$remote_path" "$out_path" || failed=true
753+
elif machine_has "wget"; then
754+
downloadwget "$remote_path" "$out_path" || failed=true
755+
else
756+
failed = true
757+
fi
758+
759+
if [ "$failed" = false ] || [ $attempts -ge 3 ] || { [ ! -z $http_code ] && [ $http_code = "404" ]; }; then
760+
break
761+
fi
762+
763+
764+
say "Trying for the $((attempts+1))rd time in $((attempts*10)) seconds."
765+
sleep $((attempts*20))
766+
done
767+
768+
769+
754770
if [ "$failed" = true ]; then
755771
say_verbose "Download failed: $remote_path"
756772
return 1
@@ -761,6 +777,8 @@ download() {
761777
# Updates global variables $http_code and $download_error_msg
762778
downloadcurl() {
763779
eval $invocation
780+
unset http_code
781+
unset download_error_msg
764782
local remote_path="$1"
765783
local out_path="${2:-}"
766784
# Append feed_credential as late as possible before calling curl to avoid logging feed_credential
@@ -789,6 +807,8 @@ downloadcurl() {
789807
# Updates global variables $http_code and $download_error_msg
790808
downloadwget() {
791809
eval $invocation
810+
unset http_code
811+
unset download_error_msg
792812
local remote_path="$1"
793813
local out_path="${2:-}"
794814
# Append feed_credential as late as possible before calling wget to avoid logging feed_credential
@@ -882,7 +902,6 @@ install_dotnet() {
882902
say "Downloading primary link $download_link"
883903
884904
# The download function will set variables $http_code and $download_error_msg in case of failure.
885-
http_code=""; download_error_msg=""
886905
download "$download_link" "$zip_path" 2>&1 || download_failed=true
887906
primary_path_http_code="$http_code"; primary_path_download_error_msg="$download_error_msg"
888907
@@ -906,7 +925,6 @@ install_dotnet() {
906925
say "Downloading legacy link $download_link"
907926
908927
# The download function will set variables $http_code and $download_error_msg in case of failure.
909-
http_code=""; download_error_msg=""
910928
download "$download_link" "$zip_path" 2>&1 || download_failed=true
911929
legacy_path_http_code="$http_code"; legacy_path_download_error_msg="$download_error_msg"
912930

0 commit comments

Comments
 (0)