Repository navigation
fix(download): prevent overlapping downloads from changing a completed file - #18163
Open
teapotonmars wants to merge 1 commit into
Open
teapotonmars wants to merge 1 commit into
teapotonmars wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
🏁 Checklist
/backport to stable-xx.x🤖 AI (if applicable)
Codex assisted with implementation, tests, and this PR description.