We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
download_file
1 parent 9612b06 commit 6f1eba5Copy full SHA for 6f1eba5
openfoodfacts/utils/__init__.py
@@ -2,7 +2,9 @@
2
import gzip
3
import json
4
import logging
5
+import random
6
import shutil
7
+import string
8
import time
9
from io import BytesIO
10
from pathlib import Path
@@ -189,7 +191,9 @@ def download_file(url: str, output_path: Path):
189
191
r = http_session.get(url, stream=True)
190
192
etag = r.headers.get("ETag", "").strip("'\"")
193
- tmp_output_path = output_path.with_name(output_path.name + ".part")
194
+ # add a random string to the output path to avoid concurrent writes
195
+ suffix = "".join(random.choices(string.ascii_letters, k=8))
196
+ tmp_output_path = output_path.with_name(output_path.name + f"-{suffix}.part")
197
with (
198
tmp_output_path.open("wb") as f,
199
tqdm.tqdm(
0 commit comments