Skip to content
Merged
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
15 changes: 13 additions & 2 deletions mergin/client_pull.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,13 +494,20 @@ def pull_project_finalize(job):
# make sure any exceptions from threads are not lost
for future in job.futures:
if future.exception() is not None:
job.mp.log.error("Error while downloading data: " + str(future.exception()))
job.mp.log.info("--- pull aborted")
raise future.exception()

job.mp.log.info("finalizing pull")

# merge downloaded chunks
for file_to_merge in job.files_to_merge:
file_to_merge.merge()
try:
for file_to_merge in job.files_to_merge:
file_to_merge.merge()
except ClientError as err:
job.mp.log.error("Error merging chunks of downloaded file: " + str(err))
job.mp.log.info("--- pull aborted")
raise

# make sure we can update geodiff reference files (aka. basefiles) with diffs or
# download their full versions so we have them up-to-date for applying changes
Expand All @@ -517,6 +524,10 @@ def pull_project_finalize(job):
# was also able to apply those diffs. It could be that someone modified
# the basefile and we ended up in this inconsistent state.
# let's remove the basefile and let the user retry - we should download clean version again
job.mp.log.error(f"Error patching basefile {basefile}")
job.mp.log.error("Diffs we were applying: " + str(diffs))
job.mp.log.error("Removing basefile because it would be corrupted anyway...")
job.mp.log.info("--- pull aborted")
os.remove(basefile)
raise ClientError("Cannot patch basefile {}! Please try syncing again.".format(basefile))

Expand Down
17 changes: 12 additions & 5 deletions mergin/merginproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,21 @@ def get_pull_changes(self, server_files):
diffs = []
diffs_size = 0
is_updated = False

# get sorted list of the history (they may not be sorted or using lexical sorting - "v10", "v11", "v5", "v6", ...)
history_list = []
for version_str, version_info in file['history'].items():
history_list.append( (int_version(version_str), version_info) )
history_list = sorted(history_list, key=lambda item: item[0]) # sort tuples based on version numbers

# need to track geodiff file history to see if there were any changes
for k, v in file['history'].items():
if int_version(k) <= int_version(self.metadata['version']):
for version, version_info in history_list:
if version <= int_version(self.metadata['version']):
continue # ignore history of no interest
is_updated = True
if 'diff' in v:
diffs.append(v['diff']['path'])
diffs_size += v['diff']['size']
if 'diff' in version_info:
diffs.append(version_info['diff']['path'])
diffs_size += version_info['diff']['size']
else:
diffs = []
break # we found force update in history, does not make sense to download diffs
Expand Down