fix(watcher): unique archive copies, read caps at the read, stale markers (review of #210)
CI / Lint / Test / Vet (pull_request) Successful in 1m5s
CI / Mirror to GitHub (pull_request) Skipped

From the independent review of #210:
- F1: processed/ and failed/ copies are created O_EXCL with -2,-3 suffixes via
  createUnique; same-named notes from different folders no longer replace one
  another's only surviving copy
- F2: extract.TextInMax / readAllMax cap the bytes actually read (a note can
  grow after the Lstat); extract.TextIn gets a 64 MiB default cap
- F3: a regular marker older than its note describes an earlier note of the
  same name; it no longer hides the new one (warn + remove); non-regular
  markers still count as done (no writes through links)
- F4: the planted-marker-link test is renamed to what it observes
Each has a test that fails without it; the read-cap test uses an endless reader
that errors at 8 MiB so a regression fails instead of exhausting memory.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-20 20:13:18 +02:00
co-authored by Claude Sonnet 5.5
parent d8c7defc78
commit 1025d77795
6 changed files with 298 additions and 42 deletions
+9 -2
View File
@@ -20,6 +20,13 @@ import (
// root, never replacing a parked note: on a name clash it tries -2, -3, ...
// A needs-review that is a symlink, or any non-directory, is refused.
func createParked(brainDir, filename string, data []byte) error {
return createUnique(brainDir, "raw/needs-review", filename, data)
}
// createUnique writes data to dirRel/filename through the brain root, never
// replacing an existing file: on a name clash it tries -2, -3, ... A dirRel that
// is a symlink, or any non-directory, is refused.
func createUnique(brainDir, dirRel, filename string, data []byte) error {
bfs, err := brainfs.Open(brainDir)
if err != nil {
return err
@@ -32,7 +39,7 @@ func createParked(brainDir, filename string, data []byte) error {
if n > 1 {
name = fmt.Sprintf("%s-%d%s", stem, n, ext)
}
err := bfs.CreateRegular("raw/needs-review/"+name, data)
err := bfs.CreateRegular(dirRel+"/"+name, data)
if err == nil {
return nil
}
@@ -40,5 +47,5 @@ func createParked(brainDir, filename string, data []byte) error {
return err
}
}
return fmt.Errorf("no free name for %q in raw/needs-review", filename)
return fmt.Errorf("no free name for %q in %s", filename, dirRel)
}