| 6336 | } |
| 6337 | |
| 6338 | int cbm_remove_indexes(const char *home_dir) { |
| 6339 | const char *cache_dir = get_cache_dir(home_dir); |
| 6340 | if (!cache_dir) { |
| 6341 | return 0; |
| 6342 | } |
| 6343 | |
| 6344 | cbm_dir_t *d = cbm_opendir(cache_dir); |
| 6345 | if (!d) { |
| 6346 | return 0; |
| 6347 | } |
| 6348 | |
| 6349 | int count = 0; |
| 6350 | cbm_dirent_t *ent; |
| 6351 | while ((ent = cbm_readdir(d)) != NULL) { |
| 6352 | size_t len = strlen(ent->name); |
| 6353 | if (len > DB_EXT_LEN && strcmp(ent->name + len - DB_EXT_LEN, ".db") == 0) { |
| 6354 | char path[CLI_BUF_1K]; |
| 6355 | snprintf(path, sizeof(path), "%s/%s", cache_dir, ent->name); |
| 6356 | /* Also remove .db.tmp if present */ |
| 6357 | char tmp_path[CLI_FIELD_1040]; |
| 6358 | snprintf(tmp_path, sizeof(tmp_path), "%s.tmp", path); |
| 6359 | cbm_unlink(tmp_path); |
| 6360 | if (cbm_unlink(path) == 0) { |
| 6361 | count++; |
| 6362 | } |
| 6363 | } |
| 6364 | } |
| 6365 | cbm_closedir(d); |
| 6366 | return count; |
| 6367 | } |
| 6368 | |
| 6369 | /* ── Config store (persistent key-value in _config.db) ─────────── */ |
| 6370 |
no test coverage detected