Count .db files in the cache directory. */
| 9033 | |
| 9034 | /* Count .db files in the cache directory. */ |
| 9035 | static int count_db_indexes(const char *home) { |
| 9036 | const char *cache_dir = get_cache_dir(home); |
| 9037 | if (!cache_dir) { |
| 9038 | return 0; |
| 9039 | } |
| 9040 | cbm_dir_t *d = cbm_opendir(cache_dir); |
| 9041 | if (!d) { |
| 9042 | return 0; |
| 9043 | } |
| 9044 | int count = 0; |
| 9045 | cbm_dirent_t *ent; |
| 9046 | while ((ent = cbm_readdir(d)) != NULL) { |
| 9047 | size_t len = strlen(ent->name); |
| 9048 | if (len > DB_EXT_LEN && strcmp(ent->name + len - DB_EXT_LEN, ".db") == 0) { |
| 9049 | count++; |
| 9050 | } |
| 9051 | } |
| 9052 | cbm_closedir(d); |
| 9053 | return count; |
| 9054 | } |
| 9055 | |
| 9056 | /* Handle pre-existing indexes during (re)install (#607). |
| 9057 | * |
no test coverage detected