| 2247 | } |
| 2248 | |
| 2249 | int cbm_writer_finalize(cbm_db_writer_t *w, const char *project, const char *root_path, |
| 2250 | const char *indexed_at, CBMDumpNode *nodes, int node_count, |
| 2251 | CBMDumpEdge *edges, int edge_count, CBMDumpVector *vectors, |
| 2252 | int vector_count, CBMDumpTokenVec *token_vecs, int token_vec_count) { |
| 2253 | if (!w) { |
| 2254 | return CBM_NOT_FOUND; |
| 2255 | } |
| 2256 | int err = w->err; |
| 2257 | uint32_t nodes_root = 0; |
| 2258 | if (err == 0) { |
| 2259 | if (w->node_rows_written == 0) { |
| 2260 | pb_free(&w->nodes_pb); |
| 2261 | nodes_root = write_table_btree(w->wc.fp, &w->wc.next_page, NULL, NULL, NULL, 0, false); |
| 2262 | } else { |
| 2263 | nodes_root = pb_finalize_table(&w->nodes_pb, &w->wc.next_page, w->last_node_rowid); |
| 2264 | } |
| 2265 | } |
| 2266 | w->wc.project = project; |
| 2267 | w->wc.root_path = root_path; |
| 2268 | w->wc.indexed_at = indexed_at; |
| 2269 | w->wc.nodes = nodes; |
| 2270 | w->wc.node_count = node_count; |
| 2271 | w->wc.edges = edges; |
| 2272 | w->wc.edge_count = edge_count; |
| 2273 | w->wc.vectors = vectors; |
| 2274 | w->wc.vector_count = vector_count; |
| 2275 | w->wc.token_vecs = token_vecs; |
| 2276 | w->wc.token_vec_count = token_vec_count; |
| 2277 | |
| 2278 | write_db_ctx_t wc = w->wc; /* value copy survives free(w) */ |
| 2279 | free(w); |
| 2280 | if (err != 0) { |
| 2281 | (void)fclose(wc.fp); /* wc is a value copy, valid after free(w) */ |
| 2282 | return err; |
| 2283 | } |
| 2284 | return write_db_after_nodes(&wc, nodes_root); |
| 2285 | } |
| 2286 | |
| 2287 | int cbm_write_db(const char *path, const char *project, const char *root_path, |
| 2288 | const char *indexed_at, CBMDumpNode *nodes, int node_count, CBMDumpEdge *edges, |
no test coverage detected