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

Function find_alias_files

src/pipeline/path_alias.c:385–445  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

383enum { TS_CONFIG_NAMES_COUNT = 2 };
384
385static void find_alias_files(const char *abs_dir, const char *rel_dir, alias_config_hit_t *out,
386 int *count, int max_count, int depth, char **excluded_dirs,
387 int excluded_count) {
388 if (*count >= max_count || depth > CBM_PATH_ALIAS_MAX_DEPTH) {
389 return;
390 }
391 cbm_dir_t *d = cbm_opendir(abs_dir);
392 if (!d) {
393 return;
394 }
395
396 /* One config file per directory: prefer tsconfig.json over jsconfig.json. */
397 for (int i = 0; i < TS_CONFIG_NAMES_COUNT && *count < max_count; i++) {
398 char check[CBM_SZ_512];
399 snprintf(check, sizeof(check), "%s/%s", abs_dir, TS_CONFIG_NAMES[i]);
400 FILE *f = cbm_fopen(check, "r");
401 if (f) {
402 fclose(f);
403 snprintf(out[*count].abs, sizeof(out[*count].abs), "%s", check);
404 snprintf(out[*count].rel, sizeof(out[*count].rel), "%s", rel_dir);
405 (*count)++;
406 break;
407 }
408 }
409
410 cbm_dirent_t *ent;
411 while ((ent = cbm_readdir(d)) != NULL && *count < max_count) {
412 if (!ent->is_dir) {
413 continue;
414 }
415 const char *name = ent->name;
416 if (name[0] == '.' || strcmp(name, "node_modules") == 0 || strcmp(name, "dist") == 0 ||
417 strcmp(name, "build") == 0 || strcmp(name, ".next") == 0 ||
418 strcmp(name, "coverage") == 0 || strcmp(name, "target") == 0 /* Rust */) {
419 continue;
420 }
421 char child_abs[CBM_SZ_512];
422 char child_rel[CBM_SZ_256];
423 snprintf(child_abs, sizeof(child_abs), "%s/%s", abs_dir, name);
424 if (rel_dir[0] == '\0') {
425 snprintf(child_rel, sizeof(child_rel), "%s", name);
426 } else {
427 snprintf(child_rel, sizeof(child_rel), "%s/%s", rel_dir, name);
428 }
429 if (cbm_pipeline_relpath_is_excluded(child_rel, excluded_dirs, excluded_count)) {
430 continue;
431 }
432 /* A link is not followed, as discovery does not follow one. is_dir is
433 * also true for a junction or a directory symbolic link on Windows,
434 * and either can lead out of the repository. A child whose metadata
435 * cannot be read is skipped the same way. */
436 cbm_path_info_t child_info;
437 if (cbm_path_info_utf8(child_abs, &child_info) != CBM_PATH_INFO_OK ||
438 child_info.is_symlink) {
439 continue;
440 }
441 find_alias_files(child_abs, child_rel, out, count, max_count, depth + 1, excluded_dirs,
442 excluded_count);

Callers 1

Calls 6

cbm_opendirFunction · 0.85
cbm_fopenFunction · 0.85
cbm_readdirFunction · 0.85
cbm_path_info_utf8Function · 0.85
cbm_closedirFunction · 0.85

Tested by

no test coverage detected