SL-15083 Remove old vfs files

master
Mnikolenko Productengine 2022-01-11 19:31:51 +02:00
parent c8f761fe93
commit c09155574d
3 changed files with 44 additions and 0 deletions

View File

@ -354,6 +354,38 @@ void LLDiskCache::clearCache()
}
}
void LLDiskCache::removeOldVFSFiles()
{
//VFS files won't be created, so consider removing this code later
static const char CACHE_FORMAT[] = "inv.llsd";
static const char DB_FORMAT[] = "db2.x";
boost::system::error_code ec;
#if LL_WINDOWS
std::wstring cache_path(utf8str_to_utf16str(gDirUtilp->getExpandedFilename(LL_PATH_CACHE, "")));
#else
std::string cache_path(gDirUtilp->getExpandedFilename(LL_PATH_CACHE, ""));
#endif
if (boost::filesystem::is_directory(cache_path, ec) && !ec.failed())
{
for (auto& entry : boost::make_iterator_range(boost::filesystem::directory_iterator(cache_path, ec), {}))
{
if (boost::filesystem::is_regular_file(entry, ec) && !ec.failed())
{
if ((entry.path().string().find(CACHE_FORMAT) != std::string::npos) ||
(entry.path().string().find(DB_FORMAT) != std::string::npos))
{
boost::filesystem::remove(entry, ec);
if (ec.failed())
{
LL_WARNS() << "Failed to delete cache file " << entry << ": " << ec.message() << LL_ENDL;
}
}
}
}
}
}
uintmax_t LLDiskCache::dirFileSize(const std::string dir)
{
uintmax_t total_file_size = 0;

View File

@ -140,6 +140,8 @@ class LLDiskCache :
*/
const std::string getCacheInfo();
void removeOldVFSFiles();
private:
/**
* Utility function to gather the total size the files in a given

View File

@ -4216,12 +4216,16 @@ bool LLAppViewer::initCache()
const bool enable_cache_debug_info = gSavedSettings.getBOOL("EnableDiskCacheDebugInfo");
bool texture_cache_mismatch = false;
bool remove_vfs_files = false;
if (gSavedSettings.getS32("LocalCacheVersion") != LLAppViewer::getTextureCacheVersion())
{
texture_cache_mismatch = true;
if(!read_only)
{
gSavedSettings.setS32("LocalCacheVersion", LLAppViewer::getTextureCacheVersion());
//texture cache version was bumped up in Simple Cache Viewer, and at this point old vfs files are not needed
remove_vfs_files = true;
}
}
@ -4270,8 +4274,14 @@ bool LLAppViewer::initCache()
if (gSavedSettings.getS32("DiskCacheVersion") != LLAppViewer::getDiskCacheVersion())
{
LLDiskCache::getInstance()->clearCache();
remove_vfs_files = true;
gSavedSettings.setS32("DiskCacheVersion", LLAppViewer::getDiskCacheVersion());
}
if (remove_vfs_files)
{
LLDiskCache::getInstance()->removeOldVFSFiles();
}
if (mPurgeCache)
{