Skip to content

fix(file-provider): prevent data loss when parent folder moves during sync.#10134

Merged
mgallien merged 2 commits into
masterfrom
bugfix/fpext-prevent-data-loss-on-move
Jun 12, 2026
Merged

fix(file-provider): prevent data loss when parent folder moves during sync.#10134
mgallien merged 2 commits into
masterfrom
bugfix/fpext-prevent-data-loss-on-move

Conversation

@camilasan

@camilasan camilasan commented Jun 9, 2026

Copy link
Copy Markdown
Member

Resolves

This PR is related to #10130, better to merge it afterwards.

Moving a folder on another client could silently wipe its contents from the device. An in-flight upload through a deleted parent would lose data permanently. Reporting children before the parent causes macOS to create a duplicate folder.

Summary

Items found at a new location are not deleted; pending uploads and open lock files are protected — the enumerator now waits until the full sync pass completes before deciding what is deleted, using a survivingOcIds set to spare anything found at a new path. Items mid-upload and local-origin lock files are excluded from deletion even when their parent is removed. Items are also sorted parent-before-child before being reported to macOS to prevent duplicate folders caused by ordering.

Steps to test it

Scenario A — Moved item is not deleted:

  1. Create doc.txt in FolderA. Let it sync.
  2. Move doc.txt into FolderB from the web UI.
  3. Wait for next sync cycle.
    ✅ doc.txt must appear inside FolderB in Finder.
    ✅ doc.txt must not appear as deleted anywhere.

Scenario B — Upload protection:

  1. Start uploading a large file (500 MB+) into FolderA.
  2. While uploading, delete FolderA from the web UI.
    ✅ The upload must complete and the file must appear on the server.
    ✅ The uploading file must not be silently lost.

Scenario C — No duplicate folder on rename (no editor open):

  1. Create FolderA with a file inside. Let it sync and open the file in an editor.
  2. Rename FolderA → FolderA-renamed from the web UI.
    ✅ Only FolderA-renamed must appear in Finder — no duplicate FolderA.

When pendingWorkingSetChanges returns items in undefined Realm order, a child item at its new path (FolderA-renamed/file.txt) can arrive in the didUpdate list before the parent rename (FolderA → FolderA-renamed).

macOS processes the child first: "file.txt belongs in FolderA-renamed/ but that folder doesn't exist yet" → macOS creates FolderA-renamed/ as a new folder. Then it processes the rename: "rename FolderA → FolderA-renamed" but FolderA-renamed already exists → macOS can't complete the rename → both FolderA and FolderA-renamed remain.

Sorting parent directories before their children guarantees macOS sees FolderA renamed to FolderA-renamed first, renames the folder on disk, and then places children inside it without creating a duplicate.

Checklist

AI (if applicable)

@camilasan camilasan changed the title Bugfix/fpext prevent data loss on move fix(file-provider): prevent data loss when parent folder moves during sync. Jun 9, 2026
@camilasan

Copy link
Copy Markdown
Member Author

/backport to stable-33.0

@camilasan

Copy link
Copy Markdown
Member Author

/backport to stable-4.0

@camilasan camilasan added this to the 33.0.6 milestone Jun 9, 2026
@camilasan camilasan modified the milestones: 33.0.6, 34.0.0 Jun 10, 2026
@camilasan camilasan force-pushed the bugfix/fpext-prevent-data-loss-on-move branch 2 times, most recently from fd77c43 to bc8c316 Compare June 10, 2026 12:26
@camilasan camilasan marked this pull request as ready for review June 10, 2026 12:26
@camilasan camilasan force-pushed the bugfix/fpext-prevent-data-loss-on-move branch from bc8c316 to 70d9ec9 Compare June 10, 2026 13:30
@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Contributor

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

Digest: sha256:2d49c31af6c898fc9ac9ac4177ddc9581c74b1a67353f47d56be3666da3101d3

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.

… sync.

When a parent directory returns 404, children are no longer eagerly
marked deleted — they may have moved with the parent. The
deconfliction pass now includes newly discovered items, and items
with pending uploads are protected from deletion in both the
enumerator and recursive directory delete paths.

Assisted-by: Claude:claude-sonnet-4-5
Signed-off-by: Camila Ayres <hello@camilasan.com>
Assisted-by: Claude:claude-sonnet-4-5
Signed-off-by: Camila Ayres <hello@camilasan.com>
@mgallien mgallien force-pushed the bugfix/fpext-prevent-data-loss-on-move branch from 70d9ec9 to d24c1cf Compare June 12, 2026 09:24
@mgallien mgallien merged commit 3a93ad2 into master Jun 12, 2026
16 of 17 checks passed
@mgallien mgallien deleted the bugfix/fpext-prevent-data-loss-on-move branch June 12, 2026 09:24
@sonarqubecloud

Copy link
Copy Markdown

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.

3 participants