Skip to content

WIP: Fix sync loop for too long path - #316

Open
harminius wants to merge 2 commits into
masterfrom
fix/sync_loop_for_too_long_path
Open

WIP: Fix sync loop for too long path#316
harminius wants to merge 2 commits into
masterfrom
fix/sync_loop_for_too_long_path

Conversation

@harminius

@harminius harminius commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Fixes MerginMaps/qgis-plugin#932

Every opened gpkg is treated as potentially updated, and we rely on geodiff to calculate the real changes. Geodiff creates an empty diff file even when there is no change.
The root cause of the issue is that geodiff's create_changeset() fails because it's not possible to create the diff file due to the filename length limit. It then uploads the whole file, but the change is still pending, so it tries indefinitely.

except (pygeodiff.GeoDiffLibError, pygeodiff.GeoDiffLibConflictError) as e:

This is a minimal fix for the issue.
There are other enhancements/issue mitigations:

  1. Shorten diff name
    Store diff files locally under a short, flat name, decoupled from the file's path in the project — e.g. .mergin/diffs/ instead of .mergin/-diff-. Fixes works esp. for files nested deep in the subfolders. This does not require server changes - the server doesn't care what we call the local file.
Path Length
Live file <rel> P + R + 1
Basefile .mergin<rel> — already mandatory today P + R + 9
Diff today .mergin<rel>-diff- P + R + 51
Diff flattened .mergin\diffs<uuid> P + 51 (constant)
Same, 16-char id P + 31 (constant)
  1. Safeguard for any infinity sync loop
    sync_project_generator's while has_changes has no iteration limit. Track, per file, how many consecutive iterations it was pushed as a full upload with no diff; if the same versioned file does this N times in a row (e.g. 2–3), raise a ClientError naming the file instead of continuing. This is cause-agnostic - it also protects against any other future reason a changeset can't be computed.

  2. Long path error workaround
    Use \\?\-prefixed paths for geodiff calls and other file I/O once a resolved path is close to/over MAX_PATH. This is the only thing that helps when the diff file path is what's too long. Verified to work with our pinned geodiff/pygeodiff version; requires care to always pass fully-normalized absolute paths once prefixed. This is more invasive.

@harminius harminius changed the title Fix sync loop for too long path WIP: Fix sync loop for too long path Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sync loop path to diff files in .mergin folder exceeds 260 characters

1 participant