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

Function resolve_db_path

src/pipeline/pipeline.c:521–554  ·  view source on GitHub ↗

Resolve the DB path for this pipeline. Caller must free(). */

Source from the content-addressed store, hash-verified

519
520/* Resolve the DB path for this pipeline. Caller must free(). */
521static char *resolve_db_path(const cbm_pipeline_t *p) {
522 if (!p) {
523 return NULL;
524 }
525 if (p->db_path) {
526 return strdup(p->db_path);
527 }
528
529 const char *cache_dir = cbm_resolve_cache_dir();
530 cache_dir = cache_dir ? cache_dir : cbm_tmpdir();
531 if (!cache_dir || !p->project_name) {
532 return NULL;
533 }
534 size_t cache_len = strlen(cache_dir);
535 size_t project_len = strlen(p->project_name);
536 if (project_len > SIZE_MAX - cache_len) {
537 return NULL;
538 }
539 size_t stem_len = cache_len + project_len;
540 if (stem_len > SIZE_MAX - sizeof("/.db")) {
541 return NULL;
542 }
543 size_t path_size = stem_len + sizeof("/.db");
544 char *path = malloc(path_size);
545 if (!path) {
546 return NULL;
547 }
548 int n = snprintf(path, path_size, "%s/%s.db", cache_dir, p->project_name);
549 if (n < 0 || (size_t)n >= path_size) {
550 free(path);
551 return NULL;
552 }
553 return path;
554}
555
556static int check_cancel(const cbm_pipeline_t *p) {
557 return atomic_load(p->cancelled) ? CBM_NOT_FOUND : 0;

Callers 4

dump_and_persist_hashesFunction · 0.85
cbm_pipeline_runFunction · 0.85

Calls 2

cbm_resolve_cache_dirFunction · 0.85
cbm_tmpdirFunction · 0.85

Tested by

no test coverage detected