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

Function cbm_config_open

src/cli/cli.c:6439–6474  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6437};
6438
6439cbm_config_t *cbm_config_open(const char *cache_dir) {
6440 if (!cache_dir) {
6441 return NULL;
6442 }
6443
6444 char dbpath[CLI_BUF_1K];
6445 snprintf(dbpath, sizeof(dbpath), "%s/_config.db", cache_dir);
6446
6447 /* Ensure directory exists */
6448 mkdirp(cache_dir, DIR_PERMS);
6449
6450 sqlite3 *db = NULL;
6451 if (sqlite3_open(dbpath, &db) != SQLITE_OK) {
6452 if (db) {
6453 sqlite3_close(db);
6454 }
6455 return NULL;
6456 }
6457
6458 /* Create table if not exists */
6459 const char *sql = "CREATE TABLE IF NOT EXISTS config (key TEXT PRIMARY KEY, value TEXT)";
6460 char *err_msg = NULL;
6461 if (sqlite3_exec(db, sql, NULL, NULL, &err_msg) != SQLITE_OK) {
6462 sqlite3_free(err_msg);
6463 sqlite3_close(db);
6464 return NULL;
6465 }
6466
6467 cbm_config_t *cfg = calloc(CBM_ALLOC_ONE, sizeof(*cfg));
6468 if (!cfg) {
6469 sqlite3_close(db);
6470 return NULL;
6471 }
6472 cfg->db = db;
6473 return cfg;
6474}
6475
6476void cbm_config_close(cbm_config_t *cfg) {
6477 if (!cfg) {

Callers 8

cbm_cmd_configFunction · 0.85
handle_ui_configFunction · 0.85
host_state_prepareFunction · 0.85
test_cli.cFile · 0.85
test_httpd.cFile · 0.85

Calls 1

mkdirpFunction · 0.85

Tested by 2