| 6494 | } |
| 6495 | |
| 6496 | static int arch_file_tree(cbm_store_t *s, const char *project, const char *path, |
| 6497 | cbm_architecture_info_t *out) { |
| 6498 | char norm[CBM_SZ_512]; |
| 6499 | char like[CBM_SZ_512]; |
| 6500 | bool scoped = arch_path_prepare(path, norm, sizeof(norm), like, sizeof(like)); |
| 6501 | char sqlbuf[ST_SQL_BUF]; |
| 6502 | const char *base = "SELECT file_path FROM nodes WHERE project=?1 AND label='File'"; |
| 6503 | if (scoped) { |
| 6504 | snprintf(sqlbuf, sizeof(sqlbuf), "%s%s", base, arch_path_scope_sql()); |
| 6505 | } else { |
| 6506 | snprintf(sqlbuf, sizeof(sqlbuf), "%s", base); |
| 6507 | } |
| 6508 | sqlite3_stmt *stmt = NULL; |
| 6509 | if (sqlite3_prepare_v2(s->db, sqlbuf, CBM_NOT_FOUND, &stmt, NULL) != SQLITE_OK) { |
| 6510 | store_set_error_sqlite(s, "arch_file_tree"); |
| 6511 | return CBM_STORE_ERR; |
| 6512 | } |
| 6513 | bind_text(stmt, SKIP_ONE, project); |
| 6514 | if (scoped) { |
| 6515 | arch_bind_path_scope(stmt, ST_COL_2, ST_COL_3, norm, like); |
| 6516 | } |
| 6517 | |
| 6518 | int fcap = CBM_SZ_32; |
| 6519 | int fn = 0; |
| 6520 | char **files = malloc(fcap * sizeof(char *)); |
| 6521 | |
| 6522 | int dcap = CBM_SZ_64; |
| 6523 | int dn = 0; |
| 6524 | char **dir_paths = calloc(dcap, sizeof(char *)); |
| 6525 | int *dir_child_counts = calloc(dcap, sizeof(int)); |
| 6526 | char ***dir_children = calloc(dcap, sizeof(char **)); |
| 6527 | int *dir_children_caps = calloc(dcap, sizeof(int)); |
| 6528 | |
| 6529 | int scan_rc28; |
| 6530 | while ((scan_rc28 = sqlite3_step(stmt)) == SQLITE_ROW) { |
| 6531 | const char *fp = (const char *)sqlite3_column_text(stmt, 0); |
| 6532 | if (!fp) { |
| 6533 | continue; |
| 6534 | } |
| 6535 | if (fn >= fcap) { |
| 6536 | fcap *= ST_GROWTH; |
| 6537 | files = safe_realloc(files, fcap * sizeof(char *)); |
| 6538 | } |
| 6539 | files[fn++] = heap_strdup(fp); |
| 6540 | arch_register_file_dirs(fp, dir_paths, dir_child_counts, dir_children, dir_children_caps, |
| 6541 | &dn, dcap); |
| 6542 | } |
| 6543 | if (scan_rc28 != SQLITE_DONE) { /* SCANCHK:28:stmt */ |
| 6544 | store_set_error_sqlite(s, "row scan aborted"); |
| 6545 | sqlite3_finalize(stmt); |
| 6546 | arch_free_dirs(dir_paths, dir_child_counts, dir_children, dir_children_caps, dn, files, fn); |
| 6547 | return CBM_STORE_ERR; |
| 6548 | } |
| 6549 | sqlite3_finalize(stmt); |
| 6550 | |
| 6551 | arch_collect_entries(dir_paths, dir_child_counts, dir_children, dn, files, fn, &out->file_tree, |
| 6552 | &out->file_tree_count); |
| 6553 |
no test coverage detected