Skip to content

feat(syncengine): fail and restart the sync if discovery is suspicious - #9572

Merged
nilsding merged 5 commits into
masterfrom
bugfix/noid/rediscover-after-deletion
Mar 10, 2026
Merged

feat(syncengine): fail and restart the sync if discovery is suspicious#9572
nilsding merged 5 commits into
masterfrom
bugfix/noid/rediscover-after-deletion

Conversation

@nilsding

@nilsding nilsding commented Mar 6, 2026

Copy link
Copy Markdown
Member

Apparently there was a change in Windows which causes the low-level APIs for iterating over directories to not return all contents when iterating over a just-changed folder that has cfapi enabled.

The file system watcher might have already caught the changes, but it could still be that during discovery those APIs are returning the wrong state. This is especially awful when folders are moved, as the rename detection will not work. In this specific case what happens is the following:

  • First sync run: during discovery only the origin folder is discovered as missing. Propagation: remote DELETE of the origin folder, and the sync DB is cleaned from all files inside that directory.
  • Second sync run: the sync engine detects the target folder, but the placeholder files inside it are unknown as they had been removed from the sync DB. As the folder structure is present locally, the folder tree will be propagated remotely, and all local virtual placeholder files are removed from the file system.

Therefore, to be on the safe side: fail the sync after discovery if there was at least one deletion once. A follow-up sync attempt is assumed to then have the correct view of the file system again.

See also: #8983

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Clang-Tidy found issue(s) with the introduced code (1/1)

Comment thread src/libsync/syncengine.h Outdated

@mgallien mgallien left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to enable this always or depending on a dedicated setting (or platform discovery) ?

@mgallien mgallien left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

windows automated tests for VFS are broken

@mgallien

mgallien commented Mar 9, 2026

Copy link
Copy Markdown
Collaborator

/backport! to stable-4.0

@nilsding
nilsding force-pushed the bugfix/noid/rediscover-after-deletion branch from ef960ae to 5add2e5 Compare March 10, 2026 11:18
@nilsding
nilsding enabled auto-merge March 10, 2026 11:57
@nilsding
nilsding force-pushed the bugfix/noid/rediscover-after-deletion branch 2 times, most recently from f155d6f to a1e8b9b Compare March 10, 2026 13:21
nilsding and others added 5 commits March 10, 2026 15:40
otherwise the debug logs will never be enabled by the
"nextcloud.*.debug=true" rule

Signed-off-by: Jyrki Gadinger <[email protected]>
Especially with many file changes incoming, by the time the sync
actually starts the local discovery list might not have caught all
changes yet.

Signed-off-by: Jyrki Gadinger <[email protected]>
Apparently there was a change in Windows which causes the low-level APIs
for iterating over directories to not return all contents when iterating
over a just-changed folder that has cfapi enabled.

The file system watcher might have already caught the changes, but it
could still be that during discovery those APIs are returning the wrong
state.  This is especially awful when folders are moved, as the rename
detection will not work.  In this specific case what happens is the
following:
- First sync run: during discovery only the origin folder is discovered
  as missing.  Propagation: remote DELETE of the origin folder, and the
  sync DB is cleaned from all files inside that directory.
- Second sync run: the sync engine detects the target folder, but the
  placeholder files inside it are unknown as they had been removed from
  the sync DB.  As the folder structure is present locally, the folder
  tree will be propagated remotely, and all local virtual placeholder
  files are removed from the file system.

Therefore, to be on the safe side: fail the sync after discovery if
there was at least one deletion once.  A follow-up sync attempt is
assumed to then have the correct view of the file system again.

See also: #8983

Signed-off-by: Jyrki Gadinger <[email protected]>
add extra sync runs as needed

Signed-off-by: Matthieu Gallien <[email protected]>
Signed-off-by: Jyrki Gadinger <[email protected]>
@nilsding
nilsding force-pushed the bugfix/noid/rediscover-after-deletion branch from a1e8b9b to 2b0deab Compare March 10, 2026 14:40
@nilsding nilsding added this to the 33.0.0 milestone Mar 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Artifact containing the AppImage: nextcloud-appimage-pr-9572.zip

Digest: sha256:2a8dfa8fe66aefdc70f303659870f2cad6d80e6beee4399f376b51759d4c37de

To test this change/fix you can download the above artifact file, unzip it, and run it.

Please make sure to quit your existing Nextcloud app and backup your data.

@nilsding
nilsding disabled auto-merge March 10, 2026 16:01
@nilsding
nilsding enabled auto-merge March 10, 2026 16:01
@nilsding
nilsding disabled auto-merge March 10, 2026 16:02
@nilsding
nilsding merged commit ef3d123 into master Mar 10, 2026
21 of 22 checks passed
@nilsding
nilsding deleted the bugfix/noid/rediscover-after-deletion branch March 10, 2026 16:02
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
44.4% Coverage on New Code (required ≥ 80%)
E Reliability Rating on New Code (required ≥ A)
73 New Code Smells (required ≤ 0)
D Maintainability Rating on New Code (required ≥ A)
1 New Bugs (required ≤ 0)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@mgallien mgallien modified the milestones: 33.0.0, 34.0.0 Mar 12, 2026
@nilsding

Copy link
Copy Markdown
Member Author

/backport to stable-33.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: 4.0.0 Random files are deleted (Moved to Trash)

2 participants