fix(brain): wing indexes and the link check read through brainfs (#157, slice 5a)
BuildWingIndex/BuildAllWingIndexes listed wiki/<wing>/<hall>/ with os.ReadDir and opened each note by path: a symlinked note put the target's title into _index.md (110k leaks in the swap race), a symlinked wing was followed and its _index.md written into the target, and a FIFO hung the build (it runs on every brain_write). - New brainfs.ReadDirDirs: real subdirectories only, every component of the dir a real directory. Wings and halls are listed with it and ReadDirRegular; titles are read with ReadRegular (readTitleAndCreatedIn). A symlinked wing is an error; a symlinked hall is skipped. - linkcheck entryIndex walks with WalkRegular: a symlinked .md name no longer makes a [[link]] resolve. - readTitleAndCreated (path-based) stays for tunnel.DetectTunnels until PR #170 lands; that is slice 5b. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -262,3 +262,21 @@ func TestReadRegularNeverReturnsAnInBrainFileSwappedInBehindASymlink(t *testing.
|
||||
assert.Zero(t, leaks)
|
||||
assert.Positive(t, ok, "positive control: the regular file is read")
|
||||
}
|
||||
|
||||
func TestReadDirDirsListsOnlyRealSubdirsAndRefusesSymlinkedComponents(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
require.NoError(t, os.MkdirAll(filepath.Join(dir, "a", "real"), 0o755))
|
||||
require.NoError(t, os.MkdirAll(filepath.Join(dir, "other"), 0o755))
|
||||
require.NoError(t, os.Symlink(filepath.Join("..", "other"), filepath.Join(dir, "a", "linked")))
|
||||
require.NoError(t, os.WriteFile(filepath.Join(dir, "a", "f.md"), []byte("f"), 0o644))
|
||||
require.NoError(t, os.Symlink("a", filepath.Join(dir, "alias")))
|
||||
b, err := Open(dir)
|
||||
require.NoError(t, err)
|
||||
defer func() { _ = b.Close() }()
|
||||
|
||||
names, err := b.ReadDirDirs("a")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, []string{"real"}, names)
|
||||
_, err = b.ReadDirDirs("alias")
|
||||
assert.ErrorIs(t, err, ErrNotRegular)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user