diff --git a/morgan/__init__.py b/morgan/__init__.py index 0e930a6..873b8e2 100644 --- a/morgan/__init__.py +++ b/morgan/__init__.py @@ -388,7 +388,12 @@ def _download_file( truehash = self._hash_file(target, hashalg) if truehash != exphash: - raise Exception("Digest mismatch for {}".format(fileinfo["filename"])) + os.remove(target) + raise ValueError( + "Digest mismatch for {}. Deleting file {}.".format( + fileinfo["filename"], target + ) + ) return True