fix: stop the scratch-name match from pruning user directories

未关闭 适合新手
#385 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
82/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
go
领域
tooling

调研方向

从 internal/indexdir/filter.go(besideStore,大约第 109–114 行)开始,找到仅按名称进行的 strings.HasPrefix 匹配,并检查 scratchdir.LockName,以改用内容检查。然后跟进 internal/indexer/discover/discoverexclusion.go:162-172 中的 pruning,查看排除记录在哪里创建。按照 issue 中的 mkdir/symlink 步骤重现;完成的标准是用户目录被索引(或记录并附带原因),同时包含 .lock 的真实 scratch 目录仍会被 pruning,并且在 internal/indexdir 下有一个测试。

由索引模型根据 Issue 内容生成。

描述

area:indexer bug needs-triage
What happens

The index skips any directory whose name starts with the store name followed by .scratch-. A user directory with such a name is skipped too. Discovery prunes it with no exclusion record, so its files are missing from the index and no reason is reported. This follows PR #384, which introduces the name match in internal/indexdir/filter.go.

Reproduced on commit 375d8be6 of branch fix/index-path-links, built from source:

$ codegraph index --force repo
files=1 nodes=2 edges=1 duration=82ms

Only repo/main.go is indexed. repo/store-real.scratch-notes/a.go is absent.

The cause is besideStore in internal/indexdir/filter.go:109-114. It matches a scratch directory by strings.HasPrefix on the name alone. DiscoverAll then prunes the matching directory before it makes any record (internal/indexer/discover/discoverexclusion.go:162-172).

What you expected instead

A directory that codegraph did not create is indexed as source, or it gets an exclusion record with a reason. Only a real scratch directory is pruned.

The match must check the content of the directory, such as its lock file .lock (scratchdir.LockName), and not the name alone. A scratch name ends in a random suffix, so the name cannot tell a scratch directory from a user directory.

Steps to reproduce
  1. Run mkdir -p repo/.codegraph repo/store-real repo/store-real.scratch-notes.
  2. Run ln -s ../store-real repo/.codegraph/store.
  3. Write package a to repo/store-real.scratch-notes/a.go, and package main to repo/main.go.
  4. Run codegraph index --force repo. Only one file is indexed.
Version

codegraph dev (commit unknown, built unknown) go1.26.11 darwin/arm64, built from 375d8be6.

Platform

macOS 27.2.1 arm64

How did you install it?

Built from source

Languages in the affected repository

Go. The bug depends on directory names, not on the language.

Before submitting
  • I searched existing issues and this is not a duplicate
  • I checked the capability matrix and this is not a documented limitation
  • This is not a security vulnerability
主要语言
Go
星标
0
派生
0
平均合并
5 小时 16 分钟
30 天内合并 PR
107

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

seanb4t/codegraph-go 的其他 Issue

查看 seanb4t/codegraph-go 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。