Skip to content

Commit 7af59d9

Browse files
authored
Merge pull request #585 from MerginMaps/log-diffs
Make also subdirectories in diffs folder
2 parents 9d2755a + 7e25d37 commit 7af59d9

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

server/mergin/sync/files.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,6 @@ def to_data_delta(self):
286286
change=self.change,
287287
version=self.version,
288288
)
289-
if self.diffs:
290-
result.diff = self.diffs[0].id
291289
return result
292290

293291

@@ -332,6 +330,9 @@ def make_object(self, data, **kwargs):
332330

333331
@post_dump
334332
def patch_field(self, data, **kwargs):
333+
assert data.get("change") != PushChangeType.UPDATE_DIFF.value or data.get(
334+
"diff"
335+
), "Diff file must be provided for update_diff change type"
335336
# drop 'diff' key entirely if empty or None as database would expect
336337
if not data.get("diff"):
337338
data.pop("diff", None)

server/mergin/sync/models.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,9 @@ def construct_checkpoint(self) -> bool:
10301030
return False
10311031

10321032
project: Project = basefile.file.project
1033-
os.makedirs(project.storage.diffs_dir, exist_ok=True)
1033+
1034+
# create diffs directory if not exists and subfolders in case of diffs/subfolder/diff-file
1035+
os.makedirs(os.path.dirname(self.abs_path), exist_ok=True)
10341036

10351037
try:
10361038
if len(diffs_paths) == 1:
@@ -1041,7 +1043,7 @@ def construct_checkpoint(self) -> bool:
10411043
project.storage.geodiff.concat_changes(diffs_paths, self.abs_path)
10421044
except (GeoDiffLibError, GeoDiffLibConflictError):
10431045
logging.error(
1044-
f"Geodiff: Failed to merge diffs for file {self.file_path_id}"
1046+
f"Geodiff: Failed to merge diffs for file {self.file_path_id}."
10451047
)
10461048
return False
10471049

@@ -1357,6 +1359,11 @@ def create_checkpoint(
13571359
# Patch the delta with the path to the new diff checkpoint
13581360
item.diff = checkpoint_diff.path
13591361
db.session.add(checkpoint_diff)
1362+
else:
1363+
# checkpoint already exists, just patch the delta with the path to the existing diff checkpoint
1364+
# this could happen when file diff exists but dela was missing
1365+
# this allowing us to remove rank > 0 delta checkpoints in case of inconsistencies
1366+
item.diff = existing_diff_checkpoint.path
13601367

13611368
checkpoint_delta = ProjectVersionDelta(
13621369
project_id=project_id,

0 commit comments

Comments
 (0)