| 256 | } |
| 257 | |
| 258 | static bool mcp_search_cache_open(mcp_search_cache_t *cache, const char *prefix) { |
| 259 | memset(cache, 0, sizeof(*cache)); |
| 260 | snprintf(cache->path, sizeof(cache->path), "%s/%s-XXXXXX", cbm_tmpdir(), prefix); |
| 261 | if (!cbm_mkdtemp(cache->path)) { |
| 262 | return false; |
| 263 | } |
| 264 | const char *saved_cache = getenv("CBM_CACHE_DIR"); |
| 265 | cache->saved_cache = saved_cache ? strdup(saved_cache) : NULL; |
| 266 | if ((saved_cache && !cache->saved_cache) || cbm_setenv("CBM_CACHE_DIR", cache->path, 1) != 0) { |
| 267 | free(cache->saved_cache); |
| 268 | cache->saved_cache = NULL; |
| 269 | (void)th_rmtree(cache->path); |
| 270 | return false; |
| 271 | } |
| 272 | return true; |
| 273 | } |
| 274 | |
| 275 | static bool mcp_search_cache_close(mcp_search_cache_t *cache) { |
| 276 | restore_cache_dir(cache->saved_cache); |
no test coverage detected