DELETE /api/project?name=X — deletes the .db file */
| 1845 | |
| 1846 | /* DELETE /api/project?name=X — deletes the .db file */ |
| 1847 | static void handle_delete_project(cbm_http_server_t *srv, cbm_http_conn_t *c, |
| 1848 | const cbm_http_req_t *req) { |
| 1849 | char name[256] = {0}; |
| 1850 | if (!cbm_http_query_param(req->query, "name", name, (int)sizeof(name)) || name[0] == '\0') { |
| 1851 | cbm_http_replyf(c, 400, g_cors_json, "{\"error\":\"missing name\"}"); |
| 1852 | return; |
| 1853 | } |
| 1854 | |
| 1855 | char db_path[1024]; |
| 1856 | db_path_for_project(name, db_path, sizeof(db_path)); |
| 1857 | if (db_path[0] == '\0') { |
| 1858 | cbm_http_replyf(c, 404, g_cors_json, "{\"error\":\"project not found\"}"); |
| 1859 | return; |
| 1860 | } |
| 1861 | |
| 1862 | if (srv->mutation_begin && !srv->mutation_begin(srv->mutation_context, name)) { |
| 1863 | cbm_http_replyf(c, 423, g_cors_json, |
| 1864 | "{\"error\":\"project is busy; retry after indexing\"}"); |
| 1865 | return; |
| 1866 | } |
| 1867 | bool mutation_held = srv->mutation_begin != NULL; |
| 1868 | |
| 1869 | if (unlink(db_path) != 0) { |
| 1870 | if (errno == ENOENT) { |
| 1871 | unwatch_project(srv, name); |
| 1872 | if (mutation_held) { |
| 1873 | srv->mutation_end(srv->mutation_context, name); |
| 1874 | } |
| 1875 | cbm_http_replyf(c, 404, g_cors_json, "{\"error\":\"project not found\"}"); |
| 1876 | return; |
| 1877 | } |
| 1878 | if (mutation_held) { |
| 1879 | srv->mutation_end(srv->mutation_context, name); |
| 1880 | } |
| 1881 | cbm_http_replyf(c, 500, g_cors_json, "{\"error\":\"failed to delete\"}"); |
| 1882 | return; |
| 1883 | } |
| 1884 | |
| 1885 | /* Also remove WAL and SHM files if they exist */ |
| 1886 | char wal_path[1040], shm_path[1040]; |
| 1887 | snprintf(wal_path, sizeof(wal_path), "%s-wal", db_path); |
| 1888 | snprintf(shm_path, sizeof(shm_path), "%s-shm", db_path); |
| 1889 | (void)unlink(wal_path); |
| 1890 | (void)unlink(shm_path); |
| 1891 | |
| 1892 | unwatch_project(srv, name); |
| 1893 | cbm_log_info("ui.project.deleted", "name", name); |
| 1894 | if (mutation_held) { |
| 1895 | srv->mutation_end(srv->mutation_context, name); |
| 1896 | } |
| 1897 | cbm_http_replyf(c, 200, g_cors_json, "{\"deleted\":true}"); |
| 1898 | } |
| 1899 | |
| 1900 | /* GET /api/project-health?name=X — database and live watcher state */ |
| 1901 | static void handle_project_health(cbm_http_conn_t *c, const cbm_http_req_t *req, |
no test coverage detected