Skip to content

Share content-hash across storage backends; drop unused Storage.stat() - #118

Merged
in-jun merged 1 commit into
mainfrom
fix/storage
Jul 18, 2026
Merged

Share content-hash across storage backends; drop unused Storage.stat()#118
in-jun merged 1 commit into
mainfrom
fix/storage

Conversation

@in-jun

@in-jun in-jun commented Jul 18, 2026

Copy link
Copy Markdown
Owner

Two related cleanups to the Storage port contract.

Fixes #19
Fixes #21

@in-jun in-jun left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the full diff against the surrounding code. Both cleanups land cleanly.

#19 — shared content hash

  • ContentHash.sha256Hex centralizes the algorithm correctly: HashingSource.sha256 streamed into blackholeSink(), digest read via ByteString.hex(). The source is consumed and closed inside the helper, so both call sites just hand it a fresh source.
  • The output encoding is byte-identical to the previous hand-rolled version — hex() and "%02x".format both emit lowercase hex of the same SHA-256 — so hashes already persisted in the ancestor store stay comparable. No migration hazard, and converged files won't suddenly read as conflicts.
  • The SMB handle/stream ordering is right: hashing consumes the whole file, so releasing the InputStream (via the okio Source) before the outer .use closes the handle is safe, and the comment captures why it differs from read(). okio is already a dependency of both core-sync and app.
  • hashFile/hashRemote stay live through scan(), so nothing goes dead under allWarningsAsErrors.

#21 — drop stat()

  • No production caller remained; the only three call sites were tests, all migrated to probe(). The assertions that moved (mtimeMillis equality, null-on-absent) are semantically preserved, and probe() is the cheaper check since it skips hashing.
  • Keeping move() is justified — it is used in production by ConflictManager for keep-both resolution.

Contract docs on Storage.scan and FileMeta.contentHash make the cross-backend invariant explicit, which is the real point of the change. No regressions or scope creep. Looks good to merge.

@in-jun
in-jun merged commit 82940c8 into main Jul 18, 2026
1 check passed
@in-jun
in-jun deleted the fix/storage branch July 18, 2026 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant