Skip to content

Commit

Permalink
Auto merge of rust-lang#34644 - infinity0:master, r=alexcrichton
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Jul 6, 2016
2 parents 4738076 + 933a103 commit a120ae7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
19 changes: 13 additions & 6 deletions src/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,16 @@ def get(url, path, verbose=False):

try:
download(sha_path, sha_url, verbose)
if os.path.exists(path):
if verify(path, sha_path, False):
print("using already-download file " + path)
return
else:
print("ignoring already-download file " + path + " due to failed verification")
os.unlink(path)
download(temp_path, url, verbose)
verify(temp_path, sha_path, verbose)
if not verify(temp_path, sha_path, True):
raise RuntimeError("failed verification")
print("moving {} to {}".format(temp_path, path))
shutil.move(temp_path, path)
finally:
Expand Down Expand Up @@ -64,13 +72,12 @@ def verify(path, sha_path, verbose):
found = hashlib.sha256(f.read()).hexdigest()
with open(sha_path, "r") as f:
expected, _ = f.readline().split()
if found != expected:
err = ("invalid checksum:\n"
verified = found == expected
if not verified and verbose:
print("invalid checksum:\n"
" found: {}\n"
" expected: {}".format(found, expected))
if verbose:
raise RuntimeError(err)
sys.exit(err)
return verified


def unpack(tarball, dst, verbose=False, match=None):
Expand Down
2 changes: 0 additions & 2 deletions src/etc/get-stage0.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ def main(triple):
filename = 'rustc-{}-{}.tar.gz'.format(channel, triple)
url = 'https://static.rust-lang.org/dist/{}/{}'.format(date, filename)
dst = dl_dir + '/' + filename
if os.path.exists(dst):
os.unlink(dst)
bootstrap.get(url, dst)

stage0_dst = triple + '/stage0'
Expand Down

0 comments on commit a120ae7

Please sign in to comment.