rclone icon indicating copy to clipboard operation
rclone copied to clipboard

copyto silently fails over previously rcat-ed object

Open ribasushi opened this issue 5 months ago • 8 comments

Before you start

  • [x] I have searched the forum and the existing issues for this problem.
  • [x] I have tested with the latest beta or stable release and can still reproduce the problem.
  • [x] This is a reproducible bug, not a usage question (questions belong on the forum).

Associated forum post URL

No response

What is the problem you are having with rclone?

If a file was uploaded using rcat, this skips populating the md5 field. If a subsequent copyto is executed over that with --checksum, the checksum check is skipped as seen in the rclone -vv output below. This probably also affects copy, I have not tested.

...
2026/06/22 12:19:28 DEBUG : 6 go routines active
2026/06/22 12:19:28 DEBUG : rclone: Version "v1.74.3" starting with parameters ["./rclone" "--config=/dev/null" "--s3-provider=Cloudflare" "--s3-endpoint=https://<REDACTED>.r2.cloudflarestorage.com" "--s3-no-check-bucket" "--s3-env-auth=true" "--s3-chunk-size=5Gi" "--s3-copy-cutoff=5Gi" "--s3-upload-cutoff=5Gi" "--checksum" "-vv" "copyto" "/srv/up/b/tempfilez/tmp.F9JSfKLfJI" ":s3:<REDACTED>...flattened.ndjson.zst"]
2026/06/22 12:19:28 DEBUG : Creating backend with remote "/srv/up/b/tempfilez/tmp.F9JSfKLfJI"
2026/06/22 12:19:28 DEBUG : Using config file from ""
2026/06/22 12:19:28 DEBUG : fs cache: renaming child cache item "/srv/up/b/tempfilez/tmp.F9JSfKLfJI" to be canonical for parent "/srv/up/b/tempfilez"
2026/06/22 12:19:28 DEBUG : Creating backend with remote ":s3:<REDACTED>...2026/06/21/"
2026/06/22 12:19:28 DEBUG : :s3: detected overridden config - adding "{qzX-7}" suffix to name
2026/06/22 12:19:28 DEBUG : fs cache: renaming cache item ":s3:<REDACTED>...2026/06/21/" to be canonical ":s3{qzX-7}:<REDACTED>...2026/06/21"
2026/06/22 12:19:28 DEBUG : <REDACTED>...flattened.ndjson.zst: size = 541214 OK
2026/06/22 12:19:28 DEBUG : <REDACTED>...flattened.ndjson.zst: Dst hash empty - aborting Src hash check  <---   THIS IS A
2026/06/22 12:19:28 DEBUG : tmp.F9JSfKLfJI: Size of src and dst objects identical                        <--- SERIOUS PROBLEM
2026/06/22 12:19:28 DEBUG : tmp.F9JSfKLfJI: Unchanged skipping
2026/06/22 12:19:28 INFO  : 
Transferred:              0 B / 0 B, -, 0 B/s, ETA -
Elapsed time:         0.0s

rclone version

rclone v1.74.3

  • os/version: debian 12.6 (64 bit)
  • os/kernel: 6.9.7 (x86_64)
  • os/type: linux
  • os/arch: amd64
  • go/version: go1.26.2
  • go/linking: dynamic
  • go/tags: none

Built straight from https://github.com/rclone/rclone/releases/tag/v1.74.3

Operating system

Linux

Which cloud storage system are you using?

Cloudflare R2

Output of rclone config redacted

There is no config, everything runs with `... --config=/dev/null`

The command you were trying to run

See the log above

A log from the command with the -vv flag

See above

Anything else?

No response

ribasushi avatar Jun 22 '26 10:06 ribasushi

Thanks for the detailed report.

When you upload with rcat, rclone is streaming data of unknown size, so it has to use a multipart upload. The problem is that S3 needs object metadata (including any MD5 checksum) at the start of a multipart upload, but rclone hasn't read the data yet at that point, so it has no MD5 to store. The resulting object ends up with a multipart-style ETag (which isn't a plain MD5) and no md5chksum metadata, so the object genuinely has no usable hash.

(For comparison, a normal rclone copy of a large file does store the MD5 - there rclone knows the source hash up front and writes it into the object metadata. It's specifically the streaming rcat/rcat-like case that can't.)

We can't easily backfill the hash afterwards either: the metadata is fixed at upload-completion time, so adding the MD5 later would require a full server-side copy of the object onto itself, which for large objects is expensive (another multipart operation) - not something we'd want to do automatically.

So on the comparison side, when you run copyto --checksum, rclone finds that the destination has no hash and falls back to a size-only comparison. That fallback is intentional (it's the general "can't read a hash, don't needlessly re-transfer" behaviour), but you're right that it's far too quiet here - with --checksum explicitly requested, silently downgrading to size-only is surprising. The once-only "falling back to --size-only" warning we already have only fires when the two remotes share no hash type at all; it doesn't fire in your case, where the remotes do share MD5 but this particular object happens to lack it.

We could make that fallback visible: when --checksum is in use and a hash comparison was expected but couldn't be performed because one side's hash is empty, we could make rclone emit a warning rather than just a debug line. Perhaps we'd emit this warning just once so as not to spam the log as this scenario is actually fairly common.

The skip-on-size behaviour itself would stay the same (changing it to always re-transfer would mean every streamed/multipart object without an MD5 re-uploads on every run), but you'll at least no longer be misled into thinking a checksum check happened when it didn't.

What do you think?

ncw avatar Jun 22 '26 10:06 ncw

I am aware of how/why rcat behaves the way it does, and have no comments there: you are already doing everything you can correctly.

The bugreport is about copyto (and possibly copy and sync) when paired with --checksum. My understanding/expectation was that the --checksum flag is bulletproof: the moment it is specified all other checks, including --size-only go out the window. Given that this has never actually been the case is regrettable, but I agree with you on backcompat taking precedence.

Two thoughts:

  • Yes please, whenever --checksum is specified, and the check is omitted for some reason emit a warning
  • Could there be some sort of --force-checksum (name debatable!) that would implement the no-compormises behavior I and likely others expected?

ribasushi avatar Jun 22 '26 11:06 ribasushi

What you are asking for is a --missing-checksum-implies-changed flag I think. So if the checksum is missing then the object gets uploaded regardless. Checksums can be missing in backends for lots of different reasons so this would be a terrible default but it could be useful in certain circumstances.

This was looked at here PR #9505 ("feat: add upload checksum no-fallback upload-missing include-modtime") adds three new boolean flags, all of which only make sense in combination with --checksum:

  • --checksum-no-fallback - if a hash can't be verified, error instead of falling back to size-only.
  • --checksum-upload-missing - re-upload any destination file that has no stored hash, so the backend computes and stores one.
  • --checksum-include-modtime - also compare modtime, instead of --checksum skipping it.

So for your case you'd want --checksum-upload-missing

I made a counter proposal for #9505 so we don't bloat rclone with an infinite number of flags - a compare minilanguage. Your use case would be --compare "size,checksum:differ" or --compare "size,checksum:require". What do you think of this idea in addition to the warning?

Comparing files

Today equal() is a fixed decision tree with mode switches. The insight is that an equality decision is really an ordered pipeline of checks, each inspecting one attribute and returning one of three verdicts:

  • same - this attribute matches → go on to the next check
  • differ - this attribute differs → file needs transfer (stop here)
  • unknown - the attribute could not be compared (no common hash type, modtime unsupported, size unknown, …) → apply this check's missing policy

A file is considered already-synced (skip the transfer) only if every check resolves to same. The first check that resolves to differ triggers the transfer.

The only genuinely subtle part - what to do when a comparison can't be made - is made explicit and per-check, instead of being three hard-coded fallbacks buried in the tree.

Syntax

--compare CHECK[:POLICY][,CHECK[:POLICY]]...

Config key compare (string), group Copy. Parsed once into []check.

Attributes

attribute "same" when…
size sizes are equal
modtime modtimes equal within --modify-window
checksum a common hash type exists and the values match (alias hash)

Missing policy (what an unknown verdict becomes)

policy meaning
fallback treat unknown as same - i.e. skip this check (the default for modtime/checksum)
differ treat unknown as differ - re-upload
require count an error, log it, and skip the file (leave dst untouched)

Each attribute has a sensible default policy so the common forms stay short:

  • size - always comparable; policy rarely needed.
  • modtime - default fallback (a backend with no modtime support just skips the check, matching today's behaviour).
  • checksum - default fallback (no common hash => fall back, exactly like --checksum today).

ncw avatar Jun 22 '26 11:06 ncw

@ncw I agree with not changing any existing flags/defaults, no contest!

Ergonomically all variations you linked sound ok to me: I am driving rclone exclusively from cli with no config file, so I am the wrong person to judge on the topic of verbosity 😅.

That said, semantically require is problematic because on first read I slotted it as "this is the thing I want", whereas I actually wanted differ. fallback also doesn't directly imply it will treat as "no change"... What about:

on-missing-skip on-missing-alert on-missing-differ

?

ribasushi avatar Jun 22 '26 11:06 ribasushi

Note that bisync has a --compare flag with this syntax:

--compare size,modtime,checksum

It would be great to have the same feature in sync 🙂

nielash avatar Jun 29 '26 09:06 nielash

@nielash I had forgotten about that... Do you think we should promote --compare into fs/operations and use it as a base for this?

ncw avatar Jun 30 '26 11:06 ncw

I think that would be great.

nielash avatar Jun 30 '26 23:06 nielash

Confirmed on the official v1.76.0 binary (darwin arm64) without an R2 account, against a local Moto S3 fixture.

  • rcat of 6 MiB from stdin creates a multipart ETag and no md5chksum metadata. A same-size, one-byte-different copyto --checksum exits 0 without transferring; -vv shows Dst hash empty. A separate S3 GET still returns the original bytes.
  • Plain check --combined - prints = payload.bin and exits 0 while reporting one hash could not be checked. On the same object, check --download --combined - prints * payload.bin and exits 1.
  • A targeted copyto --ignore-times followed by the same readback check exits 0 with the exact expected bytes. This is a recovery path for a known mismatch, not a suggestion to change the default.

Loopback-only reproducer and command output. I published and reran the downloaded fixture; no real R2 backend was tested. Reproducer and write-up were assisted by Codex.

xudukongju avatar Nov 21 '26 06:11 xudukongju