@@ -744,13 +744,29 @@ download() {
744
744
fi
745
745
746
746
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
+
754
770
if [ " $failed " = true ]; then
755
771
say_verbose " Download failed: $remote_path "
756
772
return 1
@@ -761,6 +777,8 @@ download() {
761
777
# Updates global variables $http_code and $download_error_msg
762
778
downloadcurl () {
763
779
eval $invocation
780
+ unset http_code
781
+ unset download_error_msg
764
782
local remote_path=" $1 "
765
783
local out_path=" ${2:- } "
766
784
# Append feed_credential as late as possible before calling curl to avoid logging feed_credential
@@ -789,6 +807,8 @@ downloadcurl() {
789
807
# Updates global variables $http_code and $download_error_msg
790
808
downloadwget () {
791
809
eval $invocation
810
+ unset http_code
811
+ unset download_error_msg
792
812
local remote_path=" $1 "
793
813
local out_path=" ${2:- } "
794
814
# Append feed_credential as late as possible before calling wget to avoid logging feed_credential
@@ -882,7 +902,6 @@ install_dotnet() {
882
902
say " Downloading primary link $download_link "
883
903
884
904
# The download function will set variables $http_code and $download_error_msg in case of failure.
885
- http_code=" " ; download_error_msg=" "
886
905
download " $download_link " " $zip_path " 2>&1 || download_failed=true
887
906
primary_path_http_code=" $http_code " ; primary_path_download_error_msg=" $download_error_msg "
888
907
@@ -906,7 +925,6 @@ install_dotnet() {
906
925
say " Downloading legacy link $download_link "
907
926
908
927
# The download function will set variables $http_code and $download_error_msg in case of failure.
909
- http_code=" " ; download_error_msg=" "
910
928
download " $download_link " " $zip_path " 2>&1 || download_failed=true
911
929
legacy_path_http_code=" $http_code " ; legacy_path_download_error_msg=" $download_error_msg "
912
930
0 commit comments