| 363 | } |
| 364 | |
| 365 | Result Flush(HCache cache) |
| 366 | { |
| 367 | dmMutex::ScopedLock lock(cache->m_Mutex); |
| 368 | if (!cache->m_Dirty) { |
| 369 | return RESULT_OK; |
| 370 | } |
| 371 | |
| 372 | cache->m_Dirty = false; |
| 373 | dmLogInfo("Flushing http cache to disk"); |
| 374 | |
| 375 | char cache_file[DMPATH_MAX_PATH]; |
| 376 | dmSnPrintf(cache_file, sizeof(cache_file), "%s/%s", cache->m_Path, "index"); |
| 377 | FILE* f = fopen(cache_file, "wb"); |
| 378 | if (f) { |
| 379 | Result r = WriteIndex(cache, f); |
| 380 | fclose(f); |
| 381 | if (r != RESULT_OK) { |
| 382 | dmLogError("Error writing to index file '%s'", cache_file); |
| 383 | dmSys::Unlink(cache_file); |
| 384 | return RESULT_IO_ERROR; |
| 385 | } |
| 386 | } else { |
| 387 | dmLogError("Unable to open index file '%s'", cache_file); |
| 388 | return RESULT_IO_ERROR; |
| 389 | } |
| 390 | |
| 391 | return RESULT_OK; |
| 392 | } |
| 393 | |
| 394 | Result Close(HCache cache) |
| 395 | { |
no test coverage detected