From 3ca3ea75c333078013914e174564340f894573e2 Mon Sep 17 00:00:00 2001 From: Frederick Martian Date: Sat, 25 Oct 2025 17:08:35 +0200 Subject: Add a new static function LLFile::size() to determine the size of a file_name. Replace LLAPRFile::remove(), LLAPRFile::size() and LLAPRFile::isExist() with according functions from LLFile and retire these LLAPRFile methods and the never used LLAPRFile::rename(), LLAPRFile::makeDir() and LLAPRFile::removeDir() functions. Also clean up remarks about the threading safety of the APRCachePool, which is not used in these locations anymore. --- indra/llcommon/llfile.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'indra/llcommon/llfile.cpp') diff --git a/indra/llcommon/llfile.cpp b/indra/llcommon/llfile.cpp index a539e4fe28..4ef39674c2 100644 --- a/indra/llcommon/llfile.cpp +++ b/indra/llcommon/llfile.cpp @@ -497,6 +497,45 @@ int LLFile::stat(const std::string& filename, llstat* filestatus, int suppress_e return warnif("stat", filename, rc, suppress_error); } +// static +S64 LLFile::size(const std::string& filename, int suppress_error) +{ +#if LL_WINDOWS + std::wstring utf16filename = utf8path_to_wstring(filename); + HANDLE file_handle = CreateFileW(utf16filename.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + if (INVALID_HANDLE_VALUE != file_handle) + { + LARGE_INTEGER file_size; + if (GetFileSizeEx(file_handle, &file_size)) + { + CloseHandle(file_handle); + return file_size.QuadPart; + } + } + // Get last error before calling the CloseHandle() function + int rc = set_errno_from_oserror(GetLastError()); + if (INVALID_HANDLE_VALUE != file_handle) + { + CloseHandle(file_handle); + } +#else + llstat filestatus; + int rc = ::stat(filename.c_str(), &filestatus); + if (rc == 0) + { + if (S_ISREG(filestatus.st_mode) + { + return filestatus.st_size; + } + // We got something else than a file + rc = -1; + errno = EACCES; + } +#endif + warnif("size", filename, rc, suppress_error); + return 0; +} + // static unsigned short LLFile::getattr(const std::string& filename, bool dontFollowSymLink, int suppress_error) { -- cgit v1.3