| 217 | } |
| 218 | |
| 219 | static bool mcp_search_cache_open(mcp_search_cache_t *cache, const char *prefix) { |
| 220 | memset(cache, 0, sizeof(*cache)); |
| 221 | snprintf(cache->path, sizeof(cache->path), "%s/%s-XXXXXX", cbm_tmpdir(), prefix); |
| 222 | if (!cbm_mkdtemp(cache->path)) { |
| 223 | return false; |
| 224 | } |
| 225 | const char *saved_cache = getenv("CBM_CACHE_DIR"); |
| 226 | cache->saved_cache = saved_cache ? strdup(saved_cache) : NULL; |
| 227 | if ((saved_cache && !cache->saved_cache) || cbm_setenv("CBM_CACHE_DIR", cache->path, 1) != 0) { |
| 228 | free(cache->saved_cache); |
| 229 | cache->saved_cache = NULL; |
| 230 | (void)th_rmtree(cache->path); |
| 231 | return false; |
| 232 | } |
| 233 | return true; |
| 234 | } |
| 235 | |
| 236 | static bool mcp_search_cache_close(mcp_search_cache_t *cache) { |
| 237 | restore_cache_dir(cache->saved_cache); |
no test coverage detected