diff --git a/lib/obs.py b/lib/obs.py index 94aae4f..c4558cf 100644 --- a/lib/obs.py +++ b/lib/obs.py @@ -1,5 +1,6 @@ import errno import logging +import os import shutil import time import urllib.parse @@ -169,11 +170,12 @@ class OBS: with (dirpath / name).open("wb") as f: f.write(self._download(project, package, name, revision).read()) - shutil.copy(dirpath / name, cached_file) - # Validate the MD5 of the downloaded file - if md5(cached_file) != file_md5: + if md5(dirpath / name) != file_md5: raise Exception(f"Download error in {name}") + + shutil.copy(dirpath / name, cached_file.with_suffix(".new")) + os.rename(cached_file.with_suffix(".new"), cached_file) else: shutil.copy(cached_file, dirpath / name)