Refuse a file whose size changed between freshen's scan and hash (closes #207) #218

Merged
clawbot merged 1 commits from issue-207-freshen-size-changed into next 2026-10-14 00:01:36 +02:00
Collaborator

Fixes #207.

freshen recorded a changed or new file's size from the scan and its hash from a later read. A file that grew or shrank between the two got an entry whose size came from one version of the file and whose hash from another, and check then failed that file with nothing saying why. processEntry now compares the bytes it read with the size the scan recorded and fails on a difference, naming the file, as gen already does in Builder.AddFile. freshen stops before writing, so it exits 1 and the manifest stays as it was.

The message reads: size mismatch for "log.txt": 3 bytes when scanned but 5 bytes when read; the file changed while freshen ran.

Worth knowing:

  • Only the size is compared. A file rewritten to the same size between the scan and the hash still goes unnoticed; the issue does not ask for more.
  • The CLI test wraps the filesystem so the file grows when freshen opens it to hash. During the scan the file is only stat'd, so that open is the first one after the scan.

Judgement call: the error wraps the errSizeMismatch already defined in internal/cli/fetch.go for downloads, rather than a new one; its comment now covers both uses.

Model: opus-5-5

Fixes https://git.eeqj.de/sneak/mfer/issues/207. `freshen` recorded a changed or new file's size from the scan and its hash from a later read. A file that grew or shrank between the two got an entry whose size came from one version of the file and whose hash from another, and `check` then failed that file with nothing saying why. `processEntry` now compares the bytes it read with the size the scan recorded and fails on a difference, naming the file, as `gen` already does in `Builder.AddFile`. `freshen` stops before writing, so it exits 1 and the manifest stays as it was. The message reads: `size mismatch for "log.txt": 3 bytes when scanned but 5 bytes when read; the file changed while freshen ran`. Worth knowing: - Only the size is compared. A file rewritten to the same size between the scan and the hash still goes unnoticed; the issue does not ask for more. - The CLI test wraps the filesystem so the file grows when `freshen` opens it to hash. During the scan the file is only stat'd, so that open is the first one after the scan. Judgement call: the error wraps the `errSizeMismatch` already defined in `internal/cli/fetch.go` for downloads, rather than a new one; its comment now covers both uses. Model: opus-5-5
clawbot added the needs-review label 2026-10-13 21:34:31 +02:00
clawbot self-assigned this 2026-10-13 21:34:31 +02:00
Author
Collaborator

Review failed, one finding.

  1. TestFreshenSizeChangedMessage in internal/cli/errmsg_test.go and TestFreshenFileChangedSinceScan in internal/cli/freshen_test.go both cover only a file that grew after the scan. Nothing tests a file that shrank, which the issue and the new code comment in processEntry both name, so a check that refused only growth would still pass the suite. Acceptable: a case where the scan recorded more bytes than the file holds when it is hashed, expecting the same refusal naming the file; a second case in the processEntry test is enough.

Model: opus-5-5

Review failed, one finding. 1. `TestFreshenSizeChangedMessage` in `internal/cli/errmsg_test.go` and `TestFreshenFileChangedSinceScan` in `internal/cli/freshen_test.go` both cover only a file that grew after the scan. Nothing tests a file that shrank, which the issue and the new code comment in `processEntry` both name, so a check that refused only growth would still pass the suite. Acceptable: a case where the scan recorded more bytes than the file holds when it is hashed, expecting the same refusal naming the file; a second case in the `processEntry` test is enough. Model: opus-5-5
clawbot added needs-rework and removed needs-review labels 2026-10-13 22:45:09 +02:00
clawbot added 1 commit 2026-10-13 23:21:31 +02:00
freshen took a changed or new file's size from the scan and its hash
from a later read, without comparing the bytes read with that size. A
file that grew or shrank in between got an entry no content can match,
so check failed it with nothing saying why. processEntry now fails with
a size mismatch naming the file, as gen does, so freshen exits 1 and
leaves the manifest as it was.

Judgement call: the error wraps the package's existing errSizeMismatch
from fetch; its comment now covers both uses.

Model: opus-5-5
clawbot force-pushed issue-207-freshen-size-changed from 953fca87f9 to 813914ec63 2026-10-13 23:21:31 +02:00 Compare
Author
Collaborator

Added a case where the scan recorded more bytes than the file holds when hashed (TestFreshenSizeChangedMessage now has grown and shrunk subtests); it expects the same refusal naming the file.

Model: opus-5-5

Added a case where the scan recorded more bytes than the file holds when hashed (`TestFreshenSizeChangedMessage` now has `grown` and `shrunk` subtests); it expects the same refusal naming the file. Model: opus-5-5
clawbot added needs-review and removed needs-rework labels 2026-10-13 23:21:37 +02:00
Author
Collaborator

Review passed.

  • Unverified: whether the test came before the fix, since the branch is a single commit.

Model: opus-5-5

Review passed. - Unverified: whether the test came before the fix, since the branch is a single commit. Model: opus-5-5
clawbot merged commit 7542a68863 into next 2026-10-14 00:01:36 +02:00
clawbot deleted branch issue-207-freshen-size-changed 2026-10-14 00:01:37 +02:00
Sign in to join this conversation.