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

Function arch_file_tree

src/store/store.c:6597–6657  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6595}
6596
6597static int arch_file_tree(cbm_store_t *s, const char *project, const char *path,
6598 cbm_architecture_info_t *out) {
6599 char norm[CBM_SZ_512];
6600 char like[CBM_SZ_512];
6601 bool scoped = arch_path_prepare(path, norm, sizeof(norm), like, sizeof(like));
6602 char sqlbuf[ST_SQL_BUF];
6603 const char *base = "SELECT file_path FROM nodes WHERE project=?1 AND label='File'";
6604 if (scoped) {
6605 snprintf(sqlbuf, sizeof(sqlbuf), "%s%s", base, arch_path_scope_sql());
6606 } else {
6607 snprintf(sqlbuf, sizeof(sqlbuf), "%s", base);
6608 }
6609 sqlite3_stmt *stmt = NULL;
6610 if (sqlite3_prepare_v2(s->db, sqlbuf, CBM_NOT_FOUND, &stmt, NULL) != SQLITE_OK) {
6611 store_set_error_sqlite(s, "arch_file_tree");
6612 return CBM_STORE_ERR;
6613 }
6614 bind_text(stmt, SKIP_ONE, project);
6615 if (scoped) {
6616 arch_bind_path_scope(stmt, ST_COL_2, ST_COL_3, norm, like);
6617 }
6618
6619 int fcap = CBM_SZ_32;
6620 int fn = 0;
6621 char **files = malloc(fcap * sizeof(char *));
6622
6623 int dcap = CBM_SZ_64;
6624 int dn = 0;
6625 char **dir_paths = calloc(dcap, sizeof(char *));
6626 int *dir_child_counts = calloc(dcap, sizeof(int));
6627 char ***dir_children = calloc(dcap, sizeof(char **));
6628 int *dir_children_caps = calloc(dcap, sizeof(int));
6629
6630 int scan_rc28;
6631 while ((scan_rc28 = sqlite3_step(stmt)) == SQLITE_ROW) {
6632 const char *fp = (const char *)sqlite3_column_text(stmt, 0);
6633 if (!fp) {
6634 continue;
6635 }
6636 if (fn >= fcap) {
6637 fcap *= ST_GROWTH;
6638 files = safe_realloc(files, fcap * sizeof(char *));
6639 }
6640 files[fn++] = heap_strdup(fp);
6641 arch_register_file_dirs(fp, dir_paths, dir_child_counts, dir_children, dir_children_caps,
6642 &dn, dcap);
6643 }
6644 if (scan_rc28 != SQLITE_DONE) { /* SCANCHK:28:stmt */
6645 store_set_error_sqlite(s, "row scan aborted");
6646 sqlite3_finalize(stmt);
6647 arch_free_dirs(dir_paths, dir_child_counts, dir_children, dir_children_caps, dn, files, fn);
6648 return CBM_STORE_ERR;
6649 }
6650 sqlite3_finalize(stmt);
6651
6652 arch_collect_entries(dir_paths, dir_child_counts, dir_children, dn, files, fn, &out->file_tree,
6653 &out->file_tree_count);
6654

Callers 1

Calls 10

arch_path_prepareFunction · 0.85
arch_path_scope_sqlFunction · 0.85
store_set_error_sqliteFunction · 0.85
bind_textFunction · 0.85
arch_bind_path_scopeFunction · 0.85
safe_reallocFunction · 0.85
arch_register_file_dirsFunction · 0.85
arch_free_dirsFunction · 0.85
arch_collect_entriesFunction · 0.85
heap_strdupFunction · 0.70

Tested by

no test coverage detected