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

Function handle_delete_project

src/mcp/mcp.c:2178–2250  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

2176
2177/* delete_project: just erase the .db file (and WAL/SHM). */
2178static char *handle_delete_project(cbm_mcp_server_t *srv, const char *args) {
2179 char *name = get_project_arg(args);
2180 if (!name) {
2181 return cbm_mcp_text_result("project is required", true);
2182 }
2183
2184 /* Close store if it's the project being deleted */
2185 if (srv->current_project && strcmp(srv->current_project, name) == 0) {
2186 if (srv->owns_store && srv->store) {
2187 cbm_store_close(srv->store);
2188 srv->store = NULL;
2189 }
2190 free(srv->current_project);
2191 srv->current_project = NULL;
2192 }
2193
2194 /* Wait for any in-progress pipeline to finish before deleting */
2195 cbm_pipeline_lock();
2196
2197 /* Delete the .db file + WAL/SHM */
2198 char path[CBM_SZ_1K];
2199 project_db_path(name, path, sizeof(path));
2200
2201 char wal[CBM_SZ_1K];
2202 char shm[CBM_SZ_1K];
2203 snprintf(wal, sizeof(wal), "%s-wal", path);
2204 snprintf(shm, sizeof(shm), "%s-shm", path);
2205
2206 bool exists = (access(path, F_OK) == 0);
2207 const char *status = "not_found";
2208 const char *error_detail = NULL;
2209 bool is_error = false;
2210
2211 if (exists) {
2212 int rc = cbm_unlink(path);
2213 (void)cbm_unlink(wal);
2214 (void)cbm_unlink(shm);
2215 if (rc == 0) {
2216 status = "deleted";
2217 } else {
2218 status = "delete_failed";
2219 error_detail = strerror(errno);
2220 is_error = true;
2221 }
2222 } else {
2223 is_error = true;
2224 }
2225
2226 cbm_pipeline_unlock();
2227
2228 if (srv->watcher) {
2229 cbm_watcher_unwatch(srv->watcher, name);
2230 }
2231
2232 cbm_mem_collect(); /* return freed pages to OS after closing database */
2233
2234 yyjson_mut_doc *doc = yyjson_mut_doc_new(NULL);
2235 yyjson_mut_val *root = yyjson_mut_obj(doc);

Callers 1

cbm_mcp_handle_toolFunction · 0.70

Calls 10

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
yy_doc_to_strFunction · 0.85

Tested by

no test coverage detected