diff --git a/src/rendering/caches/DiskCache.cpp b/src/rendering/caches/DiskCache.cpp index 5d39f92bf9..f44e36efc4 100644 --- a/src/rendering/caches/DiskCache.cpp +++ b/src/rendering/caches/DiskCache.cpp @@ -73,7 +73,10 @@ DiskCache::DiskCache() { if (!cacheDir.empty()) { configPath = Directory::JoinPath(cacheDir, "cache.cfg"); cacheFolder = Directory::JoinPath(cacheDir, "files"); - readConfig(); + if (!readConfig()) { + Directory::VisitFiles(cacheFolder, + [&](const std::string& path, size_t) { remove(path.c_str()); }); + } } } @@ -268,16 +271,16 @@ void DiskCache::moveToBeforeOpenedFiles(std::shared_ptr fileInfo) { } } -void DiskCache::readConfig() { +bool DiskCache::readConfig() { auto file = fopen(configPath.c_str(), "rb"); if (file == nullptr) { - return; + return false; } fseek(file, 0, SEEK_END); auto size = ftell(file); if (size == 0) { fclose(file); - return; + return false; } fseek(file, 0, SEEK_SET); tgfx::Buffer buffer(size); @@ -321,6 +324,7 @@ void DiskCache::readConfig() { if (checkDiskSpace(maxDiskSize) || !expiredFiles.empty()) { saveConfig(); } + return true; } void DiskCache::saveConfig() { @@ -413,4 +417,5 @@ void DiskCache::notifyFileSizeChanged(uint32_t fileID, size_t fileSize) { } } } + } // namespace pag diff --git a/src/rendering/caches/DiskCache.h b/src/rendering/caches/DiskCache.h index b404378198..0e81c1939f 100644 --- a/src/rendering/caches/DiskCache.h +++ b/src/rendering/caches/DiskCache.h @@ -79,7 +79,7 @@ class DiskCache { void removeFromCachedFiles(std::shared_ptr fileInfo); void moveToFront(std::shared_ptr fileInfo); void moveToBeforeOpenedFiles(std::shared_ptr fileInfo); - void readConfig(); + bool readConfig(); void saveConfig(); uint32_t getFileID(const std::string& key); void changeToTemporary(uint32_t fileID);