Skip to content

Commit 1166995

Browse files
authored
Rollup merge of #40060 - alexcrichton:retry-downloads, r=aturon
rustbuild: Retry downloads by default Don't rely on curl's --retry, it appears to not work for some errors like SSL errors.
2 parents 4c176d4 + 30b0ed0 commit 1166995

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/bootstrap/bootstrap.py

+17-4
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,33 @@ def delete_if_present(path, verbose):
5959

6060

6161
def download(path, url, probably_big, verbose):
62+
for x in range(0, 4):
63+
try:
64+
_download(path, url, probably_big, verbose, True)
65+
return
66+
except RuntimeError:
67+
print("\nspurious failure, trying again")
68+
_download(path, url, probably_big, verbose, False)
69+
70+
71+
def _download(path, url, probably_big, verbose, exception):
6272
if probably_big or verbose:
6373
print("downloading {}".format(url))
6474
# see http://serverfault.com/questions/301128/how-to-download
6575
if sys.platform == 'win32':
6676
run(["PowerShell.exe", "/nologo", "-Command",
6777
"(New-Object System.Net.WebClient)"
6878
".DownloadFile('{}', '{}')".format(url, path)],
69-
verbose=verbose)
79+
verbose=verbose,
80+
exception=exception)
7081
else:
7182
if probably_big or verbose:
7283
option = "-#"
7384
else:
7485
option = "-s"
75-
run(["curl", option, "--retry", "3", "-Sf", "-o", path, url], verbose=verbose)
86+
run(["curl", option, "--retry", "3", "-Sf", "-o", path, url],
87+
verbose=verbose,
88+
exception=exception)
7689

7790

7891
def verify(path, sha_path, verbose):
@@ -112,7 +125,7 @@ def unpack(tarball, dst, verbose=False, match=None):
112125
shutil.move(tp, fp)
113126
shutil.rmtree(os.path.join(dst, fname))
114127

115-
def run(args, verbose=False):
128+
def run(args, verbose=False, exception=False):
116129
if verbose:
117130
print("running: " + ' '.join(args))
118131
sys.stdout.flush()
@@ -122,7 +135,7 @@ def run(args, verbose=False):
122135
code = ret.wait()
123136
if code != 0:
124137
err = "failed to run: " + ' '.join(args)
125-
if verbose:
138+
if verbose or exception:
126139
raise RuntimeError(err)
127140
sys.exit(err)
128141

0 commit comments

Comments
 (0)