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

Function handle_delete_project

src/mcp/mcp.c:4519–4597  ·  view source on GitHub ↗

delete_project: just erase the .db file (and WAL/SHM). */

Source from the content-addressed store, hash-verified

4517
4518/* delete_project: just erase the .db file (and WAL/SHM). */
4519static char *handle_delete_project(cbm_mcp_server_t *srv, const char *args) {
4520 char *name = get_project_arg(args);
4521 if (!name) {
4522 return cbm_mcp_text_result("project is required", true);
4523 }
4524 if (!mcp_project_mutation_begin(srv, name)) {
4525 free(name);
4526 return cbm_mcp_text_result("project operation cancelled or blocked by an active index",
4527 true);
4528 }
4529
4530 /* Close store if it's the project being deleted */
4531 if (srv->current_project && strcmp(srv->current_project, name) == 0) {
4532 if (srv->owns_store && srv->store) {
4533 cbm_store_close(srv->store);
4534 srv->store = NULL;
4535 }
4536 free(srv->current_project);
4537 srv->current_project = NULL;
4538 }
4539
4540 /* Wait for any in-progress pipeline to finish before deleting */
4541 cbm_pipeline_lock();
4542
4543 /* Delete the .db file + WAL/SHM */
4544 char path[CBM_SZ_1K];
4545 project_db_path(name, path, sizeof(path));
4546
4547 char wal[CBM_SZ_1K];
4548 char shm[CBM_SZ_1K];
4549 snprintf(wal, sizeof(wal), "%s-wal", path);
4550 snprintf(shm, sizeof(shm), "%s-shm", path);
4551
4552 bool exists = (access(path, F_OK) == 0);
4553 const char *status = "not_found";
4554 const char *error_detail = NULL;
4555 bool is_error = false;
4556
4557 if (exists) {
4558 int rc = cbm_unlink(path);
4559 (void)cbm_unlink(wal);
4560 (void)cbm_unlink(shm);
4561 if (rc == 0) {
4562 status = "deleted";
4563 } else {
4564 status = "delete_failed";
4565 error_detail = strerror(errno);
4566 is_error = true;
4567 }
4568 } else {
4569 is_error = true;
4570 }
4571
4572 cbm_pipeline_unlock();
4573
4574 if (srv->watcher) {
4575 cbm_watcher_unwatch(srv->watcher, name);
4576 }

Callers 1

dispatch_toolFunction · 0.70

Calls 12

get_project_argFunction · 0.85
cbm_mcp_text_resultFunction · 0.85
cbm_store_closeFunction · 0.85
cbm_pipeline_lockFunction · 0.85
project_db_pathFunction · 0.85
cbm_unlinkFunction · 0.85
cbm_pipeline_unlockFunction · 0.85
cbm_watcher_unwatchFunction · 0.85
cbm_mem_collectFunction · 0.85
mcp_project_mutation_endFunction · 0.85
yy_doc_to_strFunction · 0.85

Tested by

no test coverage detected