diff options
| author | Rye <rye@alchemyviewer.org> | 2025-12-29 07:29:11 -0500 |
|---|---|---|
| committer | Andrey Kleshchev <117672381+akleshchev@users.noreply.github.com> | 2026-01-07 02:15:43 +0200 |
| commit | 615b1bcec74f4d6d759d69ecf9965b7d2b423c52 (patch) | |
| tree | de4e619620f845d0063d924fb1f48ea2b7fe9308 | |
| parent | e440c0e47958ae9adeb775de6a4f033010b82414 (diff) | |
Replace remaining boost::filesystem usage with std::filesystem
Signed-off-by: Rye <rye@alchemyviewer.org>
| -rw-r--r-- | indra/llcommon/tests/llleap_test.cpp | 20 | ||||
| -rw-r--r-- | indra/llcommon/tests/llprocess_test.cpp | 52 | ||||
| -rw-r--r-- | indra/llcommon/tests/llsdserialize_test.cpp | 12 | ||||
| -rw-r--r-- | indra/llfilesystem/lldir_mac.cpp | 16 | ||||
| -rw-r--r-- | indra/llfilesystem/lldiriterator.cpp | 10 | ||||
| -rw-r--r-- | indra/llfilesystem/lldiskcache.cpp | 98 | ||||
| -rw-r--r-- | indra/newview/llappdelegate-objc.mm | 8 | ||||
| -rw-r--r-- | indra/newview/lllocalbitmaps.cpp | 18 | ||||
| -rw-r--r-- | indra/newview/lllocalbitmaps.h | 3 | ||||
| -rw-r--r-- | indra/newview/lllocalgltfmaterials.cpp | 18 | ||||
| -rw-r--r-- | indra/newview/lllocalgltfmaterials.h | 3 | ||||
| -rw-r--r-- | indra/newview/llsnapshotlivepreview.cpp | 1 | ||||
| -rw-r--r-- | indra/newview/llviewerwindow.cpp | 19 | ||||
| -rw-r--r-- | indra/test/namedtempfile.h | 45 | ||||
| -rw-r--r-- | indra/test/test.cpp | 6 |
15 files changed, 142 insertions, 187 deletions
diff --git a/indra/llcommon/tests/llleap_test.cpp b/indra/llcommon/tests/llleap_test.cpp index fa48bcdefd..ae20e7ed27 100644 --- a/indra/llcommon/tests/llleap_test.cpp +++ b/indra/llcommon/tests/llleap_test.cpp @@ -190,7 +190,7 @@ namespace tut // computation, so I don't mind calling it twice.) Then take the // basename. reader_module(LLProcess::basename( - reader.getName().substr(0, reader.getName().length()-3))), + reader.getPath().string().substr(0, reader.getPath().string().length()-3))), PYTHON(LLStringUtil::getenv("PYTHON")) { ensure("Set PYTHON to interpreter pathname", !PYTHON.empty()); @@ -212,9 +212,9 @@ namespace tut "time.sleep(1)\n"); LLLeapVector instances; instances.push_back(LLLeap::create(get_test_name(), - StringVec{PYTHON, script.getName()})->getWeak()); + StringVec{PYTHON, script.getPath().string()})->getWeak()); instances.push_back(LLLeap::create(get_test_name(), - StringVec{PYTHON, script.getName()})->getWeak()); + StringVec{PYTHON, script.getPath().string()})->getWeak()); // In this case we're simply establishing that two LLLeap instances // can coexist without throwing exceptions or bombing in any other // way. Wait for them to terminate. @@ -229,7 +229,7 @@ namespace tut "import sys\n" "sys.stderr.write('''Hello from Python!\n" "note partial line''')\n"); - StringVec vcommand{ PYTHON, script.getName() }; + StringVec vcommand{ PYTHON, script.getPath().string() }; CaptureLog log(LLError::LEVEL_INFO); waitfor(LLLeap::create(get_test_name(), vcommand)); log.messageWith("Hello from Python!"); @@ -244,7 +244,7 @@ namespace tut "print('Hello from Python!')\n"); CaptureLog log(LLError::LEVEL_WARN); waitfor(LLLeap::create(get_test_name(), - StringVec{PYTHON, script.getName()})); + StringVec{PYTHON, script.getPath().string()})); ensure_contains("error log line", log.messageWith("invalid protocol"), "Hello from Python!"); } @@ -259,7 +259,7 @@ namespace tut "sys.stdout.write('Hello from Python!')\n"); CaptureLog log(LLError::LEVEL_WARN); waitfor(LLLeap::create(get_test_name(), - StringVec{PYTHON, script.getName()})); + StringVec{PYTHON, script.getPath().string()})); ensure_contains("error log line", log.messageWith("Discarding"), "Hello from Python!"); } @@ -273,7 +273,7 @@ namespace tut "sys.stdout.write('5a2:something')\n"); CaptureLog log(LLError::LEVEL_WARN); waitfor(LLLeap::create(get_test_name(), - StringVec{PYTHON, script.getName()})); + StringVec{PYTHON, script.getPath().string()})); ensure_contains("error log line", log.messageWith("invalid protocol"), "5a2:"); } @@ -386,7 +386,7 @@ namespace tut " else 'bad: ' + str(resp)\n" "send(pump='" << result.getName() << "', data=result)\n";}); waitfor(LLLeap::create(get_test_name(), - StringVec{PYTHON, script.getName()})); + StringVec{PYTHON, script.getPath().string()})); result.ensure(); } @@ -445,7 +445,7 @@ namespace tut " result = 'expected reqid=%s in %s' % (i, resp)\n" " break\n" "send(pump='" << result.getName() << "', data=result)\n";}); - waitfor(LLLeap::create(get_test_name(), StringVec{PYTHON, script.getName()}), + waitfor(LLLeap::create(get_test_name(), StringVec{PYTHON, script.getPath().string()}), 300); // needs more realtime than most tests result.ensure(); } @@ -512,7 +512,7 @@ namespace tut " (start, large[start:end], echoed[start:end]))\n" "sys.exit(1)\n";}); waitfor(LLLeap::create(test_name, - StringVec{PYTHON, script.getName(), stringize(size)}), + StringVec{PYTHON, script.getPath().string(), stringize(size)}), 180); // try a longer timeout result.ensure(); } diff --git a/indra/llcommon/tests/llprocess_test.cpp b/indra/llcommon/tests/llprocess_test.cpp index cdf9f70b6e..5e653d0ba0 100644 --- a/indra/llcommon/tests/llprocess_test.cpp +++ b/indra/llcommon/tests/llprocess_test.cpp @@ -87,12 +87,12 @@ static void aprchk_(const char* call, apr_status_t rv, apr_status_t expected=APR * @param desc Optional description of the file for error message; * defaults to "in <pathname>" */ -static std::string readfile(const std::string& pathname, const std::string& desc="") +static std::string readfile(const std::filesystem::path& pathname, const std::string& desc="") { std::string use_desc(desc); if (use_desc.empty()) { - use_desc = "in " + pathname; + use_desc = "in " + pathname.string(); } llifstream inf(pathname.c_str()); std::string output; @@ -165,7 +165,7 @@ struct PythonProcessLauncher mParams.desc = desc + " script"; mParams.executable = PYTHON; - mParams.args.add(mScript.getName()); + mParams.args.add(mScript.getPath().string()); } /// Launch Python script; verify that it launched @@ -233,11 +233,11 @@ struct PythonProcessLauncher { NamedTempFile out("out", ""); // placeholder // pass name of this temporary file to the script - mParams.args.add(out.getName()); + mParams.args.add(out.getPath().string()); run(); // assuming the script wrote to that file, read it std::string desc = "from " + mDesc + " script"; - return readfile(out.getName(), desc); + return readfile(out.getPath(), desc); } LLProcess::Params mParams; @@ -271,23 +271,23 @@ public: NamedTempDir(): mPath(NamedTempFile::temp_path()), - mCreated(boost::filesystem::create_directories(mPath)) + mCreated(std::filesystem::create_directories(mPath)) { - mPath = boost::filesystem::canonical(mPath); + mPath = std::filesystem::canonical(mPath); } ~NamedTempDir() { if (mCreated) { - boost::filesystem::remove_all(mPath); + std::filesystem::remove_all(mPath); } } std::string getName() const { return mPath.string(); } private: - boost::filesystem::path mPath; + std::filesystem::path mPath; bool mCreated; }; @@ -440,7 +440,7 @@ namespace tut #endif // Have to have a named copy of this std::string so its c_str() value // will persist. - std::string scriptname(script.getName()); + std::string scriptname(script.getPath().string()); argv.push_back(scriptname.c_str()); argv.push_back(NULL); @@ -719,14 +719,14 @@ namespace tut "with open(sys.argv[1], 'w') as f:\n" " f.write('bad')\n"); NamedTempFile out("out", "not started"); - py.mParams.args.add(out.getName()); + py.mParams.args.add(out.getPath().string()); py.launch(); // Wait for the script to wake up and do its first write int i = 0, timeout = 60; for ( ; i < timeout; ++i) { yield(); - if (readfile(out.getName(), "from kill() script") == "ok") + if (readfile(out.getPath(), "from kill() script") == "ok") break; } // If we broke this loop because of the counter, something's wrong @@ -745,7 +745,7 @@ namespace tut // If kill() failed, the script would have woken up on its own and // overwritten the file with 'bad'. But if kill() succeeded, it should // not have had that chance. - ensure_equals(get_test_name() + " script output", readfile(out.getName()), "ok"); + ensure_equals(get_test_name() + " script output", readfile(out.getPath()), "ok"); } template<> template<> @@ -765,7 +765,7 @@ namespace tut "# if caller hasn't managed to kill by now, bad\n" "with open(sys.argv[1], 'w') as f:\n" " f.write('bad')\n"); - py.mParams.args.add(out.getName()); + py.mParams.args.add(out.getPath().string()); py.launch(); // Capture handle for later phandle = py.mPy->getProcessHandle(); @@ -774,7 +774,7 @@ namespace tut for ( ; i < timeout; ++i) { yield(); - if (readfile(out.getName(), "from kill() script") == "ok") + if (readfile(out.getPath(), "from kill() script") == "ok") break; } // If we broke this loop because of the counter, something's wrong @@ -787,7 +787,7 @@ namespace tut // If kill() failed, the script would have woken up on its own and // overwritten the file with 'bad'. But if kill() succeeded, it should // not have had that chance. - ensure_equals(get_test_name() + " script output", readfile(out.getName()), "ok"); + ensure_equals(get_test_name() + " script output", readfile(out.getPath()), "ok"); } template<> template<> @@ -817,8 +817,8 @@ namespace tut "# okay, saw 'go', write 'ack'\n" "with open(sys.argv[1], 'w') as f:\n" " f.write('ack')\n"); - py.mParams.args.add(from.getName()); - py.mParams.args.add(to.getName()); + py.mParams.args.add(from.getPath().string()); + py.mParams.args.add(to.getPath().string()); py.mParams.autokill = false; py.launch(); // Capture handle for later @@ -828,7 +828,7 @@ namespace tut for ( ; i < timeout; ++i) { yield(); - if (readfile(from.getName(), "from autokill script") == "ok") + if (readfile(from.getPath(), "from autokill script") == "ok") break; } // If we broke this loop because of the counter, something's wrong @@ -840,14 +840,14 @@ namespace tut // How do we know it's not terminated? By making it respond to // a specific stimulus in a specific way. { - llofstream outf(to.getName().c_str()); + llofstream outf(to.getPath()); outf << "go"; } // flush and close. // now wait for the script to terminate... one way or another. waitfor(phandle, "autokill script"); // If the LLProcess destructor implicitly called kill(), the // script could not have written 'ack' as we expect. - ensure_equals(get_test_name() + " script output", readfile(from.getName()), "ack"); + ensure_equals(get_test_name() + " script output", readfile(from.getPath()), "ack"); } template<> template<> @@ -879,8 +879,8 @@ namespace tut "# okay, saw 'go', write 'ack'\n" "with open(sys.argv[1], 'w') as f:\n" " f.write('ack')\n"); - py.mParams.args.add(from.getName()); - py.mParams.args.add(to.getName()); + py.mParams.args.add(from.getPath().string()); + py.mParams.args.add(to.getPath().string()); py.mParams.autokill = true; py.mParams.attached = false; py.launch(); @@ -891,7 +891,7 @@ namespace tut for ( ; i < timeout; ++i) { yield(); - if (readfile(from.getName(), "from autokill script") == "ok") + if (readfile(from.getPath(), "from autokill script") == "ok") break; } // If we broke this loop because of the counter, something's wrong @@ -903,14 +903,14 @@ namespace tut // How do we know it's not terminated? By making it respond to // a specific stimulus in a specific way. { - llofstream outf(to.getName().c_str()); + llofstream outf(to.getPath()); outf << "go"; } // flush and close. // now wait for the script to terminate... one way or another. waitfor(phandle, "autokill script"); // If the LLProcess destructor implicitly called kill(), the // script could not have written 'ack' as we expect. - ensure_equals(get_test_name() + " script output", readfile(from.getName()), "ack"); + ensure_equals(get_test_name() + " script output", readfile(from.getPath()), "ack"); } template<> template<> diff --git a/indra/llcommon/tests/llsdserialize_test.cpp b/indra/llcommon/tests/llsdserialize_test.cpp index 272eb55521..a7abfda099 100644 --- a/indra/llcommon/tests/llsdserialize_test.cpp +++ b/indra/llcommon/tests/llsdserialize_test.cpp @@ -1808,7 +1808,7 @@ namespace tut #if LL_WINDOWS std::string q("\""); std::string qPYTHON(q + PYTHON + q); - std::string qscript(q + scriptfile.getName() + q); + std::string qscript(q + scriptfile.getPath().string() + q); int rc = (int)_spawnl(_P_WAIT, PYTHON.c_str(), qPYTHON.c_str(), qscript.c_str(), std::forward<ARGS>(args)..., NULL); if (rc == -1) @@ -1825,7 +1825,7 @@ namespace tut #else // LL_DARWIN, LL_LINUX LLProcess::Params params; params.executable = PYTHON; - params.args.add(scriptfile.getName()); + params.args.add(scriptfile.getPath().string()); for (const std::string& arg : StringVec{ std::forward<ARGS>(args)... }) { params.args.add(arg); @@ -2002,8 +2002,8 @@ namespace tut " yield frombytes\n" << pydata << // Don't forget raw-string syntax for Windows pathnames. - "debug = open(r'" << debug.getName() << "', 'w')\n" - "verify(parse_each(open(r'" << file.getName() << "', 'rb')))\n";}); + "debug = open(r'" << debug.getPath().string() << "', 'w')\n" + "verify(parse_each(open(r'" << file.getPath().string() << "', 'rb')))\n";}); } catch (const failure&) { @@ -2111,13 +2111,13 @@ namespace tut "]\n" // Don't forget raw-string syntax for Windows pathnames. // N.B. Using 'print' implicitly adds newlines. - "with open(r'" << file.getName() << "', 'wb') as f:\n" + "with open(r'" << (const char*)file.getPath().u8string().c_str() << "', 'wb') as f:\n" " for item in DATA:\n" " serialized = llsd." << pyformatter << "(item)\n" " f.write(lenformat.pack(len(serialized)))\n" " f.write(serialized)\n";}); - llifstream inf(file.getName().c_str()); + llifstream inf(file.getPath()); LLSD item; try { diff --git a/indra/llfilesystem/lldir_mac.cpp b/indra/llfilesystem/lldir_mac.cpp index 7bddee0f75..b13e72ff15 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()) { @@ -174,7 +172,7 @@ 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(); } /*virtual*/ std::string LLDir_Mac::getLLPluginLauncher() diff --git a/indra/llfilesystem/lldiriterator.cpp b/indra/llfilesystem/lldiriterator.cpp index 57d4912c94..60b55c7bf3 100644 --- a/indra/llfilesystem/lldiriterator.cpp +++ b/indra/llfilesystem/lldiriterator.cpp @@ -29,9 +29,9 @@ #include "lldiriterator.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); @@ -52,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(ll_convert<std::wstring>(dirname)); -#else - fs::path dir_path(dirname); -#endif + fs::path dir_path = fsyspath(dirname); bool is_dir = false; diff --git a/indra/llfilesystem/lldiskcache.cpp b/indra/llfilesystem/lldiskcache.cpp index 3430bec925..e971e324a0 100644 --- a/indra/llfilesystem/lldiskcache.cpp +++ b/indra/llfilesystem/lldiskcache.cpp @@ -34,8 +34,8 @@ #include "llapp.h" #include "llassettype.h" #include "lldir.h" -#include <boost/filesystem.hpp> #include <chrono> +#include <filesystem> #include "lldiskcache.h" @@ -67,7 +67,7 @@ LLDiskCache::LLDiskCache(const std::string& cache_dir, // 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 +// 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 +83,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 @@ -96,38 +96,34 @@ void LLDiskCache::purge() 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(!LLApp::isRunning()) { return; } - if (boost::filesystem::is_regular_file(*iter, ec) && !ec.failed()) + if (std::filesystem::is_regular_file(*iter, ec) && !ec) { if ((*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; } const std::string file_path = (*iter).path().string(); - const std::time_t file_time = boost::filesystem::last_write_time(*iter, ec); - if (ec.failed()) + const std::filesystem::file_time_type file_time = std::filesystem::last_write_time(*iter, ec); + if (ec) { continue; } @@ -167,8 +163,8 @@ void LLDiskCache::purge() } if (should_remove) { - boost::filesystem::remove(entry.second.second, ec); - if (ec.failed()) + std::filesystem::remove(entry.second.second, ec); + if (ec) { LL_WARNS() << "Failed to delete cache file " << entry.second.second << ": " << ec.message() << LL_ENDL; } @@ -196,7 +192,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 << ")"; @@ -238,23 +234,19 @@ 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 ((*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) { LL_WARNS() << "Failed to delete cache file " << *iter << ": " << ec.message() << LL_ENDL; } @@ -271,24 +263,20 @@ 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 (((*iter).path().string().find(CACHE_FORMAT) != std::string::npos) || ((*iter).path().string().find(DB_FORMAT) != std::string::npos)) { - boost::filesystem::remove(*iter, ec); - if (ec.failed()) + std::filesystem::remove(*iter, ec); + if (ec) { LL_WARNS() << "Failed to delete cache file " << *iter << ": " << ec.message() << LL_ENDL; } @@ -312,23 +300,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 ((*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/newview/llappdelegate-objc.mm b/indra/newview/llappdelegate-objc.mm index 409671d939..23a4effd87 100644 --- a/indra/newview/llappdelegate-objc.mm +++ b/indra/newview/llappdelegate-objc.mm @@ -26,7 +26,7 @@ #import "llappdelegate-objc.h" #if defined(LL_BUGSPLAT) -#include <boost/filesystem.hpp> +#include <filesystem> #include <vector> @import CrashReporter; @import HockeySDK; @@ -252,7 +252,7 @@ if(!secondLogPath.empty()) { - boost::filesystem::remove(secondLogPath); + std::filesystem::remove(secondLogPath); } clearDumpLogsDir(); } @@ -326,7 +326,7 @@ struct AttachmentInfo { AttachmentInfo(const std::string& path, const std::string& type): pathname(path), - basename(boost::filesystem::path(path).filename().string()), + basename(std::filesystem::path(path).filename().string()), mimetype(type) {} @@ -361,7 +361,7 @@ struct AttachmentInfo // the log data to a browser, so take this opportunity to rename the file // from <base>.crash to <base>_log.txt info[0].basename = - boost::filesystem::path(info[0].pathname).stem().string() + "_log.txt"; + std::filesystem::path(info[0].pathname).stem().string() + "_log.txt"; infos("attachmentsForBugsplatStartupManager attaching log " + info[0].basename); NSMutableArray *attachments = [[NSMutableArray alloc] init]; diff --git a/indra/newview/lllocalbitmaps.cpp b/indra/newview/lllocalbitmaps.cpp index a5ab5538e7..d80d9058e2 100644 --- a/indra/newview/lllocalbitmaps.cpp +++ b/indra/newview/lllocalbitmaps.cpp @@ -31,8 +31,6 @@ /* own header */ #include "lllocalbitmaps.h" -#include <boost/filesystem.hpp> - /* image compression headers. */ #include "llimagebmp.h" #include "llimagetga.h" @@ -40,11 +38,8 @@ #include "llimagejpeg.h" #include "llimagepng.h" -/* time headers */ -#include <time.h> -#include <ctime> - /* misc headers */ +#include "fsyspath.h" #include "llgltfmaterial.h" #include "llscrolllistctrl.h" #include "lllocaltextureobject.h" @@ -190,15 +185,8 @@ bool LLLocalBitmap::updateSelf(EUpdateType optional_firstupdate) if (gDirUtilp->fileExists(mFilename)) { // verifying that the file has indeed been modified - -#ifndef LL_WINDOWS - const std::time_t temp_time = boost::filesystem::last_write_time(boost::filesystem::path(mFilename)); -#else - const std::time_t temp_time = boost::filesystem::last_write_time(boost::filesystem::path(ll_convert<std::wstring>(mFilename))); -#endif - LLSD new_last_modified = asctime(localtime(&temp_time)); - - if (mLastModified.asString() != new_last_modified.asString()) + const std::filesystem::file_time_type new_last_modified = std::filesystem::last_write_time(fsyspath(mFilename)); + if (mLastModified != new_last_modified) { /* loading the image file and decoding it, here is a critical point which, if fails, invalidates the whole update (or unit creation) process. */ diff --git a/indra/newview/lllocalbitmaps.h b/indra/newview/lllocalbitmaps.h index 6c9d65e3b6..c4aaeae719 100644 --- a/indra/newview/lllocalbitmaps.h +++ b/indra/newview/lllocalbitmaps.h @@ -32,6 +32,7 @@ #include "lleventtimer.h" #include "llpointer.h" #include "llwearabletype.h" +#include <filesystem> class LLScrollListCtrl; class LLImageRaw; @@ -99,7 +100,7 @@ class LLLocalBitmap LLUUID mTrackingID; LLUUID mWorldID; bool mValid; - LLSD mLastModified; + std::filesystem::file_time_type mLastModified; EExtension mExtension; ELinkStatus mLinkStatus; S32 mUpdateRetries; diff --git a/indra/newview/lllocalgltfmaterials.cpp b/indra/newview/lllocalgltfmaterials.cpp index aeae7cb56a..e9f2299be7 100644 --- a/indra/newview/lllocalgltfmaterials.cpp +++ b/indra/newview/lllocalgltfmaterials.cpp @@ -30,13 +30,8 @@ /* own header */ #include "lllocalgltfmaterials.h" -#include <boost/filesystem.hpp> - -/* time headers */ -#include <time.h> -#include <ctime> - /* misc headers */ +#include "fsyspath.h" #include "llgltfmateriallist.h" #include "llimage.h" #include "llinventoryicon.h" @@ -128,15 +123,8 @@ bool LLLocalGLTFMaterial::updateSelf() if (gDirUtilp->fileExists(mFilename)) { // verifying that the file has indeed been modified - -#ifndef LL_WINDOWS - const std::time_t temp_time = boost::filesystem::last_write_time(boost::filesystem::path(mFilename)); -#else - const std::time_t temp_time = boost::filesystem::last_write_time(boost::filesystem::path(ll_convert<std::wstring>(mFilename))); -#endif - LLSD new_last_modified = asctime(localtime(&temp_time)); - - if (mLastModified.asString() != new_last_modified.asString()) + const std::filesystem::file_time_type new_last_modified = std::filesystem::last_write_time(fsyspath(mFilename)); + if (mLastModified != new_last_modified) { if (loadMaterial()) { diff --git a/indra/newview/lllocalgltfmaterials.h b/indra/newview/lllocalgltfmaterials.h index b806b54508..bf9a8c68ae 100644 --- a/indra/newview/lllocalgltfmaterials.h +++ b/indra/newview/lllocalgltfmaterials.h @@ -30,6 +30,7 @@ #include "lleventtimer.h" #include "llpointer.h" #include "llgltfmateriallist.h" +#include <filesystem> class LLScrollListCtrl; class LLGLTFMaterial; @@ -73,7 +74,7 @@ private: /* members */ std::string mShortName; LLUUID mTrackingID; LLUUID mWorldID; - LLSD mLastModified; + std::filesystem::file_time_type mLastModified; EExtension mExtension; ELinkStatus mLinkStatus; S32 mUpdateRetries; diff --git a/indra/newview/llsnapshotlivepreview.cpp b/indra/newview/llsnapshotlivepreview.cpp index 3a894996e4..7d2828a872 100644 --- a/indra/newview/llsnapshotlivepreview.cpp +++ b/indra/newview/llsnapshotlivepreview.cpp @@ -54,7 +54,6 @@ #include "llviewertexturelist.h" #include "llwindow.h" #include "llworld.h" -#include <boost/filesystem.hpp> constexpr F32 AUTO_SNAPSHOT_TIME_DELAY = 1.f; diff --git a/indra/newview/llviewerwindow.cpp b/indra/newview/llviewerwindow.cpp index 0980c4a291..c77dd9cc08 100644 --- a/indra/newview/llviewerwindow.cpp +++ b/indra/newview/llviewerwindow.cpp @@ -33,9 +33,6 @@ #include <iostream> #include <fstream> #include <algorithm> -#include <boost/filesystem.hpp> -#include <boost/lambda/core.hpp> -#include <boost/regex.hpp> #include "llagent.h" #include "llagentcamera.h" @@ -4837,14 +4834,10 @@ void LLViewerWindow::saveImageLocal(LLImageFormatted *image, const snapshot_save return; } -// Check if there is enough free space to save snapshot -#ifdef LL_WINDOWS - boost::filesystem::path b_path(ll_convert<std::wstring>(lastSnapshotDir)); -#else - boost::filesystem::path b_path(lastSnapshotDir); -#endif - boost::system::error_code ec; - if (!boost::filesystem::is_directory(b_path, ec) || ec.failed()) + // Check if there is enough free space to save snapshot + std::filesystem::path b_path = fsyspath(lastSnapshotDir); + std::error_code ec; + if (!std::filesystem::is_directory(b_path, ec) || ec) { LLSD args; args["PATH"] = lastSnapshotDir; @@ -4853,8 +4846,8 @@ void LLViewerWindow::saveImageLocal(LLImageFormatted *image, const snapshot_save failure_cb(); return; } - boost::filesystem::space_info b_space = boost::filesystem::space(b_path, ec); - if (ec.failed()) + std::filesystem::space_info b_space = std::filesystem::space(b_path, ec); + if (ec) { LLSD args; args["PATH"] = lastSnapshotDir; diff --git a/indra/test/namedtempfile.h b/indra/test/namedtempfile.h index 8027f95728..a38746759f 100644 --- a/indra/test/namedtempfile.h +++ b/indra/test/namedtempfile.h @@ -12,26 +12,29 @@ #if ! defined(LL_NAMEDTEMPFILE_H) #define LL_NAMEDTEMPFILE_H +#include "fsyspath.h" #include "llerror.h" #include "llstring.h" #include "stringize.h" #include <string> -#include <boost/filesystem.hpp> -#include <boost/filesystem/fstream.hpp> -#include <boost/noncopyable.hpp> +#include <fstream> #include <functional> #include <iostream> #include <sstream> #include <string_view> +#include <random> /** * Create a text file with specified content "somewhere in the * filesystem," cleaning up when it goes out of scope. */ -class NamedTempFile: public boost::noncopyable +class NamedTempFile { LOG_CLASS(NamedTempFile); public: + NamedTempFile(const NamedTempFile&) = delete; + NamedTempFile& operator=(const NamedTempFile&) = delete; + NamedTempFile(const std::string_view& pfx, const std::string_view& content, const std::string_view& sfx=std::string_view("")) @@ -62,16 +65,16 @@ public: virtual ~NamedTempFile() { - boost::filesystem::remove(mPath); + std::filesystem::remove(mPath); } - std::string getName() const { return mPath.string(); } + const std::filesystem::path& getPath() const { return mPath; } template <typename CALLABLE> void peep_via(CALLABLE&& callable) const { std::forward<CALLABLE>(callable)(stringize("File '", mPath, "' contains:")); - boost::filesystem::ifstream reader(mPath, std::ios::binary); + std::ifstream reader(mPath, std::ios::binary); std::string line; while (std::getline(reader, line)) std::forward<CALLABLE>(callable)(line); @@ -94,23 +97,27 @@ public: return out; } - static boost::filesystem::path temp_path(const std::string_view& pfx="", + static std::filesystem::path temp_path(const std::string_view& pfx="", const std::string_view& sfx="") { // This variable is set by GitHub actions and is the recommended place // to put temp files belonging to an actions job. const char* RUNNER_TEMP = getenv("RUNNER_TEMP"); - boost::filesystem::path tempdir{ + std::filesystem::path tempdir{ // if RUNNER_TEMP is set and not empty (RUNNER_TEMP && *RUNNER_TEMP)? - boost::filesystem::path(RUNNER_TEMP) : // use RUNNER_TEMP if available - boost::filesystem::temp_directory_path()}; // else canonical temp dir - boost::filesystem::path tempname{ - // use filename template recommended by unique_path() doc, but - // with underscores instead of hyphens: some use cases involve - // temporary Python scripts - tempdir / stringize(pfx, "%%%%_%%%%_%%%%_%%%%", sfx) }; - return boost::filesystem::unique_path(tempname); + fsyspath::path(RUNNER_TEMP) : // use RUNNER_TEMP if available + std::filesystem::temp_directory_path()}; // else canonical temp dir + + static std::mt19937 random_generator{std::random_device{}()}; + static std::uniform_int_distribution<> distribution{0, std::numeric_limits<uint8_t>::max()}; + std::string tempname{}; + static constexpr auto num_bits = 128; + for (auto i = 0; i < (num_bits / std::numeric_limits<uint8_t>::digits); ++i) { + tempname += llformat("%02x", distribution(random_generator)); + } + tempname = std::string(pfx) + tempname + std::string(sfx); + return tempdir / tempname; } protected: @@ -120,12 +127,12 @@ protected: { // Create file in a temporary place. mPath = temp_path(pfx, sfx); - boost::filesystem::ofstream out{ mPath, std::ios::binary }; + std::ofstream out{ mPath, std::ios::binary }; // Write desired content. func(out); } - boost::filesystem::path mPath; + std::filesystem::path mPath; }; /** diff --git a/indra/test/test.cpp b/indra/test/test.cpp index 5b36bb618d..cee8b84438 100644 --- a/indra/test/test.cpp +++ b/indra/test/test.cpp @@ -79,7 +79,7 @@ public: RecordToTempFile() : LLError::Recorder(), mTempFile("log", ""), - mFile(mTempFile.getName().c_str()) + mFile(mTempFile.getPath()) { } @@ -97,13 +97,13 @@ public: void reset() { mFile.close(); - mFile.open(mTempFile.getName().c_str()); + mFile.open(mTempFile.getPath()); } void replay(std::ostream& out) { mFile.close(); - llifstream inf(mTempFile.getName().c_str()); + llifstream inf(mTempFile.getPath()); std::string line; while (std::getline(inf, line)) { |
