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

Function cbm_writer_finalize

internal/cbm/sqlite_writer.c:2395–2434  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2393}
2394
2395int cbm_writer_finalize(cbm_db_writer_t *w, const char *project, const char *root_path,
2396 const char *indexed_at, CBMDumpNode *nodes, int node_count,
2397 CBMDumpEdge *edges, int edge_count, CBMDumpVector *vectors,
2398 int vector_count, CBMDumpTokenVec *token_vecs, int token_vec_count) {
2399 if (!w) {
2400 return CBM_NOT_FOUND;
2401 }
2402 int err = w->err;
2403 uint32_t nodes_root = 0;
2404 if (err == 0) {
2405 if (w->node_rows_written == 0) {
2406 pb_free(&w->nodes_pb);
2407 nodes_root = write_table_btree(w->wc.fp, &w->wc.next_page, NULL, NULL, NULL, 0, false);
2408 } else {
2409 nodes_root = pb_finalize_table(&w->nodes_pb, &w->wc.next_page, w->last_node_rowid);
2410 }
2411 }
2412 w->wc.project = project;
2413 w->wc.root_path = root_path;
2414 w->wc.indexed_at = indexed_at;
2415 w->wc.nodes = nodes;
2416 w->wc.node_count = node_count;
2417 w->wc.edges = edges;
2418 w->wc.edge_count = edge_count;
2419 w->wc.vectors = vectors;
2420 w->wc.vector_count = vector_count;
2421 w->wc.token_vecs = token_vecs;
2422 w->wc.token_vec_count = token_vec_count;
2423
2424 write_db_ctx_t wc = w->wc; /* value copy survives free(w) */
2425 free(w);
2426 if (err != 0) {
2427 /* A sticky append failure: errno belongs to whatever call failed
2428 * many calls ago, not to the publish. Clear it so the caller does
2429 * not attach a reason this path does not have. */
2430 errno = 0;
2431 return discard_writer_output(&wc, err);
2432 }
2433 return write_db_after_nodes(&wc, nodes_root);
2434}
2435
2436int cbm_write_db(const char *path, const char *project, const char *root_path,
2437 const char *indexed_at, CBMDumpNode *nodes, int node_count, CBMDumpEdge *edges,

Callers 3

cbm_write_dbFunction · 0.85
cbm_gbuf_dump_to_sqliteFunction · 0.85

Calls 5

pb_freeFunction · 0.85
write_table_btreeFunction · 0.85
pb_finalize_tableFunction · 0.85
discard_writer_outputFunction · 0.85
write_db_after_nodesFunction · 0.85

Tested by

no test coverage detected