summaryrefslogtreecommitdiff
path: root/indra/llfilesystem
diff options
context:
space:
mode:
authorAndrey Kleshchev <117672381+akleshchev@users.noreply.github.com>2025-12-11 01:42:52 +0200
committerGitHub <noreply@github.com>2025-12-11 01:42:52 +0200
commitc92b0b74cbd963cd79d1cb7754256b801f1479b1 (patch)
tree5f3cf34559856bdafd950acf0c9a4d6dec59f0bc /indra/llfilesystem
parentdbbce566e7d66c907dde7bd6c4212b0954b9a5e1 (diff)
Revert #4899 "Add more functionality to LLFile and cleanup LLAPRFile"
Interferes with linux work, will be moved to a different branch and applied separately.
Diffstat (limited to 'indra/llfilesystem')
-rw-r--r--[-rwxr-xr-x]indra/llfilesystem/lldir.cpp56
-rw-r--r--[-rwxr-xr-x]indra/llfilesystem/lldir_win32.cpp13
-rw-r--r--[-rwxr-xr-x]indra/llfilesystem/llfilesystem.cpp29
-rw-r--r--indra/llfilesystem/llfilesystem.h4
-rw-r--r--[-rwxr-xr-x]indra/llfilesystem/tests/lldir_test.cpp4
5 files changed, 74 insertions, 32 deletions
diff --git a/indra/llfilesystem/lldir.cpp b/indra/llfilesystem/lldir.cpp
index eb3c2d9909..190539cea5 100755..100644
--- a/indra/llfilesystem/lldir.cpp
+++ b/indra/llfilesystem/lldir.cpp
@@ -30,6 +30,8 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <errno.h>
+#else
+#include <direct.h>
#endif
#include "lldir.h"
@@ -41,6 +43,7 @@
#include "lldiriterator.h"
#include "stringize.h"
#include "llstring.h"
+#include <boost/filesystem.hpp>
#include <boost/bind.hpp>
#include <algorithm>
@@ -90,20 +93,30 @@ LLDir::~LLDir()
std::vector<std::string> LLDir::getFilesInDir(const std::string &dirname)
{
- // Returns a vector of filenames in the directory.
- std::filesystem::path p = LLFile::utf8StringToPath(dirname);
+ //Returns a vector of fullpath filenames.
+
+#ifdef LL_WINDOWS // or BOOST_WINDOWS_API
+ boost::filesystem::path p(ll_convert<std::wstring>(dirname));
+#else
+ boost::filesystem::path p(dirname);
+#endif
+
std::vector<std::string> v;
- std::error_code ec;
- if (std::filesystem::is_directory(p, ec))
+
+ boost::system::error_code ec;
+ if (exists(p, ec) && !ec.failed())
{
- std::filesystem::directory_iterator end_iter;
- for (std::filesystem::directory_iterator dir_itr(p);
- dir_itr != end_iter;
- ++dir_itr)
+ if (is_directory(p, ec) && !ec.failed())
{
- if (std::filesystem::is_regular_file(dir_itr->status()))
+ boost::filesystem::directory_iterator end_iter;
+ for (boost::filesystem::directory_iterator dir_itr(p);
+ dir_itr != end_iter;
+ ++dir_itr)
{
- v.push_back(dir_itr->path().filename().string());
+ if (boost::filesystem::is_regular_file(dir_itr->status()))
+ {
+ v.push_back(dir_itr->path().filename().string());
+ }
}
}
}
@@ -173,23 +186,28 @@ U32 LLDir::deleteDirAndContents(const std::string& dir_name)
//Removes the directory and its contents. Returns number of files deleted.
U32 num_deleted = 0;
- std::filesystem::path dir_path = LLFile::utf8StringToPath(dir_name);
try
{
- if (std::filesystem::is_directory(dir_path))
+#ifdef LL_WINDOWS // or BOOST_WINDOWS_API
+ boost::filesystem::path dir_path(ll_convert<std::wstring>(dir_name));
+#else
+ boost::filesystem::path dir_path(dir_name);
+#endif
+
+ if (boost::filesystem::exists(dir_path))
{
- if (!std::filesystem::is_empty(dir_path))
+ if (!boost::filesystem::is_empty(dir_path))
{ // Directory has content
- num_deleted = (U32)std::filesystem::remove_all(dir_path);
+ num_deleted = (U32)boost::filesystem::remove_all(dir_path);
}
else
{ // Directory is empty
- std::filesystem::remove(dir_path);
+ boost::filesystem::remove(dir_path);
}
}
}
- catch (std::filesystem::filesystem_error &er)
+ catch (boost::filesystem::filesystem_error &er)
{
LL_WARNS() << "Failed to delete " << dir_name << " with error " << er.code().message() << LL_ENDL;
}
@@ -1087,15 +1105,15 @@ 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);
+ LLFile::mkdir(dir_name, 0700);
#else
- llstat dir_stat;
+ struct stat dir_stat;
if(0 != LLFile::stat(dir_name, &dir_stat))
{
S32 stat_rv = errno;
if(ENOENT == stat_rv)
{
- if(0 != LLFile::mkdir(dir_name))
+ if(0 != LLFile::mkdir(dir_name, 0700)) // octal
{
LL_ERRS() << "Unable to create directory: " << dir_name << LL_ENDL;
}
diff --git a/indra/llfilesystem/lldir_win32.cpp b/indra/llfilesystem/lldir_win32.cpp
index 2b478e5dce..58c080c982 100755..100644
--- a/indra/llfilesystem/lldir_win32.cpp
+++ b/indra/llfilesystem/lldir_win32.cpp
@@ -376,7 +376,18 @@ std::string LLDir_Win32::getCurPath()
bool LLDir_Win32::fileExists(const std::string &filename) const
{
- return LLFile::exists(filename);
+ 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;
+ }
}
diff --git a/indra/llfilesystem/llfilesystem.cpp b/indra/llfilesystem/llfilesystem.cpp
index 0c220fe7cf..541266af4f 100755..100644
--- a/indra/llfilesystem/llfilesystem.cpp
+++ b/indra/llfilesystem/llfilesystem.cpp
@@ -77,17 +77,21 @@ 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);
- // not only test for existence but for the file to be not empty
- S64 size = LLFile::size(filename);
- return size > 0;
+ llifstream file(filename, std::ios::binary);
+ if (file.is_open())
+ {
+ file.seekg(0, std::ios::end);
+ return file.tellg() > 0;
+ }
+ return false;
}
// static
-bool LLFileSystem::removeFile(const LLUUID& file_id, const LLAssetType::EType file_type, int suppress_warning /*= 0*/)
+bool LLFileSystem::removeFile(const LLUUID& file_id, const LLAssetType::EType file_type, int suppress_error /*= 0*/)
{
const std::string filename = LLDiskCache::metaDataToFilepath(file_id, file_type);
- LLFile::remove(filename.c_str(), suppress_warning);
+ LLFile::remove(filename.c_str(), suppress_error);
return true;
}
@@ -112,10 +116,19 @@ bool LLFileSystem::renameFile(const LLUUID& old_file_id, const LLAssetType::ETyp
}
// static
-S64 LLFileSystem::getFileSize(const LLUUID& file_id, const LLAssetType::EType file_type)
+S32 LLFileSystem::getFileSize(const LLUUID& file_id, const LLAssetType::EType file_type)
{
const std::string filename = LLDiskCache::metaDataToFilepath(file_id, file_type);
- return LLFile::size(filename);
+
+ 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)
@@ -256,7 +269,7 @@ S32 LLFileSystem::tell() const
S32 LLFileSystem::getSize() const
{
- return (S32)LLFileSystem::getFileSize(mFileID, mFileType);
+ return LLFileSystem::getFileSize(mFileID, mFileType);
}
S32 LLFileSystem::getMaxSize() const
diff --git a/indra/llfilesystem/llfilesystem.h b/indra/llfilesystem/llfilesystem.h
index 7188683e7f..10649b6920 100644
--- a/indra/llfilesystem/llfilesystem.h
+++ b/indra/llfilesystem/llfilesystem.h
@@ -61,10 +61,10 @@ class LLFileSystem
void updateFileAccessTime(const std::string& file_path);
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_warning = 0);
+ static bool removeFile(const LLUUID& file_id, const LLAssetType::EType file_type, int suppress_error = 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 S64 getFileSize(const LLUUID& file_id, const LLAssetType::EType file_type);
+ static S32 getFileSize(const LLUUID& file_id, const LLAssetType::EType file_type);
public:
static const S32 READ;
diff --git a/indra/llfilesystem/tests/lldir_test.cpp b/indra/llfilesystem/tests/lldir_test.cpp
index 17e4ffecf1..13db6fad80 100755..100644
--- a/indra/llfilesystem/tests/lldir_test.cpp
+++ b/indra/llfilesystem/tests/lldir_test.cpp
@@ -558,8 +558,8 @@ namespace tut
LLFile::remove(dir1files[i]);
LLFile::remove(dir2files[i]);
}
- LLFile::remove(dir1);
- LLFile::remove(dir2);
+ LLFile::rmdir(dir1);
+ LLFile::rmdir(dir2);
}
template<> template<>