Skip to content

Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.

discover: skip Windows junctions and reparse points during the walk

Martin Vogelab0fe75f1f62
diff --git a/src/discover/discover.c b/src/discover/discover.c
index 479dd695b..d38a74f37 100644
--- a/src/discover/discover.c
+++ b/src/discover/discover.c
@@ -606,9 +606,20 @@ static int wide_stat(const char *path, struct stat *st) {
#endif
}
-/* Stat a path, skipping symlinks. Returns 0 on success, -1 to skip. */
+/* Stat a path, skipping symlinks (POSIX) and junctions / reparse points
+ * (Windows). Returns 0 on success, -1 to skip. Skipping reparse points keeps
+ * discovery from walking through a junction that points outside the project
+ * root, mirroring the POSIX S_ISLNK skip. */
static int safe_stat(const char *abs_path, struct stat *st) {
#ifdef _WIN32
+ wchar_t *wpath = cbm_utf8_to_wide(abs_path);
+ if (wpath) {
+ DWORD attr = GetFileAttributesW(wpath);
+ free(wpath);
+ if (attr != INVALID_FILE_ATTRIBUTES && (attr & FILE_ATTRIBUTE_REPARSE_POINT)) {
+ return CBM_NOT_FOUND;
+ }
+ }
return wide_stat(abs_path, st);
#else
if (lstat(abs_path, st) != 0) {