fix(vectorstore): walk and read the brain through brainfs (#157, slice 3)
Sync walked wiki/ and knowledge/ with filepath.WalkDir and read each .md with os.ReadFile. A symlinked note (Syncthing syncs symlinks) had its target embedded into pgvector and served by semantic search; a FIFO stalled the sync. The walk and read now go through brainfs: regular files only, type checked on the opened handle. - Chunks already embedded from a symlinked note are deleted on the next sync, because the note is no longer seen. - A walk error still aborts Sync before the delete pass, so an unreadable subdir does not delete chunks of files that exist. A missing scan dir is skipped as before. - brainfs gains Lstat, used for the mtime staleness check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -53,6 +53,12 @@ func (b *Brain) Rel(path string) (string, error) {
|
||||
return filepath.ToSlash(rel), nil
|
||||
}
|
||||
|
||||
// Lstat stats a brain-relative path through the root without following a
|
||||
// final symlink.
|
||||
func (b *Brain) Lstat(rel string) (fs.FileInfo, error) {
|
||||
return b.root.Lstat(filepath.ToSlash(rel))
|
||||
}
|
||||
|
||||
// ReadRegular reads a brain-relative path, refusing anything that is not a
|
||||
// regular file, both before the open and on the opened handle.
|
||||
func (b *Brain) ReadRegular(rel string) ([]byte, error) {
|
||||
|
||||
@@ -3,6 +3,7 @@ package brainfs
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
@@ -139,3 +140,18 @@ func (c *countingReader) Read(p []byte) (int, error) {
|
||||
c.n += n
|
||||
return n, err
|
||||
}
|
||||
|
||||
func TestLstatDoesNotFollowSymlinksAndRefusesEscapes(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
outside := filepath.Join(t.TempDir(), "o.md")
|
||||
require.NoError(t, os.WriteFile(outside, []byte("o"), 0o644))
|
||||
require.NoError(t, os.Symlink(outside, filepath.Join(dir, "l.md")))
|
||||
b, err := Open(dir)
|
||||
require.NoError(t, err)
|
||||
defer func() { _ = b.Close() }()
|
||||
fi, err := b.Lstat("l.md")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, fs.ModeSymlink, fi.Mode().Type())
|
||||
_, err = b.Lstat("../" + filepath.Base(filepath.Dir(outside)) + "/o.md")
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user