delete_project: just erase the .db file (and WAL/SHM). */
| 6785 | |
| 6786 | /* delete_project: just erase the .db file (and WAL/SHM). */ |
| 6787 | static char *handle_delete_project(cbm_mcp_server_t *srv, const char *args) { |
| 6788 | char *name = get_project_arg(args); |
| 6789 | if (!name) { |
| 6790 | return cbm_mcp_text_result("project is required", true); |
| 6791 | } |
| 6792 | if (!mcp_project_mutation_begin(srv, name)) { |
| 6793 | free(name); |
| 6794 | return cbm_mcp_text_result("project operation cancelled or blocked by an active index", |
| 6795 | true); |
| 6796 | } |
| 6797 | |
| 6798 | /* Close store if it's the project being deleted */ |
| 6799 | if (srv->current_project && strcmp(srv->current_project, name) == 0) { |
| 6800 | if (srv->owns_store && srv->store) { |
| 6801 | cbm_store_close(srv->store); |
| 6802 | srv->store = NULL; |
| 6803 | } |
| 6804 | free(srv->current_project); |
| 6805 | srv->current_project = NULL; |
| 6806 | } |
| 6807 | |
| 6808 | /* Wait for any in-progress pipeline to finish before deleting */ |
| 6809 | cbm_pipeline_lock(); |
| 6810 | |
| 6811 | /* Delete the .db file + WAL/SHM */ |
| 6812 | char path[CBM_SZ_1K]; |
| 6813 | project_db_path(name, path, sizeof(path)); |
| 6814 | |
| 6815 | char wal[CBM_SZ_1K]; |
| 6816 | char shm[CBM_SZ_1K]; |
| 6817 | snprintf(wal, sizeof(wal), "%s-wal", path); |
| 6818 | snprintf(shm, sizeof(shm), "%s-shm", path); |
| 6819 | |
| 6820 | bool exists = (access(path, F_OK) == 0); |
| 6821 | const char *status = "not_found"; |
| 6822 | const char *error_detail = NULL; |
| 6823 | bool is_error = false; |
| 6824 | |
| 6825 | if (exists) { |
| 6826 | int rc = cbm_unlink(path); |
| 6827 | (void)cbm_unlink(wal); |
| 6828 | (void)cbm_unlink(shm); |
| 6829 | if (rc == 0) { |
| 6830 | status = "deleted"; |
| 6831 | } else { |
| 6832 | status = "delete_failed"; |
| 6833 | error_detail = strerror(errno); |
| 6834 | is_error = true; |
| 6835 | } |
| 6836 | } else { |
| 6837 | is_error = true; |
| 6838 | } |
| 6839 | |
| 6840 | cbm_pipeline_unlock(); |
| 6841 | |
| 6842 | if (srv->watcher) { |
| 6843 | cbm_watcher_unwatch(srv->watcher, name); |
| 6844 | } |
no test coverage detected