about summary refs log tree commit diff
path: root/src/bootstrap
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-07-06 03:30:47 -0700
committerGitHub <noreply@github.com>2016-07-06 03:30:47 -0700
commita120ae70d08d2eb991c7796e8726debb7ad46dea (patch)
treecd948e504cb1dcbbbe99f8b62209930d5a035494 /src/bootstrap
parent47380768e7debc2ee6b66e491733b89534e80988 (diff)
parent933a1036ae12d728b2ccffa560154a8011a4c256 (diff)
downloadrust-a120ae70d08d2eb991c7796e8726debb7ad46dea.tar.gz
rust-a120ae70d08d2eb991c7796e8726debb7ad46dea.zip
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.
Diffstat (limited to 'src/bootstrap')
-rw-r--r--src/bootstrap/bootstrap.py19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py
index 33de8fd0107..832911beb58 100644
--- a/src/bootstrap/bootstrap.py
+++ b/src/bootstrap/bootstrap.py
@@ -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:
@@ -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):