Skip to content

fix(file-provider): invalidate lock tokens when file paths change. #10135

Merged
camilasan merged 3 commits into
masterfrom
bugfix/fpext-invalidate-lock-tokens
Jun 15, 2026
Merged

fix(file-provider): invalidate lock tokens when file paths change. #10135
camilasan merged 3 commits into
masterfrom
bugfix/fpext-invalidate-lock-tokens

Conversation

@camilasan

@camilasan camilasan commented Jun 9, 2026

Copy link
Copy Markdown
Member

Resolves

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

Stale WebDAV lock token cleared on path change — when an editor locks a file the server issues a token bound to that file's path. If the parent folder is renamed the token becomes invalid.

The next save attempt sends a stale If: header. The server rejects it with 412/423, and the user cannot save — they must manually copy the file elsewhere.

Summary

The code now clears it whenever a rename is detected: during sync, in the DB rename functions, and on upload errors 412 and 423.

Steps to test it

  1. Open Spreadsheet.xlsx from a group folder via Finder (server issues a WebDAV lock).
  2. While the file is open, rename its parent folder from another client or the web UI.
  3. Edit the file content.
  4. Save. LibreOffice may ask "The file has been changed since it was opened — save anyway?" Click Save anyway.
    ✅ Save succeeds — no further error dialog.
    ✅ The updated file appears in the web UI with the new content.
  5. Edit and save a second time.
    ✅ The second save also succeeds.

Warning

Known limitation
...
When a folder is renamed on another client and LibreOffice has a file open inside it, saving may create a duplicate folder on the server at the old path. The File Provider extension does not coordinate renames through NSFileCoordinator, so macOS cannot notify open applications of the path change even if they implement NSFilePresenter. A proper fix requires the extension to wrap rename operations in NSFileCoordinator writes.
...
Our extension calls remoteInterface.move(...) (a WebDAV call) and then updates the local database. It does not go through NSFileCoordinator. So even if LibreOffice correctly registered as an NSFilePresenter, it still would not be notified — because our side isn't coordinating.
...
Our extension needs to use NSFileCoordinator when renaming items.

Checklist

AI (if applicable)

@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 force-pushed the bugfix/fpext-invalidate-lock-tokens branch 6 times, most recently from cddf4ea to c9bd40b Compare June 12, 2026 11:19
@camilasan

Copy link
Copy Markdown
Member Author

/backport to stable-34.0

@github-actions

Copy link
Copy Markdown
Contributor

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

Digest: sha256:65e39ef0bfdcf1ec1dd836c8ff38a3951d975d0599b74fbbc74833b0c65ca023

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.

WebDAV lock tokens are bound to the path they were issued for.
When a parent folder moves, child lock tokens become stale and
cause 412/423 upload failures. Clear tokens on rename propagation,
server metadata sync, and upload lock errors.

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>
testParent404ReportsParentAsDeleted wrote metadata then awaited the
enumerator without holding a Realm reference. Under parallel testing the
in-memory store was freed before the enumerator reopened it on another
thread, so the materialized-items query came back empty and the 404 parent
was never reported deleted. Retain the Realm for each test lifetime.

Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Camila Ayres <hello@camilasan.com>
@camilasan camilasan force-pushed the bugfix/fpext-invalidate-lock-tokens branch from c9bd40b to 94a6df4 Compare June 15, 2026 07:23
@camilasan camilasan merged commit 9327b65 into master Jun 15, 2026
17 checks passed
@camilasan camilasan deleted the bugfix/fpext-invalidate-lock-tokens branch June 15, 2026 07:23
@backportbot

backportbot Bot commented Jun 15, 2026

Copy link
Copy Markdown

The backport to stable-4.0 failed. Please do this backport manually.

# Switch to the target branch and update it
git checkout stable-4.0
git pull origin stable-4.0

# Create the new backport branch
git checkout -b backport/10135/stable-4.0

# Cherry pick the change from the commit sha1 of the change against the default branch
# This might cause conflicts, resolve them
git cherry-pick 8ff950eb 457ae588 94a6df4c

# Push the cherry pick commit to the remote repository and open a pull request
git push origin backport/10135/stable-4.0

Error: Failed to check for changes with origin/stable-4.0: No changes found in backport branch


Learn more about backports at https://docs.nextcloud.com/server/stable/go.php?to=developer-backports.

@sonarqubecloud

Copy link
Copy Markdown

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.

2 participants