fix(brainfs): check every component of the walk root (#157)
Review round 2 on PR #166: Lstat on the walk root checks only its last component, so search with Wing+Hall (root wiki/<wing>/<hall>) walked a symlinked <wing> whose target had a real <hall> directory. WalkRegular now Lstats every prefix of the root and requires each to be a real directory. New brainfs and search (Wing+Hall) tests; the Wing-only search test is renamed to say what it covers. The doc now records the accepted residual: a directory swapped for a symlink between listing and read is still followed; os.Root keeps the read inside the brain but not inside the walk root. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -172,3 +172,20 @@ func TestWalkRegularReportsASymlinkedWalkRootAndYieldsNothing(t *testing.T) {
|
||||
require.Len(t, errs, 1)
|
||||
assert.ErrorIs(t, errs[0], ErrNotRegular)
|
||||
}
|
||||
|
||||
func TestWalkRegularReportsASymlinkedIntermediateComponentOfTheWalkRoot(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
require.NoError(t, os.MkdirAll(filepath.Join(dir, "real", "sub"), 0o755))
|
||||
require.NoError(t, os.WriteFile(filepath.Join(dir, "real", "sub", "n.md"), []byte("n"), 0o644))
|
||||
require.NoError(t, os.Symlink("real", filepath.Join(dir, "alias")))
|
||||
b, err := Open(dir)
|
||||
require.NoError(t, err)
|
||||
defer func() { _ = b.Close() }()
|
||||
var got []string
|
||||
var errs []error
|
||||
require.NoError(t, b.WalkRegular("alias/sub", func(rel string) error { got = append(got, rel); return nil },
|
||||
func(_ string, err error) { errs = append(errs, err) }))
|
||||
assert.Empty(t, got)
|
||||
require.Len(t, errs, 1)
|
||||
assert.ErrorIs(t, errs[0], ErrNotRegular)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user