Skip to content

Commit 912a9d0

Browse files
committed
Have verify() return a bool rather than a generic RuntimeError
1 parent ab5309e commit 912a9d0

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/bootstrap/bootstrap.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ def get(url, path, verbose=False):
3232
try:
3333
download(sha_path, sha_url, verbose)
3434
if os.path.exists(path):
35-
try:
36-
verify(path, sha_path, verbose)
35+
if verify(path, sha_path, verbose):
3736
print("using already-download file " + path)
3837
return
39-
except Exception as e:
40-
print("failed verification for already-download file " + path)
38+
else:
39+
print("ignoring already-download file " + path + " due to failed verification")
4140
os.unlink(path)
4241
download(temp_path, url, verbose)
43-
verify(temp_path, sha_path, verbose)
42+
if not verify(temp_path, sha_path, verbose):
43+
raise RuntimeError("failed verification")
4444
print("moving {} to {}".format(temp_path, path))
4545
shutil.move(temp_path, path)
4646
finally:
@@ -72,13 +72,12 @@ def verify(path, sha_path, verbose):
7272
found = hashlib.sha256(f.read()).hexdigest()
7373
with open(sha_path, "r") as f:
7474
expected, _ = f.readline().split()
75-
if found != expected:
76-
err = ("invalid checksum:\n"
75+
verified = found == expected
76+
if not verified and verbose:
77+
print("invalid checksum:\n"
7778
" found: {}\n"
7879
" expected: {}".format(found, expected))
79-
if verbose:
80-
raise RuntimeError(err)
81-
sys.exit(err)
80+
return verified
8281

8382

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

0 commit comments

Comments
 (0)