From 35e3aa2097d5889b1954cd4898b9f5a2cdd5f5cb Mon Sep 17 00:00:00 2001 From: Adam Leach Date: Sat, 21 Jan 2023 16:48:57 +0000 Subject: [PATCH] Fix saving etag for incomplete repo.json download. --- knossos/tasks.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/knossos/tasks.py b/knossos/tasks.py index 51bd808..f50de92 100644 --- a/knossos/tasks.py +++ b/knossos/tasks.py @@ -88,8 +88,8 @@ def work1(self, part): data.base = link if result not in (304, True): - # We got an ETag - with open(dest_path + '.etag', 'w') as hdl: + # We got an ETag, write it to a temp file + with open(dest_path + '.etag.tmp', 'w') as hdl: hdl.write(result) break @@ -106,6 +106,14 @@ def work1(self, part): with open(dest_path, 'r') as dest: data.parse(dest.read()) + # We've successfully parsed the downloaded data, + # so we know we've got a complete mods.json. + # It's now safe to replace the existing etag file. + if os.path.isfile(dest_path + '.etag'): + os.unlink(dest_path) + + os.rename(dest_path + '.etag.tmp', dest_path + '.etag') + self._public = data except Exception: