Count .db files in the cache directory. */
| 9406 | |
| 9407 | /* Count .db files in the cache directory. */ |
| 9408 | static int count_db_indexes(const char *home) { |
| 9409 | const char *cache_dir = get_cache_dir(home); |
| 9410 | if (!cache_dir) { |
| 9411 | return 0; |
| 9412 | } |
| 9413 | cbm_dir_t *d = cbm_opendir(cache_dir); |
| 9414 | if (!d) { |
| 9415 | return 0; |
| 9416 | } |
| 9417 | int count = 0; |
| 9418 | cbm_dirent_t *ent; |
| 9419 | while ((ent = cbm_readdir(d)) != NULL) { |
| 9420 | size_t len = strlen(ent->name); |
| 9421 | if (len > DB_EXT_LEN && strcmp(ent->name + len - DB_EXT_LEN, ".db") == 0) { |
| 9422 | count++; |
| 9423 | } |
| 9424 | } |
| 9425 | cbm_closedir(d); |
| 9426 | return count; |
| 9427 | } |
| 9428 | |
| 9429 | /* Handle pre-existing indexes during (re)install (#607). |
| 9430 | * |
no test coverage detected