{"record":{"id":"e2ce582c4deb334c","repo":"spacedriveapp/spacedrive","slug":"checksum-verification-failed","errorCode":null,"errorMessage":"Checksum verification failed","messagePattern":"Checksum verification failed","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"core/src/ops/files/copy/strategy.rs","lineNumber":234,"sourceCode":"\t\t}\n\n\t\tif let Some(parent) = dest_path.parent() {\n\t\t\tfs::create_dir_all(parent).await?;\n\t\t}\n\n\t\tlet bytes_copied = tokio::task::spawn_blocking({\n\t\t\tlet source_path = source_path.to_path_buf();\n\t\t\tlet dest_path = dest_path.to_path_buf();\n\t\t\tmove || -> Result<u64, std::io::Error> { std::fs::copy(&source_path, &dest_path) }\n\t\t})\n\t\t.await??;\n\n\t\t// Post-copy verification detects CoW bugs and hardware errors (bit flips, bad sectors).\n\t\tif verify_checksum {\n\t\t\tlet source_checksum = calculate_file_checksum(source_path).await?;\n\t\t\tlet dest_checksum = calculate_file_checksum(dest_path).await?;\n\t\t\tif source_checksum != dest_checksum {\n\t\t\t\treturn Err(anyhow::anyhow!(\"Checksum verification failed\"));\n\t\t\t}\n\t\t}\n\n\t\t// Signal file completion to aggregator\n\t\tif let Some(callback) = progress_callback {\n\t\t\tcallback(bytes_copied, u64::MAX);\n\t\t}\n\n\t\tctx.log(format!(\n\t\t\t\"Fast copy: {} -> {} ({} bytes)\",\n\t\t\tsource_path.display(),\n\t\t\tdest_path.display(),\n\t\t\tbytes_copied\n\t\t));\n\n\t\tOk(bytes_copied)\n\t}\n}","sourceCodeStart":216,"sourceCodeEnd":252,"githubUrl":"https://github.com/spacedriveapp/spacedrive/blob/6dfeccf2113039e35f2ce735f945e70dc3e4ea45/core/src/ops/files/copy/strategy.rs#L216-L252","documentation":"FastCopyStrategy (core/src/ops/files/copy/strategy.rs:234) verifies integrity after std::fs::copy: it hashes source and destination with calculate_file_checksum and compares. A mismatch aborts the operation with this bare error. The comment states the intent: detect CoW (copy-on-write) bugs and hardware errors such as bit flips and bad sectors — i.e., the bytes on disk at the destination do not equal the source.","triggerScenarios":"Calling copy with verify_checksum=true where (a) the source file is modified concurrently while being copied (indexer, editor, sync client), (b) the destination disk has bad sectors or flaky USB/NAS storage, (c) a filesystem CoW/clone bug copies wrong extents, or (d) memory errors corrupt data in flight.","commonSituations":"Copying files that are still being written (recent downloads, active logs); failing HDD/SD-card/USB drive; exotic filesystems (btrfs/zfs reflink corner cases, network filesystems); overclocked/unstable RAM.","solutions":["Retry the copy once — transient read/write errors are the most common cause and a re-run usually succeeds.","Ensure the source is quiescent: stop indexers/editors/sync tools writing to it, or copy from a snapshot.","Check hardware: run `smartctl -a` on the destination disk, test RAM (memtest), try a different cable/port for external drives.","If it reproduces deterministically on one file pair, read both files back byte-by-byte (cmp) to confirm on-disk divergence, then file a bug — deterministic mismatch on healthy hardware indicates a CoW/clone-path defect.","Only as a last resort copy with verify_checksum=false (you lose integrity detection)."],"exampleFix":"// before: single attempt, aborts job on transient storage hiccup\nlet n = FastCopyStrategy.execute(ctx, src, dst, true, cb).await?;\n\n// after: one bounded retry for transient checksum mismatch\nlet n = match FastCopyStrategy.execute(ctx, src, dst, true, cb).await {\n    Ok(n) => n,\n    Err(e) if e.to_string().contains(\"Checksum verification failed\") => {\n        ctx.log(format!(\"checksum mismatch, retrying once: {e}\"));\n        FastCopyStrategy.execute(ctx, src, dst, true, cb).await?\n    }\n    Err(e) => return Err(e),\n};","handlingStrategy":"retry","validationCode":"// before enabling verification, confirm the source is not actively changing\nasync fn source_is_stable(path: &std::path::Path) -> bool {\n    let a = tokio::fs::metadata(path).await.map(|m| (m.len(), m.modified().ok())).ok()?;\n    tokio::time::sleep(std::time::Duration::from_millis(250)).await;\n    let b = tokio::fs::metadata(path).await.map(|m| (m.len(), m.modified().ok())).ok()?;\n    Some(a == b)\n}","typeGuard":null,"tryCatchPattern":"// bounded retry with hardware escalation after repeated mismatches\nconst MAX: usize = 2;\nfor attempt in 1..=MAX {\n    match FastCopyStrategy.execute(ctx, source, dest, true, cb).await {\n        Ok(n) => break Ok(n),\n        Err(e) if e.to_string().contains(\"Checksum verification failed\") && attempt < MAX => {\n            tracing::warn!(attempt, \"checksum mismatch, retrying\");\n            continue;\n        }\n        Err(e) if e.to_string().contains(\"Checksum verification failed\") => {\n            break Err(anyhow::anyhow!(\"repeated checksum mismatch; inspect destination disk health (smartctl)\"));\n        }\n        Err(e) => break Err(e),\n    }\n}","preventionTips":["Quiesce files before copying (stop writers, or copy from a snapshot).","Monitor destination disk SMART health proactively.","Keep verify_checksum=true for irreplaceable data; treat a mismatch as a red flag, not noise."],"tags":["files","copy","integrity","checksum","hardware"],"backgroundTag":null,"analyzedSha":"6dfeccf2113039e35f2ce735f945e70dc3e4ea45","analyzedAt":"2026-08-16T11:26:17.074Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}