Skip to content

Commit 9fe9f15

Browse files
committed
Fix download/pull of subdirs with just empty file(s)
Fixes MerginMaps/qgis-plugin#160
1 parent 419f2d9 commit 9fe9f15

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

mergin/client_pull.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ def apply(self, directory, mp):
237237
basename = os.path.basename(self.file_path) #file['diff']['path']) if diff_only else os.path.basename(file['path'])
238238
file_dir = os.path.dirname(os.path.normpath(os.path.join(directory, self.file_path)))
239239
dest_file_path = os.path.join(file_dir, basename)
240+
os.makedirs(file_dir, exist_ok=True)
240241

241242
# merge chunks together (and delete them afterwards)
242243
file_to_merge = FileToMerge(dest_file_path, self.download_queue_items)
@@ -372,6 +373,7 @@ def pull_project_async(mc, directory):
372373
file_dir = os.path.dirname(os.path.normpath(os.path.join(temp_dir, file['path'])))
373374
basename = os.path.basename(file['diff']['path']) if diff_only else os.path.basename(file['path'])
374375
dest_file_path = os.path.join(file_dir, basename)
376+
os.makedirs(file_dir, exist_ok=True)
375377
files_to_merge.append( FileToMerge(dest_file_path, items) )
376378

377379

mergin/test/test_client.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,3 +428,32 @@ def test_missing_basefile_pull(mc):
428428
# try to sync again -- it should not crash
429429
mc.pull_project(project_dir)
430430
mc.push_project(project_dir)
431+
432+
433+
def test_empty_file_in_subdir(mc):
434+
""" Test pull of a project where there is an empty file in a sub-directory """
435+
436+
test_project = 'test_empty_file_in_subdir'
437+
project = API_USER + '/' + test_project
438+
project_dir = os.path.join(TMP_DIR, test_project) # primary project dir for updates
439+
project_dir_2 = os.path.join(TMP_DIR, test_project + '_2') # concurrent project dir
440+
test_data_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), test_project)
441+
442+
cleanup(mc, project, [project_dir, project_dir_2])
443+
# create remote project
444+
shutil.copytree(test_data_dir, project_dir)
445+
mc.create_project_and_push(test_project, project_dir)
446+
447+
# try to check out the project
448+
mc.download_project(project, project_dir_2)
449+
assert os.path.exists(os.path.join(project_dir_2, 'subdir', 'empty.txt'))
450+
451+
# add another empty file in a different subdir
452+
os.mkdir(os.path.join(project_dir, 'subdir2'))
453+
shutil.copy(os.path.join(project_dir, 'subdir', 'empty.txt'),
454+
os.path.join(project_dir, 'subdir2', 'empty2.txt'))
455+
mc.push_project(project_dir)
456+
457+
# check that pull works fine
458+
mc.pull_project(project_dir_2)
459+
assert os.path.exists(os.path.join(project_dir_2, 'subdir2', 'empty2.txt'))
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hello Mergin

mergin/test/test_empty_file_in_subdir/subdir/empty.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)