fix: pipeline, backfill, watcher and archive writes go through the brain root (#158 part B)
The remaining writers created or rewrote brain files by path: - pipeline buildAndWrite: os.MkdirAll + os.WriteFile of every page. - BackfillRefs: os.WriteFile of each concept page; a page swapped for a symlink after the read was written through (the race test overwrote an in-brain target before this change). - watcher: the raw/processed and raw/failed archive copies (os.Create), the .processed/.failed markers and the log.md entry (os.OpenFile). - cmd/server: the claude-session archive. All now go through brainfs PutRegular/AppendRegular (new package-level PutFile/AppendFile for one-off writers: the watcher's call-site lint bans .Open calls in that file so raw/ reads stay on OpenRegular). Stacked on #189 (needs PutRegular/AppendRegular). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -224,6 +224,27 @@ func (b *Brain) RealParent(rel string) error {
|
||||
return b.realDir(path.Dir(rel))
|
||||
}
|
||||
|
||||
// PutFile opens the brain dir as a root and calls PutRegular, for one-off
|
||||
// writers that hold no Brain.
|
||||
func PutFile(brainDir, rel string, data []byte) error {
|
||||
b, err := Open(brainDir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() { _ = b.Close() }()
|
||||
return b.PutRegular(rel, data)
|
||||
}
|
||||
|
||||
// AppendFile opens the brain dir as a root and calls AppendRegular.
|
||||
func AppendFile(brainDir, rel string, data []byte) error {
|
||||
b, err := Open(brainDir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() { _ = b.Close() }()
|
||||
return b.AppendRegular(rel, data)
|
||||
}
|
||||
|
||||
// mkdirReal makes sure every component of rel exists as a real directory,
|
||||
// creating missing ones through the root; an existing component that is
|
||||
// not a real directory is ErrNotRegular.
|
||||
|
||||
Reference in New Issue
Block a user