diff options
author | Stefan Behnel <stefan_ml@behnel.de> | 2021-03-21 19:40:00 +0100 |
---|---|---|
committer | Stefan Behnel <stefan_ml@behnel.de> | 2021-03-21 19:43:25 +0100 |
commit | 40caae02ad3b5e820a90e533ce9c009b6b390545 (patch) | |
tree | 29f88cb069fa2945811854b791055728ab9dc3bc | |
parent | e71b0a81420ed5a7d1bbd9afba09c74dc6a47b28 (diff) | |
download | python-lxml-40caae02ad3b5e820a90e533ce9c009b6b390545.tar.gz |
Avoid race conditions when downloading artefacts.
-rwxr-xr-x | download_artefacts.py | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/download_artefacts.py b/download_artefacts.py index 10d47b85..cf82b4c0 100755 --- a/download_artefacts.py +++ b/download_artefacts.py @@ -65,14 +65,16 @@ def download1(wheel_url, dest_dir): and file_path.stat().st_size == int(w.headers["Content-Length"])): logger.info(f"Already have {wheel_name}") else: + temp_file_path = file_path.with_suffix(".tmp") try: - with open(file_path, "wb") as f: + with open(temp_file_path, "wb") as f: shutil.copyfileobj(w, f) except: - if file_path.exists(): - file_path.unlink() + if temp_file_path.exists(): + temp_file_path.unlink() raise else: + temp_file_path.replace(file_path) logger.info(f"Finished downloading {wheel_name}") return wheel_name |