Skip to content

fix(share): Do not add a share item when the file transfer failed - #2758

Merged
SystemKeeper merged 2 commits into
nextcloud:mainfrom
ToteMeiSter:fix/share-item-move-error
Oct 14, 2026
Merged

SystemKeeper merged 2 commits into
nextcloud:mainfrom
ToteMeiSter:fix/share-item-move-error

Conversation

@ToteMeiSter

@ToteMeiSter ToteMeiSter commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Problem

ShareItemController prepareFileForUploadingAtURL:… moves the file provided by the file coordinator into the temporary directory, but ignores the result of moveItemAtPath: and only returns the coordinator error. If the move fails (no space left, source can't be removed, …), the method still reports success and addItemWithURLAndName: adds a ShareItem whose file does not exist. Preview and upload of that item then fail.

Besides, with NSFileCoordinatorReadingWithoutChanges (the fallback) the URL given to the accessor is the original file. Moving it takes the file away from its owner, or fails if the source is not removable.

Fix

  • Use the error of the move/copy for the result, so the existing fallback and the Failed to prepare file for sharing path apply.
  • NSFileCoordinatorReadingForUploading: keep moving, the URL is a snapshot that the coordinator unlinks after the accessor block (Apple documents relocating it within the block).
  • NSFileCoordinatorReadingWithoutChanges: copy the original instead of moving it.

updateItem:withURL: (replacing the item's file with the QuickLook edit) has the same defect class, and a worse outcome: it removes the item's file first and then ignores a failed moveItemAtPath:, so on failure the item loses its file. It now uses replaceItemAtURL:withItemAtURL:…, which keeps the original until the replacement succeeded, and logs the replace and coordinator errors (second commit).

Tests

Added UnitShareItemControllerTest (item with a local copy for an existing file, no item for a missing file). I could not run the build and tests locally, only CI.

AI-assisted: Claude Code (Sonnet 5.5), reviewed by the author.

prepareFileForUploadingAtURL ignored the result of the move into the
temporary directory and only looked at the file coordinator error. If
the move failed (no space left, source not removable), an item pointing
to a non-existing file was added to the share list.

Report the transfer error as a failure, so the existing fallback and the
"Failed to prepare file for sharing" path apply.

With NSFileCoordinatorReadingWithoutChanges the coordinator hands out the
original file, which must not be moved away from its owner anymore, so
copy it. The snapshot of NSFileCoordinatorReadingForUploading is still
moved, as the coordinator unlinks it after the accessor block.

Assisted-by: Claude-Code:claude-sonnet-5-5
Signed-off-by: Krainov Gleb <krajnov.g@kontentplus.ru>
…ok edit

updateItem:withURL: removed the item's file before moving the edited file in and
ignored a failed move, which left the item without a file. Replace the file
atomically and log failures.

Assisted-by: Claude-Code:claude-sonnet-5-5
Signed-off-by: Krainov Gleb <krajnov.g@kontentplus.ru>
@ToteMeiSter
ToteMeiSter deleted the fix/share-item-move-error branch October 12, 2026 14:02
@ToteMeiSter
ToteMeiSter restored the fix/share-item-move-error branch October 12, 2026 14:03
@ToteMeiSter ToteMeiSter reopened this Oct 12, 2026
@SystemKeeper

Copy link
Copy Markdown
Collaborator

Thanks for the PR! The changes look good and sane. I assume (based on your last message in the other PR) it's more of a correctness fix than an issue you ran into?

@ToteMeiSter

Copy link
Copy Markdown
Contributor Author

It's a correctness fix. On Android we ran into a real problem: the app queried the content provider of shared files on the main thread, and that froze the UI (fixed in nextcloud/talk-android#6857 and related PRs). I then checked whether iOS has the same issue. It doesn't, but while reading that code path I found this one. I haven't hit it on a device. It needs the move to fail (e.g. no free space) or the WithoutChanges fallback, so it should be rare in practice.

@SystemKeeper SystemKeeper 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.

Thanks!

@SystemKeeper
SystemKeeper merged commit 3150728 into nextcloud:main Oct 14, 2026
10 checks passed
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.

2 participants