| 6705 | } |
| 6706 | |
| 6707 | static int arch_file_tree(cbm_store_t *s, const char *project, const char *path, |
| 6708 | cbm_architecture_info_t *out) { |
| 6709 | char norm[CBM_SZ_512]; |
| 6710 | char like[CBM_SZ_512]; |
| 6711 | bool scoped = arch_path_prepare(path, norm, sizeof(norm), like, sizeof(like)); |
| 6712 | char sqlbuf[ST_SQL_BUF]; |
| 6713 | const char *base = "SELECT file_path FROM nodes WHERE project=?1 AND label='File'"; |
| 6714 | if (scoped) { |
| 6715 | snprintf(sqlbuf, sizeof(sqlbuf), "%s%s", base, arch_path_scope_sql()); |
| 6716 | } else { |
| 6717 | snprintf(sqlbuf, sizeof(sqlbuf), "%s", base); |
| 6718 | } |
| 6719 | sqlite3_stmt *stmt = NULL; |
| 6720 | if (sqlite3_prepare_v2(s->db, sqlbuf, CBM_NOT_FOUND, &stmt, NULL) != SQLITE_OK) { |
| 6721 | store_set_error_sqlite(s, "arch_file_tree"); |
| 6722 | return CBM_STORE_ERR; |
| 6723 | } |
| 6724 | bind_text(stmt, SKIP_ONE, project); |
| 6725 | if (scoped) { |
| 6726 | arch_bind_path_scope(stmt, ST_COL_2, ST_COL_3, norm, like); |
| 6727 | } |
| 6728 | |
| 6729 | int fcap = CBM_SZ_32; |
| 6730 | int fn = 0; |
| 6731 | char **files = malloc(fcap * sizeof(char *)); |
| 6732 | |
| 6733 | int dcap = CBM_SZ_64; |
| 6734 | int dn = 0; |
| 6735 | char **dir_paths = calloc(dcap, sizeof(char *)); |
| 6736 | int *dir_child_counts = calloc(dcap, sizeof(int)); |
| 6737 | char ***dir_children = calloc(dcap, sizeof(char **)); |
| 6738 | int *dir_children_caps = calloc(dcap, sizeof(int)); |
| 6739 | |
| 6740 | int scan_rc28; |
| 6741 | while ((scan_rc28 = sqlite3_step(stmt)) == SQLITE_ROW) { |
| 6742 | const char *fp = (const char *)sqlite3_column_text(stmt, 0); |
| 6743 | if (!fp) { |
| 6744 | continue; |
| 6745 | } |
| 6746 | if (fn >= fcap) { |
| 6747 | fcap *= ST_GROWTH; |
| 6748 | files = safe_realloc(files, fcap * sizeof(char *)); |
| 6749 | } |
| 6750 | files[fn++] = heap_strdup(fp); |
| 6751 | arch_register_file_dirs(fp, dir_paths, dir_child_counts, dir_children, dir_children_caps, |
| 6752 | &dn, dcap); |
| 6753 | } |
| 6754 | if (scan_rc28 != SQLITE_DONE) { /* SCANCHK:28:stmt */ |
| 6755 | store_set_error_sqlite(s, "row scan aborted"); |
| 6756 | sqlite3_finalize(stmt); |
| 6757 | arch_free_dirs(dir_paths, dir_child_counts, dir_children, dir_children_caps, dn, files, fn); |
| 6758 | return CBM_STORE_ERR; |
| 6759 | } |
| 6760 | sqlite3_finalize(stmt); |
| 6761 | |
| 6762 | arch_collect_entries(dir_paths, dir_child_counts, dir_children, dn, files, fn, &out->file_tree, |
| 6763 | &out->file_tree_count); |
| 6764 |
no test coverage detected