]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
Downloader: download to temporary file, then replace
authorAarni Koskela <akx@iki.fi>
Wed, 13 Jul 2022 11:28:25 +0000 (14:28 +0300)
committerAarni Koskela <akx@iki.fi>
Wed, 13 Jul 2022 11:28:25 +0000 (14:28 +0300)
scripts/download_import_cldr.py

index 2cdb1fc42630e059c4faed4c60c52cd49a82b029..3ddd9b47d60396da402a75123d7a796aafb54235 100755 (executable)
@@ -64,9 +64,9 @@ def main():
 
     while not is_good_file(zip_path):
         log("Downloading '%s' from %s", FILENAME, URL)
-        if os.path.isfile(zip_path):
-            os.remove(zip_path)
-        urlretrieve(URL, zip_path, (reporthook if show_progress else None))
+        tmp_path = f"{zip_path}.tmp"
+        urlretrieve(URL, tmp_path, (reporthook if show_progress else None))
+        os.replace(tmp_path, zip_path)
         changed = True
         print()
     common_path = os.path.join(cldr_path, 'common')