Skip to content

Commit a120ae7

Browse files
authored
Auto merge of #34644 - infinity0:master, r=alexcrichton
Avoid redundant downloads when bootstrapping If the local file is available, then verify it against the hash we just downloaded, and if it matches then we don't need to download it again.
2 parents 4738076 + 933a103 commit a120ae7

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/bootstrap/bootstrap.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,16 @@ def get(url, path, verbose=False):
3131

3232
try:
3333
download(sha_path, sha_url, verbose)
34+
if os.path.exists(path):
35+
if verify(path, sha_path, False):
36+
print("using already-download file " + path)
37+
return
38+
else:
39+
print("ignoring already-download file " + path + " due to failed verification")
40+
os.unlink(path)
3441
download(temp_path, url, verbose)
35-
verify(temp_path, sha_path, verbose)
42+
if not verify(temp_path, sha_path, True):
43+
raise RuntimeError("failed verification")
3644
print("moving {} to {}".format(temp_path, path))
3745
shutil.move(temp_path, path)
3846
finally:
@@ -64,13 +72,12 @@ def verify(path, sha_path, verbose):
6472
found = hashlib.sha256(f.read()).hexdigest()
6573
with open(sha_path, "r") as f:
6674
expected, _ = f.readline().split()
67-
if found != expected:
68-
err = ("invalid checksum:\n"
75+
verified = found == expected
76+
if not verified and verbose:
77+
print("invalid checksum:\n"
6978
" found: {}\n"
7079
" expected: {}".format(found, expected))
71-
if verbose:
72-
raise RuntimeError(err)
73-
sys.exit(err)
80+
return verified
7481

7582

7683
def unpack(tarball, dst, verbose=False, match=None):

src/etc/get-stage0.py

-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ def main(triple):
3131
filename = 'rustc-{}-{}.tar.gz'.format(channel, triple)
3232
url = 'https://static.rust-lang.org/dist/{}/{}'.format(date, filename)
3333
dst = dl_dir + '/' + filename
34-
if os.path.exists(dst):
35-
os.unlink(dst)
3634
bootstrap.get(url, dst)
3735

3836
stage0_dst = triple + '/stage0'

0 commit comments

Comments
 (0)