diff options
Diffstat (limited to 'indra/llfilesystem/lldiskcache.cpp')
| -rw-r--r-- | indra/llfilesystem/lldiskcache.cpp | 165 |
1 files changed, 68 insertions, 97 deletions
diff --git a/indra/llfilesystem/lldiskcache.cpp b/indra/llfilesystem/lldiskcache.cpp index 82e9e18918..5af801a1df 100644 --- a/indra/llfilesystem/lldiskcache.cpp +++ b/indra/llfilesystem/lldiskcache.cpp @@ -34,8 +34,9 @@ #include "llapp.h" #include "llassettype.h" #include "lldir.h" -#include <boost/filesystem.hpp> +#include "llstring.h" #include <chrono> +#include <filesystem> #include "lldiskcache.h" @@ -64,10 +65,10 @@ LLDiskCache::LLDiskCache(const std::string& cache_dir, // WARNING: purge() is called by LLPurgeDiskCacheThread. As such it must // NOT touch any LLDiskCache data without introducing and locking a mutex! -// Interaction through the filesystem itself should be safe. Let’s say thread +// Interaction through the filesystem itself should be safe. Let's say thread // A is accessing the cache file for reading/writing and thread B is trimming -// the cache. Let’s also assume using llifstream to open a file and -// boost::filesystem::remove are not atomic (which will be pretty much the +// the cache. Let's also assume using llifstream to open a file and +// std::filesystem::remove are not atomic (which will be pretty much the // case). // Now, A is trying to open the file using llifstream ctor. It does some @@ -83,7 +84,7 @@ LLDiskCache::LLDiskCache(const std::string& cache_dir, // garbage.) // Other situation: B is trimming the cache and A wants to read a file that is -// about to get deleted. boost::filesystem::remove does whatever it is doing +// about to get deleted. std::filesystem::remove does whatever it is doing // before actually deleting the file. If A opens the file before the file is // actually gone, the OS call from B to delete the file will fail since the OS // will prevent this. B continues with the next file. If the file is already @@ -91,47 +92,41 @@ LLDiskCache::LLDiskCache(const std::string& cache_dir, // asset will have to be re-requested. void LLDiskCache::purge() { + LL_PROFILE_ZONE_SCOPED; + if (mEnableCacheDebugInfo) { LL_INFOS() << "Total dir size before purge is " << dirFileSize(sCacheDir) << LL_ENDL; } - boost::system::error_code ec; + std::error_code ec; auto start_time = std::chrono::high_resolution_clock::now(); - typedef std::pair<std::time_t, std::pair<uintmax_t, std::string>> file_info_t; + typedef std::pair<std::filesystem::file_time_type, std::pair<uintmax_t, std::string>> file_info_t; std::vector<file_info_t> file_info; -#if LL_WINDOWS - std::wstring cache_path(ll_convert<std::wstring>(sCacheDir)); -#else - std::string cache_path(sCacheDir); -#endif - if (boost::filesystem::is_directory(cache_path, ec) && !ec.failed()) + std::filesystem::path cache_path = fsyspath(sCacheDir); + if (std::filesystem::is_directory(cache_path, ec) && !ec) { - boost::filesystem::directory_iterator iter(cache_path, ec); - while (iter != boost::filesystem::directory_iterator() && !ec.failed()) + std::filesystem::directory_iterator iter(cache_path, ec); + while (iter != std::filesystem::directory_iterator() && !ec) { - if (boost::filesystem::is_regular_file(*iter, ec) && !ec.failed()) + if(!LLApp::isRunning()) + { + return; + } + if (std::filesystem::is_regular_file(*iter, ec) && !ec) { -#if LL_WINDOWS - if (utf16str_to_utf8str((*iter).path().wstring()).find(CACHE_FILENAME_PREFIX) != std::string::npos) -#else - if ((*iter).path().string().find(CACHE_FILENAME_PREFIX) != std::string::npos) -#endif + if (fsyspath((*iter).path()).string().find(CACHE_FILENAME_PREFIX) != std::string::npos) { - uintmax_t file_size = boost::filesystem::file_size(*iter, ec); - if (ec.failed()) + uintmax_t file_size = std::filesystem::file_size(*iter, ec); + if (ec) { continue; } -#if LL_WINDOWS - const std::string file_path = utf16str_to_utf8str((*iter).path().wstring()); -#else - const std::string file_path = (*iter).path().string(); -#endif - const std::time_t file_time = boost::filesystem::last_write_time(*iter, ec); - if (ec.failed()) + const std::string file_path = fsyspath((*iter).path()).string(); + const std::filesystem::file_time_type file_time = std::filesystem::last_write_time(*iter, ec); + if (ec) { continue; } @@ -158,6 +153,10 @@ void LLDiskCache::purge() uintmax_t file_size_total = 0; for (file_info_t& entry : file_info) { + if (!LLApp::isRunning()) + { + return; + } file_size_total += entry.second.first; bool should_remove = file_size_total > mMaxSizeBytes; @@ -167,16 +166,10 @@ void LLDiskCache::purge() } if (should_remove) { -#if LL_WINDOWS - boost::filesystem::remove(utf8str_to_utf16str(entry.second.second), ec); -#else - boost::filesystem::remove(entry.second.second, ec); -#endif - if (ec.failed()) + std::filesystem::remove(fsyspath(entry.second.second), ec); + if (ec) { -#if !LL_WINDOWS LL_WARNS() << "Failed to delete cache file " << entry.second.second << ": " << ec.message() << LL_ENDL; -#endif } } } @@ -190,6 +183,10 @@ void LLDiskCache::purge() // Logging thousands of file results can take hundreds of milliseconds for (size_t i = 0; i < file_info.size(); ++i) { + if (!LLApp::isRunning()) + { + return; + } const file_info_t& entry = file_info[i]; const bool removed = file_removed[i]; const std::string action = removed ? "DELETE:" : "KEEP:"; @@ -198,7 +195,7 @@ void LLDiskCache::purge() std::ostringstream line; line << action << " "; - line << entry.first << " "; + line << S64(entry.first.time_since_epoch().count()) << " "; line << entry.second.first << " "; line << entry.second.second; line << " (" << file_size_total << "/" << mMaxSizeBytes << ")"; @@ -212,7 +209,9 @@ void LLDiskCache::purge() const std::string LLDiskCache::metaDataToFilepath(const LLUUID& id, LLAssetType::EType at) { - return llformat("%s%s%s_%s_0.asset", sCacheDir.c_str(), gDirUtilp->getDirDelimiter().c_str(), CACHE_FILENAME_PREFIX.c_str(), id.asString().c_str()); + char uuid_str[UUID_STR_LENGTH]{}; + id.to_chars(uuid_str); + return llformat("%s%s%s_%s_0.asset", sCacheDir.c_str(), gDirUtilp->getDirDelimiter().c_str(), CACHE_FILENAME_PREFIX.c_str(), uuid_str); } const std::string LLDiskCache::getCacheInfo() @@ -238,31 +237,21 @@ void LLDiskCache::clearCache() * the component files but it's called infrequently so it's * likely just fine */ - boost::system::error_code ec; -#if LL_WINDOWS - std::wstring cache_path(ll_convert<std::wstring>(sCacheDir)); -#else - std::string cache_path(sCacheDir); -#endif - if (boost::filesystem::is_directory(cache_path, ec) && !ec.failed()) + std::error_code ec; + std::filesystem::path cache_path = fsyspath(sCacheDir); + if (std::filesystem::is_directory(cache_path, ec) && !ec) { - boost::filesystem::directory_iterator iter(cache_path, ec); - while (iter != boost::filesystem::directory_iterator() && !ec.failed()) + std::filesystem::directory_iterator iter(cache_path, ec); + while (iter != std::filesystem::directory_iterator() && !ec) { - if (boost::filesystem::is_regular_file(*iter, ec) && !ec.failed()) + if (std::filesystem::is_regular_file(*iter, ec) && !ec) { -#if LL_WINDOWS - if (utf16str_to_utf8str((*iter).path().wstring()).find(CACHE_FILENAME_PREFIX) != std::string::npos) -#else - if ((*iter).path().string().find(CACHE_FILENAME_PREFIX) != std::string::npos) -#endif + if (fsyspath((*iter).path()).string().find(CACHE_FILENAME_PREFIX) != std::string::npos) { - boost::filesystem::remove(*iter, ec); - if (ec.failed()) + std::filesystem::remove(*iter, ec); + if (ec) { -#if !LL_WINDOWS LL_WARNS() << "Failed to delete cache file " << *iter << ": " << ec.message() << LL_ENDL; -#endif } } } @@ -277,33 +266,23 @@ void LLDiskCache::removeOldVFSFiles() 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(ll_convert<std::wstring>(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()) + std::error_code ec; + std::filesystem::path cache_path = fsyspath(gDirUtilp->getExpandedFilename(LL_PATH_CACHE, "")); + if (std::filesystem::is_directory(cache_path, ec) && !ec) { - boost::filesystem::directory_iterator iter(cache_path, ec); - while (iter != boost::filesystem::directory_iterator() && !ec.failed()) + std::filesystem::directory_iterator iter(cache_path, ec); + while (iter != std::filesystem::directory_iterator() && !ec) { - if (boost::filesystem::is_regular_file(*iter, ec) && !ec.failed()) + if (std::filesystem::is_regular_file(*iter, ec) && !ec) { -#if LL_WINDOWS - if ((utf16str_to_utf8str((*iter).path().wstring()).find(CACHE_FORMAT) != std::string::npos) || - (utf16str_to_utf8str((*iter).path().wstring()).find(DB_FORMAT) != std::string::npos)) -#else - if (((*iter).path().string().find(CACHE_FORMAT) != std::string::npos) || - ((*iter).path().string().find(DB_FORMAT) != std::string::npos)) -#endif + const std::string file_path = fsyspath((*iter).path()).string(); + if ((file_path.find(CACHE_FORMAT) != std::string::npos) || + (file_path.find(DB_FORMAT) != std::string::npos)) { - boost::filesystem::remove(*iter, ec); - if (ec.failed()) + std::filesystem::remove(*iter, ec); + if (ec) { -#if !LL_WINDOWS LL_WARNS() << "Failed to delete cache file " << *iter << ": " << ec.message() << LL_ENDL; -#endif } } } @@ -325,27 +304,19 @@ uintmax_t LLDiskCache::dirFileSize(const std::string& dir) * so if performance is ever an issue, optimizing this or removing it altogether, * is an easy win. */ - boost::system::error_code ec; -#if LL_WINDOWS - std::wstring dir_path(ll_convert<std::wstring>(dir)); -#else - std::string dir_path(dir); -#endif - if (boost::filesystem::is_directory(dir_path, ec) && !ec.failed()) + std::error_code ec; + std::filesystem::path dir_path = fsyspath(dir); + if (std::filesystem::is_directory(dir_path, ec) && !ec) { - boost::filesystem::directory_iterator iter(dir_path, ec); - while (iter != boost::filesystem::directory_iterator() && !ec.failed()) + std::filesystem::directory_iterator iter(dir_path, ec); + while (iter != std::filesystem::directory_iterator() && !ec) { - if (boost::filesystem::is_regular_file(*iter, ec) && !ec.failed()) + if (std::filesystem::is_regular_file(*iter, ec) && !ec) { -#if LL_WINDOWS - if (utf16str_to_utf8str((*iter).path().wstring()).find(CACHE_FILENAME_PREFIX) != std::string::npos) -#else - if ((*iter).path().string().find(CACHE_FILENAME_PREFIX) != std::string::npos) -#endif + if (fsyspath((*iter).path()).string().find(CACHE_FILENAME_PREFIX) != std::string::npos) { - uintmax_t file_size = boost::filesystem::file_size(*iter, ec); - if (!ec.failed()) + uintmax_t file_size = std::filesystem::file_size(*iter, ec); + if (!ec) { total_file_size += file_size; } |
