fix(watcher): park through the brain root, keep a note edited mid-resolve, honour only real fences (#205)
From the second independent review of #207:
- parkForReview now skips the delete when the note changed since it was read
(an LLM call sits in that window; Syncthing can deliver a newer version)
- parked copies are created via brainfs (real dirs only, O_EXCL, no symlink
following), so a planted raw/needs-review symlink cannot redirect or hide a
note; this also removes the need for the guard allowlist entry added in
1e14c56, which is reverted
- a '----' line no longer closes the proposal block
Each has a test that failed first and a mutant that fails it.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
package watcher
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/mathiasbq/hyperguild/ingestion/internal/brainfs"
|
||||
)
|
||||
|
||||
// Kept out of watcher.go on purpose: that file is covered by the raw-reader
|
||||
// guard (internal/extract/callsites_test.go), which forbids any .Open selector
|
||||
// there. This function reads nothing from raw/; it creates a file under the
|
||||
// brain root, which refuses symlinked directories and never follows a final
|
||||
// symlink.
|
||||
|
||||
// createParked writes data to raw/needs-review/<filename> through the brain
|
||||
// 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 {
|
||||
bfs, err := brainfs.Open(brainDir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() { _ = bfs.Close() }()
|
||||
ext := filepath.Ext(filename)
|
||||
stem := strings.TrimSuffix(filename, ext)
|
||||
for n := 1; n < 10000; n++ {
|
||||
name := filename
|
||||
if n > 1 {
|
||||
name = fmt.Sprintf("%s-%d%s", stem, n, ext)
|
||||
}
|
||||
err := bfs.CreateRegular("raw/needs-review/"+name, data)
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
if !errors.Is(err, fs.ErrExist) {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("no free name for %q in raw/needs-review", filename)
|
||||
}
|
||||
Reference in New Issue
Block a user