350 else: |
350 else: |
351 # If the signature validated, then we assume |
351 # If the signature validated, then we assume |
352 # that the expected hash is just a typo, but we |
352 # that the expected hash is just a typo, but we |
353 # warn just in case. |
353 # warn just in case. |
354 if sig_valid: |
354 if sig_valid: |
355 print "invalid hash!" |
355 print "invalid hash! Did you forget " \ |
|
356 "to update it?" |
356 else: |
357 else: |
357 print "corruption detected" |
358 print "corruption detected" |
358 |
359 |
359 print " expected: %s" % hash_arg |
360 print " expected: %s" % hash_arg |
360 print " actual: %s" % realhash |
361 print " actual: %s" % realhash |
361 print " payload: %s" % payloadhash |
362 print " payload: %s" % payloadhash |
362 |
363 |
363 # An invalid hash shouldn't cause us to remove |
364 # If the hash is invalid, but the signature |
364 # the target file if the signature was valid. |
365 # validation succeeded, rename the archive (so |
365 if not sig_valid: |
366 # the user doesn't have to re-download it) and |
|
367 # fail. Otherwise, try to remove the file and |
|
368 # try again. |
|
369 if sig_valid: |
|
370 newname = name + ".invalid-hash" |
|
371 try: |
|
372 os.rename(name, newname) |
|
373 except OSError: |
|
374 pass |
|
375 else: |
|
376 print "archive saved as %s; " \ |
|
377 "if it isn't corrupt, " \ |
|
378 "rename to %s" % (newname, |
|
379 name) |
|
380 sys.exit(1) |
|
381 else: |
366 try: |
382 try: |
367 os.remove(name) |
383 os.remove(name) |
368 except OSError: |
384 except OSError: |
369 pass |
385 pass |
370 |
386 |