Repository navigation
operations: make --immutable work with copyto, moveto and single file copy - fixes #4921 - #9944
Merged
Merged
Conversation
ncw
requested changes
Sep 19, 2026
ncw
left a comment
Member
There was a problem hiding this comment.
Thanks for fixing this - it looks great!
There are a couple of misplaced comments - if you could fix these and squash them into the existing commits, leaving two commits on the branch that would be perfect.
I agree the cache backend doesn't need special handling. It only matters if someone deliberately runs with --immutable
Optionally, you could also call logger(ctx, TransferError, srcObj, dstObj, err) on the immutable error path in moveOrCopyFile, like the other error returns there, so it shows up in --combined/--error reports.
Thanks again
| @@ -2257,6 +2257,35 @@ func TestSyncMultipleCompareDest(t *testing.T) { | |||
| } | |||
|
|
|||
| // Test with CopyDest set | |||
Member
There was a problem hiding this comment.
This comment belongs on the test below
| @@ -268,6 +302,34 @@ func TestCopyFileCompareDest(t *testing.T) { | |||
| } | |||
|
|
|||
| // Test with CopyDest set | |||
Member
There was a problem hiding this comment.
This comment belongs on the test below
hsdfat
force-pushed
the
fix-immutable-single-file-4921
branch
from
September 19, 2026 14:57
0333138 to
50cd74f
Compare
… copy - fixes rclone#4921 --immutable was only enforced by sync, so copyto, moveto, copy and move of a single file, and the operations/copyfile and operations/movefile rc calls overwrote a destination which differed from the source. Fail these with the same ErrorImmutableModified as sync, and reject --no-check-dest with --immutable as sync does, since without checking the destination it cannot be protected.
When the source matched a file in --copy-dest, copyDest server-side copied it over an existing destination which differed, so sync, copy and copyto with --copy-dest could modify a file --immutable should have protected. Leave such a destination for the caller, which rejects it with ErrorImmutableModified as for any other modified file.
hsdfat
force-pushed
the
fix-immutable-single-file-4921
branch
from
September 21, 2026 06:49
7393f38 to
4bc9cf7
Compare
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?
--immutableis enforced bysync, but the single file paths throughoperations.moveOrCopyFileignored it, sothese overwrote a destination which differed from the source:
rclone copytoandrclone movetorclone copy,rclone moveandrclone syncwhen the source is a single fileoperations/copyfileandoperations/movefilerc callsThis adds the same check
syncmakes: if a transfer is needed and the destination exists, fail withErrorImmutableModifiedas a no-retry error and leave both files alone. It sits before the--backup-dirstep, sonothing is moved into the backup directory first. An unchanged destination is still fine, and a missing one is
still copied.
It also rejects
--no-check-destwith--immutable, assyncalready does, since without looking at thedestination it cannot be protected.
The other callers of
CopyFile/MoveFileget the same check, which only fires when--immutableis set and theywould overwrite a file with different contents:
bisyncconflict renames andgitannex, where refusing seems right.cachebackend's background upload of temporary files, which uses the global config. A mount of acacheremote run with--immutablewould now refuse to upload over a changed file instead of overwriting it. Ifyou'd rather that internal upload ignored
--immutable, I can clear it there.The second commit fixes a related hole, which
synchas too: with--copy-dest, when the source matched a file inthe copy-dest directory,
copyDestserver-side copied it over an existing destination even if that differed, beforethe immutable check was reached. It now leaves such a destination for the caller, which rejects it as for any other
modified file. It is separate so it can be dropped if you'd rather handle it differently.
Testing
TestCopyFileImmutable: copying an unchanged file twice succeeds; copying a modified file fails withErrorImmutableModifiedand leaves both sides untouched;--no-check-destis rejected.TestMoveFileImmutable: moving a modified file fails and the source is not deleted.TestCopyFileCopyDestImmutableandTestSyncCopyDestImmutable: a match in--copy-destdoes not replace adifferent destination. Like the existing copy-dest tests these need server-side copy, so they skip on local; I ran
them with
-remote :memory:.All four fail on master (the destination is overwritten).
go build ./...,make quicktest,go test ./fs/operations/ ./fs/sync/(local and:memory:) andgolangci-lint run ./fs/operations/ ./fs/sync/pass.
Linked issue
Fixes #4921
Checklist
--immutabledocs already say it applies to commands which transfer files.)test_allpasses for this backend - not a backend change.