Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions mergin/merginproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -1042,23 +1042,22 @@ def resolve_unfinished_pull(self, user_name):

self.log.info("resolving unfinished pull")

temp_dir = tempfile.mkdtemp(prefix="python-api-client-")

for root, dirs, files in os.walk(self.unfinished_pull_dir):
for file_name in files:
src = os.path.join(root, file_name)
dest = self.fpath(file_name)
basefile = self.fpath_meta(file_name)
file_path = os.path.relpath(src, self.unfinished_pull_dir)
dest = self.fpath(file_path)
basefile = self.fpath_meta(file_path)

self.log.info("trying to resolve unfinished pull for: " + file_name)
self.log.info("trying to resolve unfinished pull for: " + file_path)

# 'src' here is a server version of the file from unfinished
# pull and 'dest' is a local version of the same file.
# to resolve unfinished pull we create a conflicted copy and
# replace local file with the changes from the server.
try:
# conflicted copy
conflict = self.create_conflicted_copy(dest, user_name)
conflict = self.create_conflicted_copy(file_path, user_name)
conflicts.append(conflict)
# original file synced with server
self.geodiff.make_copy_sqlite(src, basefile)
Expand Down
19 changes: 10 additions & 9 deletions mergin/test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1973,17 +1973,15 @@ def test_unfinished_pull(mc):
project = create_project_path(test_project, mc)
project_dir = os.path.join(TMP_DIR, test_project) # primary project dir
project_dir_2 = os.path.join(TMP_DIR, test_project + "_2") # concurrent project dir
unfinished_pull_dir = os.path.join(
TMP_DIR, test_project, ".mergin", "unfinished_pull"
) # unfinished_pull dir for the primary project
test_gpkg = os.path.join(project_dir, "test.gpkg")
test_gpkg_2 = os.path.join(project_dir_2, "test.gpkg")
test_gpkg_basefile = os.path.join(project_dir, ".mergin", "test.gpkg")
test_gpkg = os.path.join(project_dir, "subfolder", "test.gpkg")
test_gpkg_2 = os.path.join(project_dir_2, "subfolder", "test.gpkg")
test_gpkg_basefile = os.path.join(project_dir, ".mergin", "subfolder", "test.gpkg")
test_gpkg_conflict = conflicted_copy_file_name(test_gpkg, mc.username(), 2)
test_gpkg_unfinished_pull = os.path.join(project_dir, ".mergin", "unfinished_pull", "test.gpkg")
test_gpkg_unfinished_pull = os.path.join(project_dir, ".mergin", "unfinished_pull", "subfolder", "test.gpkg")
cleanup(mc, project, [project_dir, project_dir_2])

os.makedirs(project_dir)
os.makedirs(os.path.join(project_dir, "subfolder"), exist_ok=True)
shutil.copy(os.path.join(TEST_DATA_DIR, "base.gpkg"), test_gpkg)
_use_wal(test_gpkg) # make sure we use WAL, that's the more common and more difficult scenario
mc.create_project_and_push(project, project_dir)
Expand All @@ -1998,8 +1996,8 @@ def test_unfinished_pull(mc):
_use_wal(test_gpkg) # make sure we use WAL

pull_changes, push_changes, _ = mc.project_status(project_dir)
assert _is_file_updated("test.gpkg", pull_changes)
assert _is_file_updated("test.gpkg", push_changes)
assert _is_file_updated("subfolder/test.gpkg", pull_changes)
assert _is_file_updated("subfolder/test.gpkg", push_changes)

assert not os.path.exists(test_gpkg_conflict)
assert not mc.has_unfinished_pull(project_dir)
Expand Down Expand Up @@ -2050,6 +2048,9 @@ def test_unfinished_pull(mc):
assert _get_table_row_count(test_gpkg_basefile, "simple") == 3
assert _get_table_row_count(test_gpkg_conflict, "simple") == 4

mc.push_project(project_dir)
mc.push_project(project_dir_2)


@pytest.mark.skipif(sudo_works(), reason="needs working sudo")
def test_unfinished_pull_push(mc):
Expand Down
Loading