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

Function cbm_writer_open

internal/cbm/sqlite_writer.c:2278–2300  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2276};
2277
2278cbm_db_writer_t *cbm_writer_open(const char *path) {
2279 cbm_db_writer_t *w = (cbm_db_writer_t *)calloc(CBM_ALLOC_ONE, sizeof(*w));
2280 if (!w) {
2281 return NULL;
2282 }
2283 int n = snprintf(w->wc.final_path, sizeof(w->wc.final_path), "%s", path);
2284 if (n < 0 || (size_t)n >= sizeof(w->wc.final_path) ||
2285 make_writer_temp_path(path, w, w->wc.temp_path, sizeof(w->wc.temp_path)) != 0) {
2286 free(w);
2287 return NULL;
2288 }
2289 FILE *fp = cbm_fopen(w->wc.temp_path, "wb");
2290 if (!fp) {
2291 (void)cbm_unlink(w->wc.temp_path);
2292 free(w);
2293 return NULL;
2294 }
2295 w->wc.fp = fp;
2296 w->wc.next_page = FIRST_DATA_PAGE;
2297 /* Nodes are never page 1 (page 1 is sqlite_master, written at finalize). */
2298 pb_init(&w->nodes_pb, fp, FIRST_DATA_PAGE, false);
2299 return w;
2300}
2301
2302int cbm_writer_append_nodes(cbm_db_writer_t *w, const CBMDumpNode *nodes, int count) {
2303 if (!w) {

Callers 3

cbm_write_dbFunction · 0.85
cbm_gbuf_dump_to_sqliteFunction · 0.85

Calls 4

make_writer_temp_pathFunction · 0.85
cbm_fopenFunction · 0.85
cbm_unlinkFunction · 0.85
pb_initFunction · 0.85

Tested by

no test coverage detected