MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / pkgmap_walk_dir

Function pkgmap_walk_dir

src/pipeline/pass_pkgmap.c:1147–1212  ·  view source on GitHub ↗

Recursive filesystem walker that finds and parses package manifest * files independently of the main discovery filter. The main discovery * filter intentionally hides package.json / composer.json etc. from * code indexing (they're config, not source), but pass_pkgmap still * needs to read them to resolve workspace imports. Skips directories * matched by the shared cbm_should_skip_dir helper s

Source from the content-addressed store, hash-verified

1145 * it hang. On Windows we additionally skip reparse points before
1146 * descending as a best-effort early-out. */
1147static int pkgmap_walk_dir(const char *abs_dir, const char *rel_dir, cbm_pkg_entries_t *entries,
1148 int depth, char **excluded_dirs, int excluded_count) {
1149 if (depth >= PKGMAP_WALK_MAX_DEPTH) {
1150 cbm_log_info("pkgmap.walk", "depth_cap", rel_dir && rel_dir[0] ? rel_dir : ".");
1151 return 0;
1152 }
1153 cbm_dir_t *dir = cbm_opendir(abs_dir);
1154 if (!dir) {
1155 return 0;
1156 }
1157 int parsed = 0;
1158 cbm_dirent_t *entry;
1159 while ((entry = cbm_readdir(dir)) != NULL) {
1160 const char *name = entry->name;
1161 if (name[0] == '.' && (name[1] == '\0' || (name[1] == '.' && name[2] == '\0'))) {
1162 continue;
1163 }
1164 char abs_path[PKGMAP_PATH_BUF];
1165 char rel_path[PKGMAP_PATH_BUF];
1166 snprintf(abs_path, sizeof(abs_path), "%s/%s", abs_dir, name);
1167 if (rel_dir && rel_dir[0]) {
1168 snprintf(rel_path, sizeof(rel_path), "%s/%s", rel_dir, name);
1169 } else {
1170 snprintf(rel_path, sizeof(rel_path), "%s", name);
1171 }
1172 struct stat st;
1173 if (pkgmap_safe_stat(abs_path, &st) != 0) {
1174 continue;
1175 }
1176 if (S_ISDIR(st.st_mode)) {
1177 if (cbm_should_skip_dir(name, CBM_MODE_FULL) ||
1178 cbm_pipeline_relpath_is_excluded(rel_path, excluded_dirs, excluded_count)) {
1179 continue;
1180 }
1181#ifdef _WIN32
1182 /* Don't follow Windows directory junctions — they can form
1183 * cycles. The depth bound is the hard guarantee; this just
1184 * avoids wasted descent. (POSIX symlinks are already skipped by
1185 * pkgmap_safe_stat's S_ISLNK check.) */
1186 if (pkgmap_is_reparse_point(abs_path)) {
1187 continue;
1188 }
1189#endif
1190 parsed += pkgmap_walk_dir(abs_path, rel_path, entries, depth + 1, excluded_dirs,
1191 excluded_count);
1192 continue;
1193 }
1194 if (!S_ISREG(st.st_mode)) {
1195 continue;
1196 }
1197 if (!is_pkgmap_manifest_basename(name)) {
1198 continue;
1199 }
1200 int source_len = 0;
1201 char *source = pkgmap_read_file(abs_path, &source_len);
1202 if (!source) {
1203 continue;
1204 }

Callers 1

cbm_pkgmap_scan_repoFunction · 0.85

Calls 11

cbm_opendirFunction · 0.85
cbm_readdirFunction · 0.85
pkgmap_safe_statFunction · 0.85
cbm_should_skip_dirFunction · 0.85
pkgmap_is_reparse_pointFunction · 0.85
pkgmap_read_fileFunction · 0.85
cbm_pkgmap_try_parseFunction · 0.85
cbm_freeFunction · 0.85
cbm_closedirFunction · 0.85

Tested by

no test coverage detected