Count .db files in the cache directory. */
| 3565 | |
| 3566 | /* Count .db files in the cache directory. */ |
| 3567 | static int count_db_indexes(const char *home) { |
| 3568 | const char *cache_dir = get_cache_dir(home); |
| 3569 | if (!cache_dir) { |
| 3570 | return 0; |
| 3571 | } |
| 3572 | cbm_dir_t *d = cbm_opendir(cache_dir); |
| 3573 | if (!d) { |
| 3574 | return 0; |
| 3575 | } |
| 3576 | int count = 0; |
| 3577 | cbm_dirent_t *ent; |
| 3578 | while ((ent = cbm_readdir(d)) != NULL) { |
| 3579 | size_t len = strlen(ent->name); |
| 3580 | if (len > DB_EXT_LEN && strcmp(ent->name + len - DB_EXT_LEN, ".db") == 0) { |
| 3581 | count++; |
| 3582 | } |
| 3583 | } |
| 3584 | cbm_closedir(d); |
| 3585 | return count; |
| 3586 | } |
| 3587 | |
| 3588 | /* Handle pre-existing indexes during (re)install (#607). |
| 3589 | * |
no test coverage detected