Skip to content

Commit 1416e5e

Browse files
committed
Changes suggested in the review.
1 parent f51cb7c commit 1416e5e

1 file changed

Lines changed: 10 additions & 11 deletions

File tree

mergin/client_pull.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,11 @@ class UpdateTask:
234234
"""
235235

236236
# TODO: methods other than COPY
237-
def __init__(self, file_path, download_queue_items, destination_file=None, remove_download_dir=False):
237+
def __init__(self, file_path, download_queue_items, destination_file=None):
238238
self.file_path = file_path
239239
self.destination_file = destination_file
240240
self.download_queue_items = download_queue_items
241-
self.remove_download_dir = remove_download_dir
242-
241+
243242
def apply(self, directory, mp):
244243
""" assemble downloaded chunks into a single file """
245244

@@ -261,13 +260,6 @@ def apply(self, directory, mp):
261260
if mp.is_versioned_file(self.file_path) and self.destination_file is None:
262261
mp.geodiff.make_copy_sqlite(mp.fpath(self.file_path), mp.fpath_meta(self.file_path))
263262

264-
# For single file download, chunks are saved in a temporary dir that needs to be removed manually
265-
if self.remove_download_dir:
266-
# extract download dir from the first download item
267-
download_item = self.download_queue_items[0]
268-
download_dir = os.path.dirname(download_item.download_file_path)
269-
shutil.rmtree(download_dir)
270-
271263

272264
class DownloadQueueItem:
273265
""" a piece of data from a project that should be downloaded - it can be either a chunk or it can be a diff """
@@ -595,7 +587,7 @@ def download_file_async(mc, project_dir, file_path, output_file, version):
595587
if file["path"] == file_path:
596588
file['version'] = version
597589
items = _download_items(file, temp_dir)
598-
task = UpdateTask(file['path'], items, output_file, remove_download_dir=True)
590+
task = UpdateTask(file['path'], items, output_file)
599591
download_list.extend(task.download_queue_items)
600592
for item in task.download_queue_items:
601593
total_size += item.size
@@ -633,8 +625,15 @@ def download_file_finalize(job):
633625

634626
job.mp.log.info("--- download finished")
635627

628+
temp_dir = None
636629
for task in job.update_tasks:
637630
task.apply(job.directory, job.mp)
631+
if task.download_queue_items:
632+
temp_dir = os.path.dirname(task.download_queue_items[0].download_file_path)
633+
634+
# Remove temporary download directory
635+
if temp_dir is not None:
636+
shutil.rmtree(temp_dir)
638637

639638

640639
def download_diffs_async(mc, project_directory, file_path, version_from, version_to):

0 commit comments

Comments
 (0)