Skip to content

fix(download): prevent overlapping downloads from changing a completed file - #18163

Open
teapotonmars wants to merge 1 commit into
nextcloud:masterfrom
teapotonmars:review/download-isolation
Open

teapotonmars wants to merge 1 commit into
nextcloud:masterfrom
teapotonmars:review/download-isolation

Conversation

@teapotonmars

Copy link
Copy Markdown

When folder sync and another caller download the same remote file at the same time, both transfers can open the same temporary file. For an unencrypted download, one transfer can move that file into the user's library while the other still has it open for writing. A download that reported success can then change underneath the reader.

Give each transfer its own temporary folder through save or export. On the first download to a storage location, try to clear abandoned transfers. If cleanup fails but a new folder can still be created, the download proceeds. Encrypted downloads also get separate temporary files for ciphertext. Decryption still writes directly to the destination.

Testing

Five unit tests cover interleaved writes, cancellation and abandoned files, failed cleanup, a symlink at the temporary root, and export before cleanup. On a Pixel 10 Pro Fold connected to a live Nextcloud account, the test blocked startup cleanup, paused a download of a PDF, and downloaded the same file a second time. The published PDF matched a separate reference download's SHA-256 both before and after the first transfer resumed. The server ETag stayed the same.

🖼️ Screenshots

🏚️ Before 🏡 After
No visible UI change No visible UI change

🏁 Checklist

  • ⛑️ Tests (unit and/or integration) are included or not needed
  • 🔙 Backport requests are created or not needed: /backport to stable-xx.x
  • 📅 Milestone is set
  • 🌸 PR title is meaningful (if it should be in the changelog: is it meaningful to users?)

🤖 AI (if applicable)

  • The content of this PR was partly or fully generated using AI

Codex assisted with implementation, tests, and this PR description.

Two downloads of the same account and remote path can write to the same
temporary file. For unencrypted downloads, one transfer can then change
a file that the other has already moved into the user's library.

Give each transfer its own folder until it finishes saving or exporting.
Try to clear abandoned folders on the first download to each storage
location. An undeletable leftover can coexist with a new download when
the parent directory is still writable.

Encrypted downloads also get separate temporary files for ciphertext.
They continue to decrypt directly into the destination.

Assisted-by: Codex:GPT-6
Signed-off-by: Emma Liddell <emma@emmaliddell.com>

This branch has not been deployed

No deployments
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.

1 participant