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

Function cbm_config_open

src/cli/cli.c:6603–6638  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6601};
6602
6603cbm_config_t *cbm_config_open(const char *cache_dir) {
6604 if (!cache_dir) {
6605 return NULL;
6606 }
6607
6608 char dbpath[CLI_BUF_1K];
6609 snprintf(dbpath, sizeof(dbpath), "%s/_config.db", cache_dir);
6610
6611 /* Ensure directory exists */
6612 mkdirp(cache_dir, DIR_PERMS);
6613
6614 sqlite3 *db = NULL;
6615 if (sqlite3_open(dbpath, &db) != SQLITE_OK) {
6616 if (db) {
6617 sqlite3_close(db);
6618 }
6619 return NULL;
6620 }
6621
6622 /* Create table if not exists */
6623 const char *sql = "CREATE TABLE IF NOT EXISTS config (key TEXT PRIMARY KEY, value TEXT)";
6624 char *err_msg = NULL;
6625 if (sqlite3_exec(db, sql, NULL, NULL, &err_msg) != SQLITE_OK) {
6626 sqlite3_free(err_msg);
6627 sqlite3_close(db);
6628 return NULL;
6629 }
6630
6631 cbm_config_t *cfg = calloc(CBM_ALLOC_ONE, sizeof(*cfg));
6632 if (!cfg) {
6633 sqlite3_close(db);
6634 return NULL;
6635 }
6636 cfg->db = db;
6637 return cfg;
6638}
6639
6640void cbm_config_close(cbm_config_t *cfg) {
6641 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