Skip to content
C.W.K.
Stream
Lesson 04 of 05 · published

Checksums over Timestamps

~12 min · checksum, rsync, drift, integrity

Level 0Trace
0 XP0/36 lessons0/12 achievements
0/100 XP to next level100 XP to go0% complete

The shortcut in a quick check

File synchronization commonly compares size and modification time. Different values trigger a copy; equal values skip it. That shortcut is usually fast and correct, but a memory ledger exists to record every real change, not most of them.

Editors and recovery tools can preserve timestamps, and a sentence may change to another of equal length. Content then differs while both proxies match. The sweep reports no change and the ledger gains a hole. After this happens once, checksum cost stops looking extravagant.

The question a content hash asks

A checksum reads bytes rather than metadata. It costs more with many or large files, but the cost purchases evidence when claiming byte identity between source and mirror. Metadata can still narrow candidates while hashes make the final decision.

Placement matters more than the algorithm name. Hashing only source before copy cannot detect destination corruption. Read both source and mirror or use a transfer mode that genuinely compares content on both sides.

Tune performance by measurement

If hashing every large asset is expensive, choose policies by class. Small Markdown memory can always use checksums, immutable media can use inventory signatures, and enormous derived caches can remain outside stewardship.

If performance forces a proxy, the ledger must not claim byte completeness. Label fast and verified scans separately and expose the last verified time. Slowness is not failure; an ambiguous guarantee is.

Preserve the failure shape in a regression

Ordinary edit tests let every quick check pass. Create a fixture with different bytes, equal size, and restored mtime to prove the detector reads content. When an incident arrives in an unusual shape, the regression should keep that exact shape so a later optimization cannot reopen the same hole.

Metadata is a hint of change; a checksum is evidence of content. A byte-complete ledger must compare bytes rather than trust a fast proxy.

Code

Create equal size and mtime with different content·python
from pathlib import Path
import hashlib, os, tempfile

root = Path(tempfile.mkdtemp())
a, b = root / "a.txt", root / "b.txt"
a.write_text("alpha\n")
b.write_text("bravo\n")
st = a.stat()
os.utime(b, ns=(st.st_atime_ns, st.st_mtime_ns))
assert a.stat().st_size == b.stat().st_size
assert a.stat().st_mtime_ns == b.stat().st_mtime_ns
assert hashlib.sha256(a.read_bytes()).digest() != hashlib.sha256(b.read_bytes()).digest()

External links

Exercise

Add a same-size, same-mtime, different-bytes fixture to a synchronization test. If the detector misses it, separate verified and fast modes.
Hint
Use equal-length words and restore the timestamp with os.utime.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.