|
2 | 2 | import logging
|
3 | 3 | import os
|
4 | 4 | import time
|
| 5 | +import uuid |
5 | 6 |
|
6 | 7 | import humanize
|
7 | 8 | import requests
|
@@ -115,6 +116,7 @@ def download_file(self, url, headers, folder_name, file_name):
|
115 | 116 | file_size = self.get_file_size(url, headers)
|
116 | 117 | chunk_size = file_size // self.num_threads
|
117 | 118 | supports_range = self.supports_range_requests(url, headers)
|
| 119 | + unique_id = uuid.uuid4() |
118 | 120 |
|
119 | 121 | progress = Progress(
|
120 | 122 | "[progress.description]{task.description}",
|
@@ -143,7 +145,7 @@ def download_file(self, url, headers, folder_name, file_name):
|
143 | 145 | headers,
|
144 | 146 | i * chunk_size,
|
145 | 147 | ((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}"), |
147 | 149 | progress,
|
148 | 150 | task_id,
|
149 | 151 | )
|
@@ -171,7 +173,7 @@ def download_file(self, url, headers, folder_name, file_name):
|
171 | 173 | if supports_range:
|
172 | 174 | with open(output_file_path, "wb") as final_file:
|
173 | 175 | 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}") |
175 | 177 | with open(temp_file_path, "rb") as part_file:
|
176 | 178 | final_file.write(part_file.read())
|
177 | 179 | os.remove(temp_file_path)
|
|
0 commit comments