diff options
Diffstat (limited to 'indra/llfilesystem')
| -rw-r--r-- | indra/llfilesystem/CMakeLists.txt | 11 | ||||
| -rw-r--r-- | indra/llfilesystem/lldir.cpp | 190 | ||||
| -rw-r--r-- | indra/llfilesystem/lldir.h | 5 | ||||
| -rw-r--r-- | indra/llfilesystem/lldir_linux.cpp | 18 | ||||
| -rw-r--r-- | indra/llfilesystem/lldir_linux.h | 1 | ||||
| -rw-r--r-- | indra/llfilesystem/lldir_mac.cpp | 26 | ||||
| -rw-r--r-- | indra/llfilesystem/lldir_mac.h | 1 | ||||
| -rw-r--r-- | indra/llfilesystem/lldir_utils_objc.mm | 28 | ||||
| -rw-r--r-- | indra/llfilesystem/lldir_win32.cpp | 34 | ||||
| -rw-r--r-- | indra/llfilesystem/lldir_win32.h | 3 | ||||
| -rw-r--r-- | indra/llfilesystem/lldirguard.h | 7 | ||||
| -rw-r--r-- | indra/llfilesystem/lldiriterator.cpp | 44 | ||||
| -rw-r--r-- | indra/llfilesystem/lldiskcache.cpp | 165 | ||||
| -rw-r--r-- | indra/llfilesystem/llfilesystem.cpp | 107 | ||||
| -rw-r--r-- | indra/llfilesystem/llfilesystem.h | 7 | ||||
| -rw-r--r-- | indra/llfilesystem/lllfsthread.cpp | 1 | ||||
| -rw-r--r-- | indra/llfilesystem/tests/lldir_test.cpp | 141 |
17 files changed, 340 insertions, 449 deletions
diff --git a/indra/llfilesystem/CMakeLists.txt b/indra/llfilesystem/CMakeLists.txt index 8d85f739b3..96dc472c4c 100644 --- a/indra/llfilesystem/CMakeLists.txt +++ b/indra/llfilesystem/CMakeLists.txt @@ -31,6 +31,12 @@ if (DARWIN) LIST(APPEND llfilesystem_SOURCE_FILES lldir_utils_objc.h) LIST(APPEND llfilesystem_SOURCE_FILES lldir_mac.cpp) LIST(APPEND llfilesystem_HEADER_FILES lldir_mac.h) + + set_source_files_properties( + lldir_utils_objc.mm + PROPERTIES + SKIP_PRECOMPILE_HEADERS TRUE + ) endif (DARWIN) if (LINUX OR CMAKE_SYSTEM_NAME MATCHES FreeBSD) @@ -55,11 +61,16 @@ list(APPEND llfilesystem_SOURCE_FILES ${llfilesystem_HEADER_FILES}) add_library (llfilesystem ${llfilesystem_SOURCE_FILES}) target_link_libraries(llfilesystem + llmath llcommon ) target_include_directories( llfilesystem INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) include(LibraryInstall) +if (USE_PRECOMPILED_HEADERS) + target_precompile_headers(llfilesystem REUSE_FROM llprecompiled) +endif () + # Add tests if (LL_TESTS) include(LLAddBuildTest) diff --git a/indra/llfilesystem/lldir.cpp b/indra/llfilesystem/lldir.cpp index d12080aafa..46a94277c5 100644 --- a/indra/llfilesystem/lldir.cpp +++ b/indra/llfilesystem/lldir.cpp @@ -30,8 +30,6 @@ #include <sys/stat.h> #include <sys/types.h> #include <errno.h> -#else -#include <direct.h> #endif #include "lldir.h" @@ -43,17 +41,10 @@ #include "lldiriterator.h" #include "stringize.h" #include "llstring.h" -#include <boost/filesystem.hpp> -#include <boost/range/begin.hpp> -#include <boost/range/end.hpp> -#include <boost/assign/list_of.hpp> +#include "llprocess.h" #include <boost/bind.hpp> -#include <boost/ref.hpp> #include <algorithm> -using boost::assign::list_of; -using boost::assign::map_list_of; - #if LL_WINDOWS #include "lldir_win32.h" LLDir_Win32 gDirUtil; @@ -100,35 +91,36 @@ LLDir::~LLDir() std::vector<std::string> LLDir::getFilesInDir(const std::string &dirname) { - //Returns a vector of fullpath filenames. - -#ifdef LL_WINDOWS // or BOOST_WINDOWS_API - boost::filesystem::path p(utf8str_to_utf16str(dirname)); -#else - boost::filesystem::path p(dirname); -#endif - + // Returns a vector of filenames in the directory. + fsyspath dir_path(dirname); std::vector<std::string> v; - - if (exists(p)) + std::error_code ec; + if (std::filesystem::is_directory(dir_path, ec)) { - if (is_directory(p)) + std::filesystem::directory_iterator end_iter; + try { - boost::filesystem::directory_iterator end_iter; - for (boost::filesystem::directory_iterator dir_itr(p); + for (std::filesystem::directory_iterator dir_itr(dir_path); dir_itr != end_iter; ++dir_itr) { - if (boost::filesystem::is_regular_file(dir_itr->status())) + try { -#if LL_WINDOWS - v.push_back(utf16str_to_utf8str(dir_itr->path().filename().wstring())); -#else - v.push_back(dir_itr->path().filename().string()); -#endif + if (std::filesystem::is_regular_file(dir_itr->status())) + { + v.push_back(fsyspath(dir_itr->path().filename()).string()); + } + } + catch (const std::system_error& e) + { + LL_WARNS() << "Exception accessing directory entry: " << e.what() << LL_ENDL; } } } + catch (const std::system_error& e) + { + LL_WARNS() << "Exception iterating directory: " << e.what() << LL_ENDL; + } } return v; } @@ -199,31 +191,31 @@ U32 LLDir::deleteDirAndContents(const std::string& dir_name) try { -#ifdef LL_WINDOWS // or BOOST_WINDOWS_API - boost::filesystem::path dir_path(utf8str_to_utf16str(dir_name)); -#else - boost::filesystem::path dir_path(dir_name); -#endif - - if (boost::filesystem::exists(dir_path)) + fsyspath dir_path(dir_name); + if (std::filesystem::is_directory(dir_path)) { - if (!boost::filesystem::is_empty(dir_path)) + if (!std::filesystem::is_empty(dir_path)) { // Directory has content - num_deleted = (U32)boost::filesystem::remove_all(dir_path); + num_deleted = (U32)std::filesystem::remove_all(dir_path); } else { // Directory is empty - boost::filesystem::remove(dir_path); + std::filesystem::remove(dir_path); } } } - catch (boost::filesystem::filesystem_error &er) + catch (std::filesystem::filesystem_error &er) { LL_WARNS() << "Failed to delete " << dir_name << " with error " << er.code().message() << LL_ENDL; } return num_deleted; } +bool LLDir::fileExists(const std::string& filename) const +{ + return LLFile::exists(filename); +} + const std::string LLDir::findFile(const std::string &filename, const std::string& searchPath1, const std::string& searchPath2, @@ -451,28 +443,28 @@ const std::string &LLDir::getUserName() const static std::string ELLPathToString(ELLPath location) { typedef std::map<ELLPath, const char*> ELLPathMap; -#define ENT(symbol) (symbol, #symbol) - static const ELLPathMap sMap = map_list_of - ENT(LL_PATH_NONE) - ENT(LL_PATH_USER_SETTINGS) - ENT(LL_PATH_APP_SETTINGS) - ENT(LL_PATH_PER_SL_ACCOUNT) // returns/expands to blank string if we don't know the account name yet - ENT(LL_PATH_CACHE) - ENT(LL_PATH_CHARACTER) - ENT(LL_PATH_HELP) - ENT(LL_PATH_LOGS) - ENT(LL_PATH_TEMP) - ENT(LL_PATH_SKINS) - ENT(LL_PATH_TOP_SKIN) - ENT(LL_PATH_CHAT_LOGS) - ENT(LL_PATH_PER_ACCOUNT_CHAT_LOGS) - ENT(LL_PATH_USER_SKIN) - ENT(LL_PATH_LOCAL_ASSETS) - ENT(LL_PATH_EXECUTABLE) - ENT(LL_PATH_DEFAULT_SKIN) - ENT(LL_PATH_FONTS) - ENT(LL_PATH_LAST) - ; +#define ENT(symbol) { symbol, #symbol } + static const ELLPathMap sMap = { + ENT(LL_PATH_NONE), + ENT(LL_PATH_USER_SETTINGS), + ENT(LL_PATH_APP_SETTINGS), + ENT(LL_PATH_PER_SL_ACCOUNT), // returns/expands to blank string if we don't know the account name yet + ENT(LL_PATH_CACHE), + ENT(LL_PATH_CHARACTER), + ENT(LL_PATH_HELP), + ENT(LL_PATH_LOGS), + ENT(LL_PATH_TEMP), + ENT(LL_PATH_SKINS), + ENT(LL_PATH_TOP_SKIN), + ENT(LL_PATH_CHAT_LOGS), + ENT(LL_PATH_PER_ACCOUNT_CHAT_LOGS), + ENT(LL_PATH_USER_SKIN), + ENT(LL_PATH_LOCAL_ASSETS), + ENT(LL_PATH_EXECUTABLE), + ENT(LL_PATH_DEFAULT_SKIN), + ENT(LL_PATH_FONTS), + ENT(LL_PATH_LAST), + }; #undef ENT ELLPathMap::const_iterator found = sMap.find(location); @@ -728,10 +720,10 @@ std::vector<std::string> LLDir::findSkinnedFilenames(const std::string& subdir, LL_PROFILE_ZONE_SCOPED_CATEGORY_UI; // Recognize subdirs that have no localization. - static const std::set<std::string> sUnlocalized = list_of - ("") // top-level directory not localized - ("textures") // textures not localized - ; + static const std::set<std::string> sUnlocalized = { + "", // top-level directory not localized + "textures" // textures not localized + }; LL_DEBUGS("LLDir") << "subdir '" << subdir << "', filename '" << filename << "', constraint " @@ -1033,7 +1025,7 @@ bool LLDir::setCacheDir(const std::string &path) { LLFile::mkdir(path); std::string tempname = add(path, "temp"); - LLFILE* file = LLFile::fopen(tempname,"wt"); + LLFILE* file = LLFile::fopen(tempname, LLFILE_MODE("wt")); if (file) { fclose(file); @@ -1110,20 +1102,78 @@ LLDir::SepOff LLDir::needSep(const std::string& path, const std::string& name) c return SepOff(false, 0); } +void LLDir::openDir(const std::string& filepath) +{ + if (filepath.empty()) + { + LL_WARNS() << "Cannot open file browser: filepath is empty" << LL_ENDL; + return; + } + + // Extract directory path from full filepath + std::string dir_path = getDirName(filepath); + + LLProcess::Params params; + +#if LL_WINDOWS + // Windows: Use explorer.exe with /select flag to highlight the file + std::string system_root = LLStringUtil::getenv("SystemRoot"); + if (system_root.empty()) + { + system_root = LLStringUtil::getenv("WINDIR"); + } + if (system_root.empty()) + { + LL_WARNS() << "Neither SystemRoot nor WINDIR environment variable is set" << LL_ENDL; + system_root = "C:\\Windows"; // Last resort fallback + } + params.executable = system_root + "\\explorer.exe"; + params.args.add("/select,"); + params.args.add(filepath); +#elif LL_DARWIN + // macOS: Use 'open' command with -R flag to reveal in Finder + params.executable = "/usr/bin/open"; + params.args.add("-R"); + params.args.add(filepath); +#elif LL_LINUX + // Linux: Use xdg-open to open the directory + // Note: Most file managers don't support file selection, so we open the directory + params.executable = "/usr/bin/xdg-open"; + params.args.add(dir_path); +#elif __FreeBSD__ + params.executable = "/usr/local/bin/xdg-open"; + params.args.add(dir_path); +#else + LL_WARNS() << "Platform not supported for file browser opening" << LL_ENDL; + return; +#endif + + params.autokill = false; // Don't kill the file browser when viewer exits + + if (!LLProcess::create(params)) + { + LL_WARNS() << "Failed to open file browser for: " << filepath << LL_ENDL; + } + else + { + LL_INFOS() << "Opened file browser for: " << filepath << LL_ENDL; + } +} + void dir_exists_or_crash(const std::string &dir_name) { #if LL_WINDOWS // *FIX: lame - it doesn't do the same thing on windows. not so // important since we don't deploy simulator to windows boxes. - LLFile::mkdir(dir_name, 0700); + LLFile::mkdir(dir_name); #else - struct stat dir_stat; + llstat dir_stat; if(0 != LLFile::stat(dir_name, &dir_stat)) { S32 stat_rv = errno; if(ENOENT == stat_rv) { - if(0 != LLFile::mkdir(dir_name, 0700)) // octal + if(0 != LLFile::mkdir(dir_name)) { LL_ERRS() << "Unable to create directory: " << dir_name << LL_ENDL; } diff --git a/indra/llfilesystem/lldir.h b/indra/llfilesystem/lldir.h index b0d2b6aada..8742b7f937 100644 --- a/indra/llfilesystem/lldir.h +++ b/indra/llfilesystem/lldir.h @@ -71,7 +71,7 @@ class LLDir std::vector<std::string> getFilesInDir(const std::string &dirname); // pure virtual functions virtual std::string getCurPath() = 0; - virtual bool fileExists(const std::string &filename) const = 0; + virtual bool fileExists(const std::string &filename) const; const std::string findFile(const std::string& filename, const std::vector<std::string> filenames) const; const std::string findFile(const std::string& filename, const std::string& searchPath1 = "", const std::string& searchPath2 = "", const std::string& searchPath3 = "") const; @@ -194,6 +194,9 @@ class LLDir virtual void dumpCurrentDirectories(LLError::ELevel level = LLError::LEVEL_DEBUG); + // Open the system file browser to reveal a file or directory + void openDir(const std::string& filepath); + // Utility routine std::string buildSLOSCacheDir() const; diff --git a/indra/llfilesystem/lldir_linux.cpp b/indra/llfilesystem/lldir_linux.cpp index 69cfedebc7..dba479c195 100644 --- a/indra/llfilesystem/lldir_linux.cpp +++ b/indra/llfilesystem/lldir_linux.cpp @@ -246,24 +246,6 @@ std::string LLDir_Linux::getCurPath() return tmp_str; } - -bool LLDir_Linux::fileExists(const std::string &filename) const -{ - struct stat stat_data; - // Check the age of the file - // Now, we see if the files we've gathered are recent... - int res = stat(filename.c_str(), &stat_data); - if (!res) - { - return true; - } - else - { - return false; - } -} - - /*virtual*/ std::string LLDir_Linux::getLLPluginLauncher() { return gDirUtilp->getExecutableDir() + gDirUtilp->getDirDelimiter() + diff --git a/indra/llfilesystem/lldir_linux.h b/indra/llfilesystem/lldir_linux.h index f9b0427ccd..ef7206430a 100644 --- a/indra/llfilesystem/lldir_linux.h +++ b/indra/llfilesystem/lldir_linux.h @@ -47,7 +47,6 @@ public: virtual std::string getCurPath(); virtual U32 countFilesInDir(const std::string &dirname, const std::string &mask); - /*virtual*/ bool fileExists(const std::string &filename) const; /*virtual*/ std::string getLLPluginLauncher(); /*virtual*/ std::string getLLPluginFilename(std::string base_name); diff --git a/indra/llfilesystem/lldir_mac.cpp b/indra/llfilesystem/lldir_mac.cpp index b25c654e31..f6181d7be4 100644 --- a/indra/llfilesystem/lldir_mac.cpp +++ b/indra/llfilesystem/lldir_mac.cpp @@ -35,7 +35,7 @@ #include <sys/stat.h> #include <unistd.h> #include <glob.h> -#include <boost/filesystem.hpp> +#include <filesystem> #include "lldir_utils_objc.h" // -------------------------------------------------------------------------------- @@ -45,15 +45,15 @@ static bool CreateDirectory(const std::string &parent, std::string *fullname) { - boost::filesystem::path p(parent); + std::filesystem::path p(parent); p /= child; if (fullname) *fullname = std::string(p.string()); - if (! boost::filesystem::create_directory(p)) + if (! std::filesystem::create_directory(p)) { - return (boost::filesystem::is_directory(p)); + return (std::filesystem::is_directory(p)); } return true; } @@ -75,10 +75,8 @@ LLDir_Mac::LLDir_Mac() // mExecutablePathAndName mExecutablePathAndName = executablepathstr; - boost::filesystem::path executablepath(executablepathstr); + std::filesystem::path executablepath(executablepathstr); -# ifndef BOOST_SYSTEM_NO_DEPRECATED -#endif mExecutableFilename = executablepath.filename().string(); mExecutableDir = executablepath.parent_path().string(); @@ -140,7 +138,7 @@ LLDir_Mac::LLDir_Mac() mOSUserAppDir = mOSUserDir; // mTempDir - //Aura 120920 boost::filesystem::temp_directory_path() not yet implemented on mac. :( + //Aura 120920 std::filesystem::temp_directory_path() not yet implemented on mac. :( std::string tmpdir = getSystemTempFolder(); if (!tmpdir.empty()) { @@ -149,7 +147,7 @@ LLDir_Mac::LLDir_Mac() mWorkingDir = getCurPath(); - mLLPluginDir = mAppRODataDir + mDirDelimiter + "llplugin"; + mLLPluginDir = mAppRODataDir + mDirDelimiter + "SLPlugin.app" + mDirDelimiter + "Contents" + mDirDelimiter + "Frameworks"; } } @@ -174,17 +172,9 @@ void LLDir_Mac::initAppDirs(const std::string &app_name, std::string LLDir_Mac::getCurPath() { - return boost::filesystem::path( boost::filesystem::current_path() ).string(); + return std::filesystem::path( std::filesystem::current_path() ).string(); } - - -bool LLDir_Mac::fileExists(const std::string &filename) const -{ - return boost::filesystem::exists(filename); -} - - /*virtual*/ std::string LLDir_Mac::getLLPluginLauncher() { return gDirUtilp->getAppRODataDir() + gDirUtilp->getDirDelimiter() + diff --git a/indra/llfilesystem/lldir_mac.h b/indra/llfilesystem/lldir_mac.h index f812ee810b..54dc2eb237 100644 --- a/indra/llfilesystem/lldir_mac.h +++ b/indra/llfilesystem/lldir_mac.h @@ -45,7 +45,6 @@ public: const std::string& app_read_only_data_dir); virtual std::string getCurPath(); - virtual bool fileExists(const std::string &filename) const; /*virtual*/ std::string getLLPluginLauncher(); /*virtual*/ std::string getLLPluginFilename(std::string base_name); diff --git a/indra/llfilesystem/lldir_utils_objc.mm b/indra/llfilesystem/lldir_utils_objc.mm index 01fe9e1f2c..35513d5647 100644 --- a/indra/llfilesystem/lldir_utils_objc.mm +++ b/indra/llfilesystem/lldir_utils_objc.mm @@ -1,28 +1,28 @@ -/** +/** * @file lldir_utils_objc.mm * @brief Cocoa implementation of directory utilities for macOS * * $LicenseInfo:firstyear=2020&license=viewerlgpl$ * Second Life Viewer Source Code * Copyright (C) 2020, Linden Research, Inc. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License only. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * + * * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ - */ + */ #if LL_DARWIN //WARNING: This file CANNOT use standard linden includes due to conflicts between definitions of BOOL @@ -39,18 +39,18 @@ std::string getSystemTempFolder() tempDir = @"/tmp"; result = std::string([tempDir UTF8String]); } - + return result; } -//findSystemDirectory scoped exclusively to this file. +//findSystemDirectory scoped exclusively to this file. std::string findSystemDirectory(NSSearchPathDirectory searchPathDirectory, NSSearchPathDomainMask domainMask) { std::string result; @autoreleasepool { NSString *path = nil; - + // Search for the path NSArray* paths = NSSearchPathForDirectoriesInDomains(searchPathDirectory, domainMask, @@ -60,10 +60,10 @@ std::string findSystemDirectory(NSSearchPathDirectory searchPathDirectory, path = [paths objectAtIndex:0]; //HACK: Always attempt to create directory, ignore errors. NSError *error = nil; - + [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error]; - - + + result = std::string([path UTF8String]); } } @@ -88,7 +88,7 @@ std::string getSystemResourceFolder() NSString *bundlePath = [[NSBundle mainBundle] resourcePath]; result = std::string([bundlePath UTF8String]); } - + return result; } @@ -102,7 +102,7 @@ std::string getSystemApplicationSupportFolder() { return findSystemDirectory (NSApplicationSupportDirectory, NSUserDomainMask); - + } #endif // LL_DARWIN diff --git a/indra/llfilesystem/lldir_win32.cpp b/indra/llfilesystem/lldir_win32.cpp index a607c70b44..912a2963c6 100644 --- a/indra/llfilesystem/lldir_win32.cpp +++ b/indra/llfilesystem/lldir_win32.cpp @@ -52,7 +52,7 @@ namespace // This is called so early that we can't count on static objects being // properly constructed yet, so declare a pointer instead of an instance. - std::ofstream* prelogf = nullptr; + llofstream* prelogf = nullptr; void prelog(const std::string& message) { @@ -172,7 +172,7 @@ LLDir_Win32::LLDir_Win32() { w_str[wcslen(w_str)-1] = '\0'; /* Flawfinder: ignore */ // remove trailing slash } - mTempDir = utf16str_to_utf8str(llutf16string(w_str)); + mTempDir = ll_convert<std::string>(std::wstring(w_str)); if (mOSUserDir.empty()) { @@ -208,7 +208,7 @@ LLDir_Win32::LLDir_Win32() { // successfully created logdir, plunk a log file there std::string logfilename(add(mOSUserDir, "lldir.log")); - std::ofstream logfile(logfilename.c_str()); + llofstream logfile(logfilename.c_str()); if (! logfile.is_open()) { report(std::cerr); @@ -225,14 +225,14 @@ LLDir_Win32::LLDir_Win32() // Set working directory, for LLDir::getWorkingDir() GetCurrentDirectory(MAX_PATH, w_str); - mWorkingDir = utf16str_to_utf8str(llutf16string(w_str)); + mWorkingDir = ll_convert<std::string>(std::wstring(w_str)); // Set the executable directory S32 size = GetModuleFileName(NULL, w_str, MAX_PATH); if (size) { w_str[size] = '\0'; - mExecutablePathAndName = utf16str_to_utf8str(llutf16string(w_str)); + mExecutablePathAndName = ll_convert<std::string>(std::wstring(w_str)); auto path_end = mExecutablePathAndName.find_last_of('\\'); if (path_end != std::string::npos) { @@ -347,8 +347,8 @@ U32 LLDir_Win32::countFilesInDir(const std::string &dirname, const std::string & WIN32_FIND_DATA FileData; - llutf16string pathname = utf8str_to_utf16str(dirname); - pathname += utf8str_to_utf16str(mask); + std::wstring pathname = ll_convert<std::wstring>(dirname); + pathname += ll_convert<std::wstring>(mask); if ((count_search_h = FindFirstFile(pathname.c_str(), &FileData)) != INVALID_HANDLE_VALUE) { @@ -370,27 +370,9 @@ std::string LLDir_Win32::getCurPath() WCHAR w_str[MAX_PATH]; GetCurrentDirectory(MAX_PATH, w_str); - return utf16str_to_utf8str(llutf16string(w_str)); + return ll_convert<std::string>(std::wstring(w_str)); } - -bool LLDir_Win32::fileExists(const std::string &filename) const -{ - llstat stat_data; - // Check the age of the file - // Now, we see if the files we've gathered are recent... - int res = LLFile::stat(filename, &stat_data); - if (!res) - { - return true; - } - else - { - return false; - } -} - - /*virtual*/ std::string LLDir_Win32::getLLPluginLauncher() { return gDirUtilp->getExecutableDir() + gDirUtilp->getDirDelimiter() + diff --git a/indra/llfilesystem/lldir_win32.h b/indra/llfilesystem/lldir_win32.h index ab2726f1a0..c3a41d3e33 100644 --- a/indra/llfilesystem/lldir_win32.h +++ b/indra/llfilesystem/lldir_win32.h @@ -44,14 +44,13 @@ public: /*virtual*/ std::string getCurPath(); /*virtual*/ U32 countFilesInDir(const std::string &dirname, const std::string &mask); - /*virtual*/ bool fileExists(const std::string &filename) const; /*virtual*/ std::string getLLPluginLauncher(); /*virtual*/ std::string getLLPluginFilename(std::string base_name); private: void* mDirSearch_h{ nullptr }; - llutf16string mCurrentDir; + std::wstring mCurrentDir; }; #endif // LL_LLDIR_WIN32_H diff --git a/indra/llfilesystem/lldirguard.h b/indra/llfilesystem/lldirguard.h index fcb179bbc8..c6ce13efb4 100644 --- a/indra/llfilesystem/lldirguard.h +++ b/indra/llfilesystem/lldirguard.h @@ -31,6 +31,9 @@ #include "llerror.h" #if LL_WINDOWS + +#include "llwin32headers.h" + class LLDirectoryGuard { public: @@ -46,8 +49,8 @@ public: (wcsncmp(mOrigDir,mFinalDir,mOrigDirLen)!=0)) { // Dir has changed - std::string mOrigDirUtf8 = utf16str_to_utf8str(llutf16string(mOrigDir)); - std::string mFinalDirUtf8 = utf16str_to_utf8str(llutf16string(mFinalDir)); + std::string mOrigDirUtf8 = ll_convert<std::string>(std::wstring(mOrigDir)); + std::string mFinalDirUtf8 = ll_convert<std::string>(std::wstring(mFinalDir)); LL_INFOS() << "Resetting working dir from " << mFinalDirUtf8 << " to " << mOrigDirUtf8 << LL_ENDL; SetCurrentDirectory(mOrigDir); } diff --git a/indra/llfilesystem/lldiriterator.cpp b/indra/llfilesystem/lldiriterator.cpp index cd99c79357..ec6d1726f0 100644 --- a/indra/llfilesystem/lldiriterator.cpp +++ b/indra/llfilesystem/lldiriterator.cpp @@ -24,13 +24,14 @@ * $/LicenseInfo$ */ +#include "linden_common.h" + #include "lldiriterator.h" -#include "fix_macros.h" #include "llregex.h" -#include <boost/filesystem.hpp> +#include <filesystem> -namespace fs = boost::filesystem; +namespace fs = std::filesystem; static std::string glob_to_regex(const std::string& glob); @@ -51,11 +52,7 @@ private: LLDirIterator::Impl::Impl(const std::string &dirname, const std::string &mask) : mIsValid(false) { -#ifdef LL_WINDOWS // or BOOST_WINDOWS_API - fs::path dir_path(utf8str_to_utf16str(dirname)); -#else - fs::path dir_path(dirname); -#endif + fs::path dir_path = fsyspath(dirname); bool is_dir = false; @@ -72,11 +69,7 @@ LLDirIterator::Impl::Impl(const std::string &dirname, const std::string &mask) if (!is_dir) { -#if LL_WINDOWS - LL_WARNS() << "Invalid path: \"" << utf16str_to_utf8str(dir_path.wstring()) << "\"" << LL_ENDL; -#else - LL_WARNS() << "Invalid path: \"" << dir_path.string() << "\"" << LL_ENDL; -#endif + LL_WARNS() << "Invalid path: \"" << dirname << "\"" << LL_ENDL; return; } @@ -133,24 +126,27 @@ bool LLDirIterator::Impl::next(std::string &fname) { while (mIter != end_itr && !found) { - boost::smatch match; -#if LL_WINDOWS - std::string name = utf16str_to_utf8str(mIter->path().filename().wstring()); -#else - std::string name = mIter->path().filename().string(); -#endif - found = ll_regex_match(name, match, mFilterExp); - if (found) + try { - fname = name; + boost::smatch match; + std::string name = fsyspath(mIter->path().filename()).string(); + found = ll_regex_match(name, match, mFilterExp); + if (found) + { + fname = name; + } + } + catch (const std::system_error& e) + { + LL_WARNS() << "Exception accessing directory entry: " << e.what() << LL_ENDL; } ++mIter; } } - catch (const fs::filesystem_error& e) + catch (const std::system_error& e) { - LL_WARNS() << e.what() << LL_ENDL; + LL_WARNS() << "Exception iterating directory: " << e.what() << LL_ENDL; } return found; diff --git a/indra/llfilesystem/lldiskcache.cpp b/indra/llfilesystem/lldiskcache.cpp index d9b223fb49..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(utf8str_to_utf16str(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(utf8str_to_utf16str(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(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()) + 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(utf8str_to_utf16str(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; } diff --git a/indra/llfilesystem/llfilesystem.cpp b/indra/llfilesystem/llfilesystem.cpp index c8ce9531c2..388cbc280f 100644 --- a/indra/llfilesystem/llfilesystem.cpp +++ b/indra/llfilesystem/llfilesystem.cpp @@ -34,8 +34,6 @@ #include "llfasttimer.h" #include "lldiskcache.h" -#include "boost/filesystem.hpp" - constexpr S32 LLFileSystem::READ = 0x00000001; constexpr S32 LLFileSystem::WRITE = 0x00000002; constexpr S32 LLFileSystem::READ_WRITE = 0x00000003; // LLFileSystem::READ & LLFileSystem::WRITE @@ -51,22 +49,21 @@ LLFileSystem::LLFileSystem(const LLUUID& file_id, const LLAssetType::EType file_ mBytesRead = 0; mMode = mode; + // build the filepath + mPath = fsyspath(LLDiskCache::metaDataToFilepath(mFileID, mFileType)); + // This block of code was originally called in the read() method but after comments here: // https://bitbucket.org/lindenlab/viewer/commits/e28c1b46e9944f0215a13cab8ee7dded88d7fc90#comment-10537114 // we decided to follow Henri's suggestion and move the code to update the last access time here. if (mode == LLFileSystem::READ) { - // build the filename (TODO: we do this in a few places - perhaps we should factor into a single function) - const std::string filename = LLDiskCache::metaDataToFilepath(mFileID, mFileType); - // update the last access time for the file if it exists - this is required // even though we are reading and not writing because this is the // way the cache works - it relies on a valid "last accessed time" for // each file so it knows how to remove the oldest, unused files - bool exists = gDirUtilp->fileExists(filename); - if (exists) + if (LLFile::exists(mPath)) { - updateFileAccessTime(filename); + updateFileAccessTime(); } } } @@ -77,21 +74,17 @@ bool LLFileSystem::getExists(const LLUUID& file_id, const LLAssetType::EType fil LL_PROFILE_ZONE_SCOPED; const std::string filename = LLDiskCache::metaDataToFilepath(file_id, file_type); - llifstream file(filename, std::ios::binary); - if (file.is_open()) - { - file.seekg(0, std::ios::end); - return file.tellg() > 0; - } - return false; + // not only test for existence but for the file to be not empty + S64 size = LLFile::size(filename); + return size > 0; } // static -bool LLFileSystem::removeFile(const LLUUID& file_id, const LLAssetType::EType file_type, int suppress_error /*= 0*/) +bool LLFileSystem::removeFile(const LLUUID& file_id, const LLAssetType::EType file_type, int suppress_warning /*= 0*/) { const std::string filename = LLDiskCache::metaDataToFilepath(file_id, file_type); - LLFile::remove(filename.c_str(), suppress_error); + LLFile::remove(filename.c_str(), suppress_warning); return true; } @@ -103,9 +96,6 @@ bool LLFileSystem::renameFile(const LLUUID& old_file_id, const LLAssetType::ETyp 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. - LLFileSystem::removeFile(new_file_id, new_file_type, ENOENT); - if (LLFile::rename(old_filename, new_filename) != 0) { // We would like to return false here indicating the operation @@ -118,29 +108,11 @@ bool LLFileSystem::renameFile(const LLUUID& old_file_id, const LLAssetType::ETyp return true; } -// static -S32 LLFileSystem::getFileSize(const LLUUID& file_id, const LLAssetType::EType file_type) -{ - const std::string filename = LLDiskCache::metaDataToFilepath(file_id, file_type); - - S32 file_size = 0; - llifstream file(filename, std::ios::binary); - if (file.is_open()) - { - file.seekg(0, std::ios::end); - file_size = (S32)file.tellg(); - } - - return file_size; -} - bool LLFileSystem::read(U8* buffer, S32 bytes) { bool success = false; - const std::string filename = LLDiskCache::metaDataToFilepath(mFileID, mFileType); - - llifstream file(filename, std::ios::binary); + llifstream file(mPath, std::ios::binary); if (file.is_open()) { file.seekg(mPosition, std::ios::beg); @@ -180,13 +152,11 @@ bool LLFileSystem::eof() const bool LLFileSystem::write(const U8* buffer, S32 bytes) { - const std::string filename = LLDiskCache::metaDataToFilepath(mFileID, mFileType); - bool success = false; if (mMode == APPEND) { - llofstream ofs(filename, std::ios::app | std::ios::binary); + llofstream ofs(mPath, std::ios::app | std::ios::binary); if (ofs) { ofs.write((const char*)buffer, bytes); @@ -199,7 +169,7 @@ bool LLFileSystem::write(const U8* buffer, S32 bytes) else if (mMode == READ_WRITE) { // Don't truncate if file already exists - llofstream ofs(filename, std::ios::in | std::ios::binary); + llofstream ofs(mPath, std::ios::in | std::ios::binary); if (ofs) { ofs.seekp(mPosition, std::ios::beg); @@ -210,7 +180,7 @@ bool LLFileSystem::write(const U8* buffer, S32 bytes) else { // File doesn't exist - open in write mode - ofs.open(filename, std::ios::binary); + ofs.open(mPath, std::ios::binary); if (ofs.is_open()) { ofs.write((const char*)buffer, bytes); @@ -221,7 +191,7 @@ bool LLFileSystem::write(const U8* buffer, S32 bytes) } else { - llofstream ofs(filename, std::ios::binary); + llofstream ofs(mPath, std::ios::binary); if (ofs) { ofs.write((const char*)buffer, bytes); @@ -272,7 +242,7 @@ S32 LLFileSystem::tell() const S32 LLFileSystem::getSize() const { - return LLFileSystem::getFileSize(mFileID, mFileType); + return narrow(LLFile::size(mPath)); } S32 LLFileSystem::getMaxSize() const @@ -287,17 +257,18 @@ bool LLFileSystem::rename(const LLUUID& new_id, const LLAssetType::EType new_typ mFileID = new_id; mFileType = new_type; + mPath = fsyspath(LLDiskCache::metaDataToFilepath(mFileID, mFileType)); return true; } bool LLFileSystem::remove() const { - LLFileSystem::removeFile(mFileID, mFileType); + LLFile::remove(mPath); return true; } -void LLFileSystem::updateFileAccessTime(const std::string& file_path) +void LLFileSystem::updateFileAccessTime() { /** * Threshold in time_t units that is used to decide if the last access time @@ -308,52 +279,32 @@ void LLFileSystem::updateFileAccessTime(const std::string& file_path) * * Let's start with 1 hour in time_t units and see how that unfolds */ - constexpr std::time_t time_threshold = 1 * 60 * 60; + constexpr std::chrono::hours time_threshold(1); // current time - const std::time_t cur_time = std::time(nullptr); - - boost::system::error_code ec; -#if LL_WINDOWS - // file last write time - const std::time_t last_write_time = boost::filesystem::last_write_time(utf8str_to_utf16str(file_path), ec); - if (ec.failed()) - { - LL_WARNS() << "Failed to read last write time for cache file " << file_path << ": " << ec.message() << LL_ENDL; - return; - } + const std::filesystem::file_time_type cur_time = std::chrono::file_clock::now(); - // delta between cur time and last time the file was written - const std::time_t delta_time = cur_time - last_write_time; - - // we only write the new value if the time in time_threshold has elapsed - // before the last one - if (delta_time > time_threshold) - { - boost::filesystem::last_write_time(utf8str_to_utf16str(file_path), cur_time, ec); - } -#else + std::error_code ec; // file last write time - const std::time_t last_write_time = boost::filesystem::last_write_time(file_path, ec); - if (ec.failed()) + const std::filesystem::file_time_type last_write_time = std::filesystem::last_write_time(mPath, ec); + if (ec) { - LL_WARNS() << "Failed to read last write time for cache file " << file_path << ": " << ec.message() << LL_ENDL; + LL_WARNS() << "Failed to read last write time for cache file " << mPath << ": " << ec.message() << LL_ENDL; return; } // delta between cur time and last time the file was written - const std::time_t delta_time = cur_time - last_write_time; + const auto delta_time = cur_time - last_write_time; // we only write the new value if the time in time_threshold has elapsed // before the last one if (delta_time > time_threshold) { - boost::filesystem::last_write_time(file_path, cur_time, ec); + std::filesystem::last_write_time(mPath, cur_time, ec); } -#endif - if (ec.failed()) + if (ec) { - LL_WARNS() << "Failed to update last write time for cache file " << file_path << ": " << ec.message() << LL_ENDL; + LL_WARNS() << "Failed to update last write time for cache file " << mPath << ": " << ec.message() << LL_ENDL; } } diff --git a/indra/llfilesystem/llfilesystem.h b/indra/llfilesystem/llfilesystem.h index 10649b6920..bc8b9216bd 100644 --- a/indra/llfilesystem/llfilesystem.h +++ b/indra/llfilesystem/llfilesystem.h @@ -33,6 +33,7 @@ #include "lluuid.h" #include "llassettype.h" #include "lldiskcache.h" +#include <filesystem> class LLFileSystem { @@ -58,13 +59,12 @@ class LLFileSystem * file in the cache is read (not written) so that the last time the file was * accessed is up to date (This is used in the mechanism for purging the cache) */ - void updateFileAccessTime(const std::string& file_path); + void updateFileAccessTime(); static bool getExists(const LLUUID& file_id, const LLAssetType::EType file_type); - static bool removeFile(const LLUUID& file_id, const LLAssetType::EType file_type, int suppress_error = 0); + static bool removeFile(const LLUUID& file_id, const LLAssetType::EType file_type, int suppress_warning = 0); static bool renameFile(const LLUUID& old_file_id, const LLAssetType::EType old_file_type, const LLUUID& new_file_id, const LLAssetType::EType new_file_type); - static S32 getFileSize(const LLUUID& file_id, const LLAssetType::EType file_type); public: static const S32 READ; @@ -73,6 +73,7 @@ class LLFileSystem static const S32 APPEND; protected: + std::filesystem::path mPath; LLAssetType::EType mFileType; LLUUID mFileID; S32 mPosition; diff --git a/indra/llfilesystem/lllfsthread.cpp b/indra/llfilesystem/lllfsthread.cpp index 6a882f64a8..69f7085290 100644 --- a/indra/llfilesystem/lllfsthread.cpp +++ b/indra/llfilesystem/lllfsthread.cpp @@ -51,6 +51,7 @@ S32 LLLFSThread::updateClass(U32 ms_elapsed) //static void LLLFSThread::cleanupClass() { + LL_PROFILE_ZONE_SCOPED; llassert(sLocal != NULL); sLocal->setQuitting(); while (sLocal->getPending()) diff --git a/indra/llfilesystem/tests/lldir_test.cpp b/indra/llfilesystem/tests/lldir_test.cpp index 6e191ad096..412feb147b 100644 --- a/indra/llfilesystem/tests/lldir_test.cpp +++ b/indra/llfilesystem/tests/lldir_test.cpp @@ -27,26 +27,15 @@ #include "linden_common.h" +#include <filesystem> #include "llstring.h" #include "tests/StringVec.h" #include "../lldir.h" #include "../lldiriterator.h" #include "../test/lltut.h" +#include "../test/namedtempfile.h" #include "stringize.h" -#include <boost/assign/list_of.hpp> - -using boost::assign::list_of; - -// We use ensure_equals(..., vec(list_of(...))) not because it's functionally -// required, but because ensure_equals() knows how to format a StringVec. -// Turns out that when ensure_equals() displays a test failure with just -// list_of("string")("another"), you see 'stringanother' vs. '("string", -// "another")'. -StringVec vec(const StringVec& v) -{ - return v; -} // For some tests, use a dummy LLDir that uses memory data instead of touching // the filesystem @@ -416,7 +405,7 @@ namespace tut std::string makeTestFile( const std::string& dir, const std::string& file ) { std::string path = dir + file; - LLFILE* handle = LLFile::fopen( path, "w" ); + LLFILE* handle = LLFile::fopen(path, LLFILE_MODE("w")); ensure("failed to open test file '"+path+"'", handle != NULL ); // Harbison & Steele, 4th ed., p. 366: "If an error occurs, fputs // returns EOF; otherwise, it returns some other, nonnegative value." @@ -425,23 +414,19 @@ namespace tut return path; } - std::string makeTestDir( const std::string& dirbase ) + std::string makeTestDir( ) { - int counter; - std::string uniqueDir; - bool foundUnused; - std::string delim = gDirUtilp->getDirDelimiter(); + auto p = NamedTempFile::temp_path(); + std::filesystem::create_directories(p.native()); - for (counter=0, foundUnused=false; !foundUnused; counter++ ) - { - char counterStr[3]; - sprintf(counterStr, "%02d", counter); - uniqueDir = dirbase + counterStr; - foundUnused = ! ( LLFile::isdir(uniqueDir) || LLFile::isfile(uniqueDir) ); - } - ensure("test directory '" + uniqueDir + "' creation failed", !LLFile::mkdir(uniqueDir)); + std::string ret = p.string(); + + // There's an implicit assumtion all over this code that the returned path ends with "/" (or "\") - return uniqueDir + delim; // HACK - apparently, the trailing delimiter is needed... + if(ret.size() >= 1 && ret[ ret.size()-1 ] != std::filesystem::path::preferred_separator ) + ret += std::filesystem::path::preferred_separator; + + return ret; } static const char* DirScanFilename[5] = { "file1.abc", "file2.abc", "file1.xyz", "file2.xyz", "file1.mno" }; @@ -497,8 +482,9 @@ namespace tut // Create the same 5 file names of the two directories - std::string dir1 = makeTestDir(dirTemp + "LLDirIterator"); - std::string dir2 = makeTestDir(dirTemp + "LLDirIterator"); + std::string dir1 = makeTestDir(); + std::string dir2 = makeTestDir(); + std::string dir1files[5]; std::string dir2files[5]; for (int i=0; i<5; i++) @@ -571,8 +557,8 @@ namespace tut LLFile::remove(dir1files[i]); LLFile::remove(dir2files[i]); } - LLFile::rmdir(dir1); - LLFile::rmdir(dir2); + LLFile::remove(dir1); + LLFile::remove(dir2); } template<> template<> @@ -590,20 +576,18 @@ namespace tut // top-level directory of a skin isn't localized ensure_equals(lldir.findSkinnedFilenames(LLDir::SKINBASE, "colors.xml", LLDir::ALL_SKINS), - vec(list_of("install/skins/default/colors.xml") - ("user/skins/default/colors.xml"))); + StringVec{ "install/skins/default/colors.xml", "user/skins/default/colors.xml" }); // We should not have needed to check for skins/default/en. We should // just "know" that SKINBASE is not localized. lldir.ensure_not_checked("install/skins/default/en"); ensure_equals(lldir.findSkinnedFilenames(LLDir::TEXTURES, "only_default.jpeg"), - vec(list_of("install/skins/default/textures/only_default.jpeg"))); + StringVec{ "install/skins/default/textures/only_default.jpeg" }); // Nor should we have needed to check skins/default/textures/en // because textures is known not to be localized. lldir.ensure_not_checked("install/skins/default/textures/en"); - StringVec expected(vec(list_of("install/skins/default/xui/en/strings.xml") - ("user/skins/default/xui/en/strings.xml"))); + StringVec expected(StringVec{ "install/skins/default/xui/en/strings.xml", "user/skins/default/xui/en/strings.xml" }); ensure_equals(lldir.findSkinnedFilenames(LLDir::XUI, "strings.xml", LLDir::ALL_SKINS), expected); // The first time, we had to probe to find out whether xui was localized. @@ -616,23 +600,19 @@ namespace tut lldir.ensure_not_checked("install/skins/default/xui/en"); // localized subdir with "en-us" instead of "en" - ensure_equals(lldir.findSkinnedFilenames("html", "welcome.html"), - vec(list_of("install/skins/default/html/en-us/welcome.html"))); + ensure_equals(lldir.findSkinnedFilenames("html", "welcome.html"), StringVec{ "install/skins/default/html/en-us/welcome.html" }); lldir.ensure_checked("install/skins/default/html/en"); lldir.ensure_checked("install/skins/default/html/en-us"); lldir.clear_checked(); - ensure_equals(lldir.findSkinnedFilenames("html", "welcome.html"), - vec(list_of("install/skins/default/html/en-us/welcome.html"))); + ensure_equals(lldir.findSkinnedFilenames("html", "welcome.html"), StringVec{ "install/skins/default/html/en-us/welcome.html" }); lldir.ensure_not_checked("install/skins/default/html/en"); lldir.ensure_not_checked("install/skins/default/html/en-us"); - ensure_equals(lldir.findSkinnedFilenames("future", "somefile.txt"), - vec(list_of("install/skins/default/future/somefile.txt"))); + ensure_equals(lldir.findSkinnedFilenames("future", "somefile.txt"), StringVec{ "install/skins/default/future/somefile.txt" }); // Test probing for an unrecognized unlocalized future subdir. lldir.ensure_checked("install/skins/default/future/en"); lldir.clear_checked(); - ensure_equals(lldir.findSkinnedFilenames("future", "somefile.txt"), - vec(list_of("install/skins/default/future/somefile.txt"))); + ensure_equals(lldir.findSkinnedFilenames("future", "somefile.txt"), StringVec{ "install/skins/default/future/somefile.txt" }); // Second time it should remember that future is unlocalized. lldir.ensure_not_checked("install/skins/default/future/en"); @@ -643,8 +623,7 @@ namespace tut // make the default localization be "en" and allow "en-gb" (or // whatever) localizations, which would work much more the way you'd // expect. - ensure_equals(lldir.findSkinnedFilenames("html", "welcome.html"), - vec(list_of("install/skins/default/html/en-us/welcome.html"))); + ensure_equals(lldir.findSkinnedFilenames("html", "welcome.html"), StringVec{ "install/skins/default/html/en-us/welcome.html" }); /*------------------------ "default", "fr" -------------------------*/ // We start being able to distinguish localized subdirs from @@ -654,100 +633,74 @@ namespace tut // pass merge=true to request this filename in all relevant skins ensure_equals(lldir.findSkinnedFilenames(LLDir::XUI, "strings.xml", LLDir::ALL_SKINS), - vec(list_of - ("install/skins/default/xui/en/strings.xml") - ("install/skins/default/xui/fr/strings.xml") - ("user/skins/default/xui/en/strings.xml") - ("user/skins/default/xui/fr/strings.xml"))); + StringVec{ "install/skins/default/xui/en/strings.xml", "install/skins/default/xui/fr/strings.xml", + "user/skins/default/xui/en/strings.xml", "user/skins/default/xui/fr/strings.xml" }); // pass (or default) merge=false to request only most specific skin ensure_equals(lldir.findSkinnedFilenames(LLDir::XUI, "strings.xml"), - vec(list_of - ("user/skins/default/xui/en/strings.xml") - ("user/skins/default/xui/fr/strings.xml"))); + StringVec{ "user/skins/default/xui/en/strings.xml", "user/skins/default/xui/fr/strings.xml" }); // Our dummy floater.xml has a user localization (for "fr") but no // English override. This is a case in which CURRENT_SKIN nonetheless // returns paths from two different skins. ensure_equals(lldir.findSkinnedFilenames(LLDir::XUI, "floater.xml"), - vec(list_of - ("install/skins/default/xui/en/floater.xml") - ("user/skins/default/xui/fr/floater.xml"))); + StringVec{ "install/skins/default/xui/en/floater.xml", "user/skins/default/xui/fr/floater.xml" }); // Our dummy newfile.xml has an English override but no user // localization. This is another case in which CURRENT_SKIN // nonetheless returns paths from two different skins. ensure_equals(lldir.findSkinnedFilenames(LLDir::XUI, "newfile.xml"), - vec(list_of - ("user/skins/default/xui/en/newfile.xml") - ("install/skins/default/xui/fr/newfile.xml"))); + StringVec{ "user/skins/default/xui/en/newfile.xml", "install/skins/default/xui/fr/newfile.xml" }); ensure_equals(lldir.findSkinnedFilenames("html", "welcome.html"), - vec(list_of - ("install/skins/default/html/en-us/welcome.html") - ("install/skins/default/html/fr/welcome.html"))); + StringVec{ "install/skins/default/html/en-us/welcome.html", "install/skins/default/html/fr/welcome.html" }); /*------------------------ "default", "zh" -------------------------*/ lldir.setSkinFolder("default", "zh"); // Because strings.xml has only a "fr" override but no "zh" override // in any skin, the most localized version we can find is "en". - ensure_equals(lldir.findSkinnedFilenames(LLDir::XUI, "strings.xml"), - vec(list_of("user/skins/default/xui/en/strings.xml"))); + ensure_equals(lldir.findSkinnedFilenames(LLDir::XUI, "strings.xml"), StringVec{ "user/skins/default/xui/en/strings.xml" }); /*------------------------- "steam", "en" --------------------------*/ lldir.setSkinFolder("steam", "en"); ensure_equals(lldir.findSkinnedFilenames(LLDir::SKINBASE, "colors.xml", LLDir::ALL_SKINS), - vec(list_of - ("install/skins/default/colors.xml") - ("install/skins/steam/colors.xml") - ("user/skins/default/colors.xml") - ("user/skins/steam/colors.xml"))); + StringVec{ "install/skins/default/colors.xml", "install/skins/steam/colors.xml", "user/skins/default/colors.xml", + "user/skins/steam/colors.xml" }); ensure_equals(lldir.findSkinnedFilenames(LLDir::TEXTURES, "only_default.jpeg"), - vec(list_of("install/skins/default/textures/only_default.jpeg"))); + StringVec{ "install/skins/default/textures/only_default.jpeg" }); ensure_equals(lldir.findSkinnedFilenames(LLDir::TEXTURES, "only_steam.jpeg"), - vec(list_of("install/skins/steam/textures/only_steam.jpeg"))); + StringVec{ "install/skins/steam/textures/only_steam.jpeg" }); ensure_equals(lldir.findSkinnedFilenames(LLDir::TEXTURES, "only_user_default.jpeg"), - vec(list_of("user/skins/default/textures/only_user_default.jpeg"))); + StringVec{ "user/skins/default/textures/only_user_default.jpeg" }); ensure_equals(lldir.findSkinnedFilenames(LLDir::TEXTURES, "only_user_steam.jpeg"), - vec(list_of("user/skins/steam/textures/only_user_steam.jpeg"))); + StringVec{ "user/skins/steam/textures/only_user_steam.jpeg" }); // CURRENT_SKIN - ensure_equals(lldir.findSkinnedFilenames(LLDir::XUI, "strings.xml"), - vec(list_of("user/skins/steam/xui/en/strings.xml"))); + ensure_equals(lldir.findSkinnedFilenames(LLDir::XUI, "strings.xml"), StringVec{ "user/skins/steam/xui/en/strings.xml" }); // pass constraint=ALL_SKINS to request this filename in all relevant skins ensure_equals(lldir.findSkinnedFilenames(LLDir::XUI, "strings.xml", LLDir::ALL_SKINS), - vec(list_of - ("install/skins/default/xui/en/strings.xml") - ("install/skins/steam/xui/en/strings.xml") - ("user/skins/default/xui/en/strings.xml") - ("user/skins/steam/xui/en/strings.xml"))); + StringVec{ "install/skins/default/xui/en/strings.xml", "install/skins/steam/xui/en/strings.xml", + "user/skins/default/xui/en/strings.xml", "user/skins/steam/xui/en/strings.xml" }); /*------------------------- "steam", "fr" --------------------------*/ lldir.setSkinFolder("steam", "fr"); // pass CURRENT_SKIN to request only the most specialized files ensure_equals(lldir.findSkinnedFilenames(LLDir::XUI, "strings.xml"), - vec(list_of - ("user/skins/steam/xui/en/strings.xml") - ("user/skins/steam/xui/fr/strings.xml"))); + StringVec{ "user/skins/steam/xui/en/strings.xml", "user/skins/steam/xui/fr/strings.xml" }); // pass ALL_SKINS to request this filename in all relevant skins ensure_equals(lldir.findSkinnedFilenames(LLDir::XUI, "strings.xml", LLDir::ALL_SKINS), - vec(list_of - ("install/skins/default/xui/en/strings.xml") - ("install/skins/default/xui/fr/strings.xml") - ("install/skins/steam/xui/en/strings.xml") - ("install/skins/steam/xui/fr/strings.xml") - ("user/skins/default/xui/en/strings.xml") - ("user/skins/default/xui/fr/strings.xml") - ("user/skins/steam/xui/en/strings.xml") - ("user/skins/steam/xui/fr/strings.xml"))); + StringVec{ "install/skins/default/xui/en/strings.xml", "install/skins/default/xui/fr/strings.xml", + "install/skins/steam/xui/en/strings.xml", "install/skins/steam/xui/fr/strings.xml", + "user/skins/default/xui/en/strings.xml", "user/skins/default/xui/fr/strings.xml", + "user/skins/steam/xui/en/strings.xml", "user/skins/steam/xui/fr/strings.xml" }); } template<> template<> |
