Repository navigation
Implement 'atomic downloads' with copy-to-temp + rename - #6913
Conversation
ncw
left a comment
There was a problem hiding this comment.
Here are some initial thoughts. I think this might need a few iterations as operations.Copy is very complicated!
|
If it's starting to look better, I can move on to tests & CLI options in the upcoming iterations. |
There was a problem hiding this comment.
I'm a little confused why there's dst and newDst in this function. It might be because there are a lot of assignments to dst and newDst is updated to "carry the newly created file handle forward" when there were no errors.
I think the error handling here is correct and the debug prints print sensible output too. I'm just not 100% sure what should be returned from this path and how the newDst is used by the caller.
There was a problem hiding this comment.
I think this looks correct.
The return from this function should be the final object in its final resting place. We try not to update newDst unless the function returned err = nil which is why I think there is dst and newDst.
I think the whole dst and newDst needs a careful review, but let's not do it in this PR! I'll do it after we merge it.
ncw
left a comment
There was a problem hiding this comment.
I think this is looking about right now :-)
Do you want to carry on with the other bits?
There was a problem hiding this comment.
I think this looks correct.
The return from this function should be the final object in its final resting place. We try not to update newDst unless the function returned err = nil which is why I think there is dst and newDst.
I think the whole dst and newDst needs a careful review, but let's not do it in this PR! I'll do it after we merge it.
|
@ncw Should the |
Yes this needs to be a global flag as it affects BTW You can disable a feature for a backend, eg |
|
OK, I added --inplace and a couple of tests. I did notice that some tests were failing at least Not entirely sure if my added tests add a lot of value as they're copied from other tests, so the coverage should be similar to existing coverage. EDIT: yes, my change definitely breaks TestSyncUTFNorm. Investigating further. |
|
I find that TestSyncUTFNorm break goes away with this change: At least this Argument I thought this would've fixed it: But it still breaks with some weirdness in the UTF-8 filenames: (copy&pasting from the shell removes the spaces that I see in the terminal :)) |
|
I think the problem is this... If Thats a subtle point also... Some backends do different things on Update vs Put. If you use Update when you should have used Put on Google Drive you'll make a duplicate file. Now on the backends we are talking about, |
|
I can get tests (ie., But to be fair, I don't completely understand this function so it's hard to tell if that's the right thing to do. :) |
I think that patch is nearly right - I commented on it what I think it should be. |
|
Added a comment here: 4d31ccf#commitcomment-109940910 (I'm finding it really hard to keep track of review comments in GitHub PRs :)) |
|
How this is supposed to work? I mean what flags to use? |
|
The patch implements this so that it's enabled by default. If you want to revert to old behavior, you can turn it off with the "--inplace" flag. This is the same default and same flag as in rsync. |
What does it do exactly? what will happen if i do this?
here sftp is a sftp remote |
|
@nurpax I think next week I will pull this locally and see if I can find out what is going on. If I manage to fix it I'll push a commit on top of yours. |
|
@nurpax I've spent quite a long time working on this. I've
So I think this is nearly done! It needs
Can you pull what I've done (I'd suggest into a new branch since I rebased it) and see how it is working for you? PS the |
|
@ncw, thank you so much for helping out with this change! I read through your modifications and it locally and it works as I'd expect it to work: copying new and replacing existing files works, I tried with a bunch of different "rclone copy/sync" scenarios where the source was modified. Tests also passed. As far as my original needs for this feature go, it's done. 👍 I don't have an opinion on ftp/sftp. We don't use that path and I have little recent experience on using ftp, so I can't tell what downsides enabling this might have. For the record, there are some requests in #3770 (comment) that are not implemented in this change. I think they could hide the partial files by masking out The comment mentions It's possible to revert back to old behavior by using the |
Before this fix it was returning the base objects string rather than the overridden remote.
Before this change rclone used a normal SFTP rename if present to
implement Move.
However the normal SFTP rename won't overwrite existing files.
This fixes it to either use the POSIX rename extension
("[email protected]") or to delete the source first before
renaming using the normal SFTP rename.
This isn't normally a problem as rclone always removes any existing
objects first, however to implement non --inplace operations we do
require overwriting an existing file.
Implement a Partialuploads feature flag to mark backends for which uploads are not atomic. This is set for the following backends - local - ftp - sftp See rclone#3770
When copying to a backend which has the PartialUploads feature flag set and can Move files the file is copied into a temporary name first. Once the copy is complete, the file is renamed to the real destination. This prevents other processes from seeing partially downloaded copies of files being downloaded and prevents overwriting the old file until the new one is complete. This also adds --inplace flag that can be used to disable the partial file copy/rename feature. See rclone#3770 Co-authored-by: Nick Craig-Wood <[email protected]>
Great!
I think enabling this on SFTP is pretty safe. Enabling this on FTP is probably less safe as there are a lot of extremely crusty FTP servers out there. I'm going to enable it for FTP and SFTP since the integration tests all pass. I had to patch the SFTP backend to allow overwriting files when renaming.
I'm happy for
Yes
Yes! I've just pushed an update with docs, sftp and ftp support. If that builds OK then I'll merge :-) Thank you for doing this, and in particular thank you for untangling the confusion re rsync as to exactly what this feature should do. |
|
Excellent! Thanks for the help, I'm glad it's merged! :) |
|
Hi guys. Please have a look at: Looks like this PR introduced some small bug. |
|
I will look at this shortly! |

Download a local copy into a temporary file first. Once the download is complete, rename the temp file to the real destination.
This prevents other processes from seeing partially downloaded copies of files being downloaded.
for #3770
What is the purpose of this change?
Support "atomic downloads" by copy-to-temp/rename. This prevents other processes from seeing partially downloaded files while rclone is downloading.
Was the change discussed in an issue or in the forum before?
#3770
Checklist
Checklist incomplete, pushing PR for review. If the approach looks sensible, I'll update the PR with tests & other required items.