From 8621f5a44fd0cfb65553c40ad38c6de6501d3132 Mon Sep 17 00:00:00 2001 From: Christian Schmidbauer Date: Tue, 7 Oct 2025 17:28:31 +0200 Subject: [PATCH] fix: remove files with digest mismatch Avoid having invalid files in the index directory after a corrupted download. --- morgan/__init__.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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