| 7349 | } |
| 7350 | |
| 7351 | int cbm_remove_indexes(const char *home_dir) { |
| 7352 | const char *cache_dir = get_cache_dir(home_dir); |
| 7353 | if (!cache_dir) { |
| 7354 | return 0; |
| 7355 | } |
| 7356 | |
| 7357 | cbm_dir_t *d = cbm_opendir(cache_dir); |
| 7358 | if (!d) { |
| 7359 | return 0; |
| 7360 | } |
| 7361 | |
| 7362 | int count = 0; |
| 7363 | cbm_dirent_t *ent; |
| 7364 | while ((ent = cbm_readdir(d)) != NULL) { |
| 7365 | if (cbm_is_project_index_db(ent->name)) { |
| 7366 | char path[CLI_BUF_1K]; |
| 7367 | snprintf(path, sizeof(path), "%s/%s", cache_dir, ent->name); |
| 7368 | /* Also remove .db.tmp if present */ |
| 7369 | char tmp_path[CLI_FIELD_1040]; |
| 7370 | snprintf(tmp_path, sizeof(tmp_path), "%s.tmp", path); |
| 7371 | cbm_unlink(tmp_path); |
| 7372 | if (cbm_unlink(path) == 0) { |
| 7373 | count++; |
| 7374 | } |
| 7375 | /* Remove the SQLite sidecars (-wal/-shm/-journal) for both the |
| 7376 | * live and staged DBs. Idempotent and ENOENT-tolerant, so it runs |
| 7377 | * even when the .db unlink failed -- an orphan -wal can outlive |
| 7378 | * its .db. Sidecars are not indexes, so count is unchanged. */ |
| 7379 | cbm_remove_db_sidecars(path); |
| 7380 | cbm_remove_db_sidecars(tmp_path); |
| 7381 | } |
| 7382 | } |
| 7383 | cbm_closedir(d); |
| 7384 | return count; |
| 7385 | } |
| 7386 | |
| 7387 | /* ── Config store (persistent key-value in _config.db) ─────────── */ |
| 7388 |
no test coverage detected