Repository navigation
Conversation
APPE deleted the existing file and stored only the appended data, so `curl --append` and upload resumes such as `curl -C -` lost everything already on the server while reporting success. The ftp library passes APPE the same offset as STOR, so PutFile now appends from the end of an existing file itself. REST followed by STOR opened the file with O_APPEND, which made every write go to the end of the file and the seek to the restart offset had no effect. Open it O_RDWR instead so the data lands at the offset. With --vfs-cache-mode off, APPE onto an existing file now fails with an error, as REST+STOR already did, instead of replacing the file.
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.
What does this change do?
rclone serve ftpdestroys data when a client appends to a file or resumes an upload, and reports success.PutFilewith the same offset (-1) for APPE as for STOR, so it takes the "new upload" branch.curl --appendloses what was there, andcurl -C -(SIZE then APPE) leaves only the tail: a 100000 byte upload resumed after 5000 bytes ends up 95000 bytes.O_APPEND|O_RDWRand then seeks. WithO_APPENDevery write goes to the end, soREST 6+STOR "WORLD"ontohello worldgiveshello worldWORLDinstead ofhello WORLD.The fix appends from the end of an existing file when the command is APPE, and opens the file
O_RDWRso the seek to the restart offset takes effect. Data after the written range is kept, as vsftpd does.One behaviour change: with
--vfs-cache-mode off, APPE onto an existing file now fails with a 450 error, like REST+STOR already does in that mode, instead of replacing the file. APPE to a new file still works in every mode.Tests:
TestUploadOffsetcovers APPE to a new and to an existing file, and REST at the end and in the middle of a file, checking both the download and the file on disk. Without the fixAppendgets" again"andRestartInMiddlegets"hello worldWORLD". The test file is excluded on darwin, so I ran it on macOS with the build tag lifted locally: the package's existing tests fail and pass the same with and without the change. I also checked APPE andcurl -C -resumes end to end against a built binary inoffandwritescache modes.Linked issue
None, found while testing
serve ftpuploads.Checklist
test_allpasses for this backend and if submitting a new backend can provide a test account for the integration tester - see CONTRIBUTING.md.