Skip to content

Commit 718d0b8

Browse files
authored
Merge pull request #3 from maycuatroi/fix-temp-file-naming
Fix temp file naming to prevent overwriting during parallel downloads
2 parents 99be8cc + bb77741 commit 718d0b8

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

evo_downloader/downloader.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import logging
33
import os
44
import time
5+
import uuid
56

67
import humanize
78
import requests
@@ -115,6 +116,7 @@ def download_file(self, url, headers, folder_name, file_name):
115116
file_size = self.get_file_size(url, headers)
116117
chunk_size = file_size // self.num_threads
117118
supports_range = self.supports_range_requests(url, headers)
119+
unique_id = uuid.uuid4()
118120

119121
progress = Progress(
120122
"[progress.description]{task.description}",
@@ -143,7 +145,7 @@ def download_file(self, url, headers, folder_name, file_name):
143145
headers,
144146
i * chunk_size,
145147
((i + 1) * chunk_size - 1 if i < self.num_threads - 1 else file_size - 1),
146-
os.path.join(temp_folder, f"part_{i}"),
148+
os.path.join(temp_folder, f"part_{unique_id}_{i}"),
147149
progress,
148150
task_id,
149151
)
@@ -171,7 +173,7 @@ def download_file(self, url, headers, folder_name, file_name):
171173
if supports_range:
172174
with open(output_file_path, "wb") as final_file:
173175
for i in range(self.num_threads):
174-
temp_file_path = os.path.join(temp_folder, f"part_{i}")
176+
temp_file_path = os.path.join(temp_folder, f"part_{unique_id}_{i}")
175177
with open(temp_file_path, "rb") as part_file:
176178
final_file.write(part_file.read())
177179
os.remove(temp_file_path)

0 commit comments

Comments
 (0)