fix(ingestion): an unlistable brain root is a scan error, not clean
PR #159 round 2: with the brain root at mode 0100 (enterable, not listable) WalkDir failed at the root, Scan discarded the error and reported clean, and startup passed while search, which goes straight into wiki/, served a planted symlink. Scan now returns the root's walk error, so startup refuses on anything but a missing root. Also pins that a cleared set is reported again when it reappears. Refs #157 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -62,8 +62,9 @@ func (r Result) String() string {
|
||||
// directory it could not read, continuing past both. Only the ROOT .git is
|
||||
// skipped (it is brain-sync's, and no reader walks it); a nested .git is
|
||||
// scanned like any other directory. brainDir itself may be a symlink (a
|
||||
// volume mount); it is resolved first. The error is non-nil only when the
|
||||
// root cannot be resolved, wrapping os.ErrNotExist when it is missing.
|
||||
// volume mount); it is resolved first. The error is non-nil when the root
|
||||
// cannot be resolved (wrapping os.ErrNotExist when it is missing) or cannot be
|
||||
// listed.
|
||||
func Scan(brainDir string) (Result, error) {
|
||||
root, err := filepath.EvalSymlinks(brainDir)
|
||||
if err != nil {
|
||||
@@ -71,7 +72,7 @@ func Scan(brainDir string) (Result, error) {
|
||||
}
|
||||
var r Result
|
||||
rootGit := filepath.Join(root, ".git")
|
||||
_ = filepath.WalkDir(root, func(p string, d fs.DirEntry, err error) error {
|
||||
walkErr := filepath.WalkDir(root, func(p string, d fs.DirEntry, err error) error {
|
||||
rel, _ := filepath.Rel(root, p)
|
||||
rel = filepath.ToSlash(rel)
|
||||
if err != nil {
|
||||
@@ -94,6 +95,13 @@ func Scan(brainDir string) (Result, error) {
|
||||
})
|
||||
sort.Strings(r.Symlinks)
|
||||
sort.Strings(r.Unreadable)
|
||||
if walkErr != nil {
|
||||
// Only the root's own error reaches here (deeper errors are recorded
|
||||
// as Unreadable). A root that cannot be listed cannot be shown clean
|
||||
// (PR #159 round 2: discarding this reported clean while search
|
||||
// served a planted symlink).
|
||||
return r, fmt.Errorf("scan brain dir: %w", walkErr)
|
||||
}
|
||||
return r, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user