From ab5309e9e8467508766aee176dc121672d606524 Mon Sep 17 00:00:00 2001 From: Ximin Luo Date: Mon, 4 Jul 2016 16:37:46 +0200 Subject: [PATCH] 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. --- src/bootstrap/bootstrap.py | 8 ++++++++ src/etc/get-stage0.py | 2 -- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py index 33de8fd01076..49f00bf46f13 100644 --- a/src/bootstrap/bootstrap.py +++ b/src/bootstrap/bootstrap.py @@ -31,6 +31,14 @@ def get(url, path, verbose=False): try: download(sha_path, sha_url, verbose) + if os.path.exists(path): + try: + verify(path, sha_path, verbose) + print("using already-download file " + path) + return + except Exception as e: + print("failed verification for already-download file " + path) + os.unlink(path) download(temp_path, url, verbose) verify(temp_path, sha_path, verbose) print("moving {} to {}".format(temp_path, path)) diff --git a/src/etc/get-stage0.py b/src/etc/get-stage0.py index 28e3363189a0..127251cc802c 100644 --- a/src/etc/get-stage0.py +++ b/src/etc/get-stage0.py @@ -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'