@@ -32,15 +32,15 @@ def get(url, path, verbose=False):
32
32
try :
33
33
download (sha_path , sha_url , verbose )
34
34
if os .path .exists (path ):
35
- try :
36
- verify (path , sha_path , verbose )
35
+ if verify (path , sha_path , verbose ):
37
36
print ("using already-download file " + path )
38
37
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" )
41
40
os .unlink (path )
42
41
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" )
44
44
print ("moving {} to {}" .format (temp_path , path ))
45
45
shutil .move (temp_path , path )
46
46
finally :
@@ -72,13 +72,12 @@ def verify(path, sha_path, verbose):
72
72
found = hashlib .sha256 (f .read ()).hexdigest ()
73
73
with open (sha_path , "r" ) as f :
74
74
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 "
77
78
" found: {}\n "
78
79
" expected: {}" .format (found , expected ))
79
- if verbose :
80
- raise RuntimeError (err )
81
- sys .exit (err )
80
+ return verified
82
81
83
82
84
83
def unpack (tarball , dst , verbose = False , match = None ):
0 commit comments