diff --git a/indra/llfilesystem/lldiskcache.cpp b/indra/llfilesystem/lldiskcache.cpp index 9fca8b3a35b9baea2ab25f00387426fd9a7dea65..baf02cc34309dfd75b23fb3bdf4f4ed1bc6f40f8 100644 --- a/indra/llfilesystem/lldiskcache.cpp +++ b/indra/llfilesystem/lldiskcache.cpp @@ -39,25 +39,27 @@ #include "lldiskcache.h" +std::string LLDiskCache::sCacheDir = ""; +std::string LLDiskCache::sCacheFilenameExt = ".sl_cache"; + LLDiskCache::LLDiskCache(const std::string cache_dir, const int max_size_bytes, const bool enable_cache_debug_info) : - mCacheDir(cache_dir), mMaxSizeBytes(max_size_bytes), mEnableCacheDebugInfo(enable_cache_debug_info) { - mCacheFilenameExt = ".sl_cache"; + sCacheDir = cache_dir; createCache(); } void LLDiskCache::createCache() { - LLFile::mkdir(mCacheDir); + LLFile::mkdir(sCacheDir); std::vector<std::string> uuidprefix = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" }; for (auto& prefixchar : uuidprefix) { - LLFile::mkdir(absl::StrCat(mCacheDir, gDirUtilp->getDirDelimiter(), prefixchar)); + LLFile::mkdir(absl::StrCat(sCacheDir, gDirUtilp->getDirDelimiter(), prefixchar)); } } @@ -65,7 +67,7 @@ void LLDiskCache::purge() { if (mEnableCacheDebugInfo) { - LL_INFOS() << "Total dir size before purge is " << dirFileSize(mCacheDir) << LL_ENDL; + LL_INFOS() << "Total dir size before purge is " << dirFileSize(sCacheDir) << LL_ENDL; } auto start_time = std::chrono::high_resolution_clock::now(); @@ -74,7 +76,7 @@ void LLDiskCache::purge() std::vector<file_info_t> file_info; #if LL_WINDOWS - std::wstring cache_path(ll_convert_string_to_wide(mCacheDir)); + std::wstring cache_path(ll_convert_string_to_wide(sCacheDir)); #else std::string cache_path(mCacheDir); #endif @@ -84,7 +86,7 @@ void LLDiskCache::purge() { if (boost::filesystem::is_regular_file(entry)) { - if (entry.path().string().rfind(mCacheFilenameExt) != std::string::npos) + if (entry.path().string().rfind(sCacheFilenameExt) != std::string::npos) { uintmax_t file_size = boost::filesystem::file_size(entry); const std::string file_path = entry.path().string(); @@ -137,7 +139,7 @@ void LLDiskCache::purge() { auto end_time = std::chrono::high_resolution_clock::now(); auto execute_time = std::chrono::duration_cast<std::chrono::milliseconds>(end_time - start_time).count(); - LL_INFOS() << "Total dir size after purge is " << dirFileSize(mCacheDir) << LL_ENDL; + LL_INFOS() << "Total dir size after purge is " << dirFileSize(sCacheDir) << LL_ENDL; LL_INFOS() << "Cache purge took " << execute_time << " ms to execute for " << file_info.size() << " files" << LL_ENDL; } } @@ -189,18 +191,19 @@ const std::string LLDiskCache::assetTypeToString(LLAssetType::EType at) return std::string("UNKNOWN"); } +// static const std::string LLDiskCache::metaDataToFilepath(const LLUUID& id, LLAssetType::EType at) { std::string uuidstr = id.asString(); const auto& dirdelim = gDirUtilp->getDirDelimiter(); - return absl::StrCat(mCacheDir, dirdelim, absl::string_view(&uuidstr[0], 1), dirdelim, uuidstr, mCacheFilenameExt); + return absl::StrCat(sCacheDir, dirdelim, absl::string_view(&uuidstr[0], 1), dirdelim, uuidstr, sCacheFilenameExt); } const std::string LLDiskCache::getCacheInfo() { F32 max_in_mb = (F32)mMaxSizeBytes / (1024.0 * 1024.0); - F32 percent_used = ((F32)dirFileSize(mCacheDir) / (F32)mMaxSizeBytes) * 100.0; + F32 percent_used = ((F32)dirFileSize(sCacheDir) / (F32)mMaxSizeBytes) * 100.0; return llformat("Max size %1.f MB (%.1f %% used)", max_in_mb, percent_used); } @@ -214,7 +217,7 @@ void LLDiskCache::clearCache() * likely just fine */ #if LL_WINDOWS - boost::filesystem::path cache_path(ll_convert_string_to_wide(mCacheDir)); + boost::filesystem::path cache_path(ll_convert_string_to_wide(sCacheDir)); #else boost::filesystem::path cache_path(mCacheDir); #endif @@ -250,7 +253,7 @@ uintmax_t LLDiskCache::dirFileSize(const std::string dir) { if (boost::filesystem::is_regular_file(entry)) { - if (entry.path().string().rfind(mCacheFilenameExt) != std::string::npos) + if (entry.path().string().rfind(sCacheFilenameExt) != std::string::npos) { total_file_size += boost::filesystem::file_size(entry); } diff --git a/indra/llfilesystem/lldiskcache.h b/indra/llfilesystem/lldiskcache.h index 13137efbcc618599c1e5ac88f39cd95419b13f00..4ebc3366721e56a961d3fc439b5d7bfe517cefcb 100644 --- a/indra/llfilesystem/lldiskcache.h +++ b/indra/llfilesystem/lldiskcache.h @@ -104,7 +104,7 @@ class LLDiskCache : * so many things had to be pushed back there to accomodate it, that I * decided to move it here. Still not sure that's completely right. */ - const std::string metaDataToFilepath(const LLUUID& id, + static const std::string metaDataToFilepath(const LLUUID& id, LLAssetType::EType at); /** @@ -159,7 +159,7 @@ class LLDiskCache : * setting could potentially point it at a non-cache directory (for example, * the Windows System dir) with disastrous results. */ - std::string mCacheDir; + static std::string sCacheDir; /** * The extension inserted at the end of a cache file filename to @@ -169,7 +169,7 @@ class LLDiskCache : * like the users' OS system dir by mistake or maliciously and * this will help to offset any damage if that happens. */ - std::string mCacheFilenameExt; + static std::string sCacheFilenameExt; /** * When enabled, displays additional debugging information in diff --git a/indra/llfilesystem/llfilesystem.cpp b/indra/llfilesystem/llfilesystem.cpp index 1c4dd05af693a7ccf68e79903ea5e79a5da2d826..25b335fc1b6090cc7076e4fca2811dde88cc3285 100644 --- a/indra/llfilesystem/llfilesystem.cpp +++ b/indra/llfilesystem/llfilesystem.cpp @@ -50,7 +50,7 @@ LLFileSystem::LLFileSystem(const LLUUID& file_id, const LLAssetType::EType file_ // static bool LLFileSystem::getExists(const LLUUID& file_id, const LLAssetType::EType file_type) { - const std::string filename = LLDiskCache::getInstance()->metaDataToFilepath(file_id, file_type); + const std::string filename = LLDiskCache::metaDataToFilepath(file_id, file_type); llstat stat; if (LLFile::stat(filename, &stat) == 0) @@ -63,7 +63,7 @@ bool LLFileSystem::getExists(const LLUUID& file_id, const LLAssetType::EType fil // static bool LLFileSystem::removeFile(const LLUUID& file_id, const LLAssetType::EType file_type) { - const std::string filename = LLDiskCache::getInstance()->metaDataToFilepath(file_id, file_type); + const std::string filename = LLDiskCache::metaDataToFilepath(file_id, file_type); LLFile::remove(filename, ENOENT); @@ -74,8 +74,8 @@ bool LLFileSystem::removeFile(const LLUUID& file_id, const LLAssetType::EType fi bool LLFileSystem::renameFile(const LLUUID& old_file_id, const LLAssetType::EType old_file_type, const LLUUID& new_file_id, const LLAssetType::EType new_file_type) { - const std::string old_filename = LLDiskCache::getInstance()->metaDataToFilepath(old_file_id, old_file_type); - const std::string new_filename = LLDiskCache::getInstance()->metaDataToFilepath(new_file_id, new_file_type); + const std::string old_filename = LLDiskCache::metaDataToFilepath(old_file_id, old_file_type); + const std::string new_filename = LLDiskCache::metaDataToFilepath(new_file_id, new_file_type); // Rename needs the new file to not exist. LLFile::remove(new_filename, ENOENT); @@ -95,7 +95,7 @@ bool LLFileSystem::renameFile(const LLUUID& old_file_id, const LLAssetType::ETyp // static S32 LLFileSystem::getFileSize(const LLUUID& file_id, const LLAssetType::EType file_type) { - const std::string filename = LLDiskCache::getInstance()->metaDataToFilepath(file_id, file_type); + const std::string filename = LLDiskCache::metaDataToFilepath(file_id, file_type); S32 file_size = 0; llstat stat; @@ -111,7 +111,7 @@ BOOL LLFileSystem::read(U8* buffer, S32 bytes) { BOOL success = TRUE; - const std::string filename = LLDiskCache::getInstance()->metaDataToFilepath(mFileID, mFileType); + const std::string filename = LLDiskCache::metaDataToFilepath(mFileID, mFileType); LLUniqueFile filep = LLFile::fopen(filename, "rb"); if (filep) @@ -175,7 +175,7 @@ BOOL LLFileSystem::eof() BOOL LLFileSystem::write(const U8* buffer, S32 bytes) { - const std::string filename = LLDiskCache::getInstance()->metaDataToFilepath(mFileID, mFileType); + const std::string filename = LLDiskCache::metaDataToFilepath(mFileID, mFileType); BOOL success = FALSE;