Skip to content

Commit 7f75301

Browse files
committed
while downloading use temp directory
1 parent f29b5ed commit 7f75301

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

mergin/client_pull.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ def download_project_async(mc, project_path, directory, project_version=None):
146146
mp.log.info("--- version: " + mc.user_agent_info())
147147
mp.log.info(f"--- start download {project_path}")
148148

149+
tmp_dir = tempfile.TemporaryDirectory(prefix="python-api-client-")
150+
149151
try:
150152
# check whether we download the latest version or not
151153
latest_proj_info = mc.project_info(project_path)
@@ -155,15 +157,13 @@ def download_project_async(mc, project_path, directory, project_version=None):
155157
project_info = latest_proj_info
156158

157159
except ClientError:
158-
_cleanup_failed_download(directory, mp)
160+
_cleanup_failed_download(tmp_dir.name, mp)
159161
raise
160162

161163
version = project_info["version"] if project_info["version"] else "v0"
162164

163165
mp.log.info(f"got project info. version {version}")
164166

165-
tmp_dir = tempfile.TemporaryDirectory(prefix="python-api-client-")
166-
167167
# prepare download
168168
update_tasks = [] # stuff to do at the end of download
169169
for file in project_info["files"]:
@@ -182,9 +182,7 @@ def download_project_async(mc, project_path, directory, project_version=None):
182182

183183
mp.log.info(f"will download {len(update_tasks)} files in {len(download_list)} chunks, total size {total_size}")
184184

185-
job = DownloadJob(
186-
project_path, total_size, version, update_tasks, download_list, directory, mp, project_info, tmp_dir
187-
)
185+
job = DownloadJob(project_path, total_size, version, update_tasks, download_list, tmp_dir, mp, project_info)
188186

189187
# start download
190188
job.executor = concurrent.futures.ThreadPoolExecutor(max_workers=4)

0 commit comments

Comments
 (0)