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: