Count .db files in the cache directory. */
| 8983 | |
| 8984 | /* Count .db files in the cache directory. */ |
| 8985 | static int count_db_indexes(const char *home) { |
| 8986 | const char *cache_dir = get_cache_dir(home); |
| 8987 | if (!cache_dir) { |
| 8988 | return 0; |
| 8989 | } |
| 8990 | cbm_dir_t *d = cbm_opendir(cache_dir); |
| 8991 | if (!d) { |
| 8992 | return 0; |
| 8993 | } |
| 8994 | int count = 0; |
| 8995 | cbm_dirent_t *ent; |
| 8996 | while ((ent = cbm_readdir(d)) != NULL) { |
| 8997 | size_t len = strlen(ent->name); |
| 8998 | if (len > DB_EXT_LEN && strcmp(ent->name + len - DB_EXT_LEN, ".db") == 0) { |
| 8999 | count++; |
| 9000 | } |
| 9001 | } |
| 9002 | cbm_closedir(d); |
| 9003 | return count; |
| 9004 | } |
| 9005 | |
| 9006 | /* Handle pre-existing indexes during (re)install (#607). |
| 9007 | * |
no test coverage detected