Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
a82a962
Revert "Fix typo found by Copilot"
akleshchev Dec 10, 2025
86c64d7
Revert "Generate error if the asset upload is bigger than INT_MAX as …
akleshchev Dec 10, 2025
1253f14
Revert "Make function documentation more clear about the negative off…
akleshchev Dec 10, 2025
3fda61a
Revert "Update indra/test/llfile_tut.cpp"
akleshchev Dec 10, 2025
b6236a8
Revert "Update indra/llcommon/llfile.h"
akleshchev Dec 10, 2025
7f0e45e
Revert "Fix typo and check for valid opened file"
akleshchev Dec 10, 2025
044be35
Revert "Add header include for apr_signal.h that was removed from lla…
akleshchev Dec 10, 2025
b597e92
Revert "Remove chatty warning message when checking for existence of …
akleshchev Dec 10, 2025
a2fd544
Revert "Improve comment and remove superfluous error_code check"
akleshchev Dec 10, 2025
721eb59
Revert "Cleanup unused LLAPRFile functions"
akleshchev Dec 10, 2025
cbd17cd
Revert "Incorporate some of the comment improvements suggested by Cop…
akleshchev Dec 10, 2025
e9674e9
Revert "Remove commented out old function calls"
akleshchev Dec 10, 2025
8266661
Revert "Fix several typos and comments"
akleshchev Dec 10, 2025
bb9ed60
Revert "The returned vector should only contain filenames, not the en…
akleshchev Dec 10, 2025
33b83c2
Revert "- Improve documentation of LLFile functions and methods - Imp…
akleshchev Dec 10, 2025
17387d8
Revert "Add LLFile unit tests"
akleshchev Dec 10, 2025
f8e9b7a
Revert "Refactoring of LLFile class to support additional methods"
akleshchev Dec 10, 2025
891e0b6
Revert "Clarify some documentation and add an LLFile:read() and LLFil…
akleshchev Dec 10, 2025
fe36d4d
Revert "Add a new static function LLFile::size() to determine the siz…
akleshchev Dec 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion indra/llaudio/llaudiodecodemgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ bool LLVorbisDecodeState::initDecode()
LL_DEBUGS("AudioEngine") << "Initing decode from vfile: " << mUUID << LL_ENDL;

mInFilep = new LLFileSystem(mUUID, LLAssetType::AT_SOUND);
if (!mInFilep || mInFilep->getSize() <= 0)
if (!mInFilep || !mInFilep->getSize())
{
LL_WARNS("AudioEngine") << "unable to open vorbis source vfile for reading" << LL_ENDL;
delete mInFilep;
Expand Down
4 changes: 1 addition & 3 deletions indra/llcommon/llapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#endif

#include "llcommon.h"

#include "llapr.h"
#include "llerrorcontrol.h"
#include "llframetimer.h"
#include "lllivefile.h"
Expand All @@ -53,8 +53,6 @@
//
// Signal handling
#ifndef LL_WINDOWS
#include "apr_signal.h"

# include <signal.h>
# include <unistd.h> // for fork()
void setup_signals();
Expand Down
220 changes: 220 additions & 0 deletions indra/llcommon/llapr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,226 @@ S32 LLAPRFile::seek(apr_file_t* file_handle, apr_seek_where_t where, S32 offset)
}
}

//static
S32 LLAPRFile::readEx(const std::string& filename, void *buf, S32 offset, S32 nbytes, LLVolatileAPRPool* pool)
{
LL_PROFILE_ZONE_SCOPED;
//*****************************************
LLAPRFilePoolScope scope(pool);
apr_file_t* file_handle = open(filename, scope.getVolatileAPRPool(), APR_READ|APR_BINARY);
//*****************************************
if (!file_handle)
{
return 0;
}

llassert(offset >= 0);

if (offset > 0)
offset = LLAPRFile::seek(file_handle, APR_SET, offset);

apr_size_t bytes_read;
if (offset < 0)
{
bytes_read = 0;
}
else
{
bytes_read = nbytes ;
apr_status_t s = apr_file_read(file_handle, buf, &bytes_read);
if (s != APR_SUCCESS)
{
LL_WARNS("APR") << " Attempting to read filename: " << filename << LL_ENDL;
ll_apr_warn_status(s);
bytes_read = 0;
}
else
{
llassert_always(bytes_read <= 0x7fffffff);
}
}

//*****************************************
close(file_handle) ;
//*****************************************
return (S32)bytes_read;
}

//static
S32 LLAPRFile::writeEx(const std::string& filename, const void *buf, S32 offset, S32 nbytes, LLVolatileAPRPool* pool)
{
LL_PROFILE_ZONE_SCOPED;
apr_int32_t flags = APR_CREATE|APR_WRITE|APR_BINARY;
if (offset < 0)
{
flags |= APR_APPEND;
offset = 0;
}

//*****************************************
LLAPRFilePoolScope scope(pool);
apr_file_t* file_handle = open(filename, scope.getVolatileAPRPool(), flags);
//*****************************************
if (!file_handle)
{
return 0;
}

if (offset > 0)
{
offset = LLAPRFile::seek(file_handle, APR_SET, offset);
}

apr_size_t bytes_written;
if (offset < 0)
{
bytes_written = 0;
}
else
{
bytes_written = nbytes ;
apr_status_t s = apr_file_write(file_handle, buf, &bytes_written);
if (s != APR_SUCCESS)
{
LL_WARNS("APR") << "Attempting to write filename: " << filename << LL_ENDL;
if (APR_STATUS_IS_ENOSPC(s))
{
LLApp::notifyOutOfDiskSpace();
}
ll_apr_warn_status(s);
bytes_written = 0;
}
else
{
llassert_always(bytes_written <= 0x7fffffff);
}
}

//*****************************************
LLAPRFile::close(file_handle);
//*****************************************

return (S32)bytes_written;
}

//static
bool LLAPRFile::remove(const std::string& filename, LLVolatileAPRPool* pool)
{
apr_status_t s;

LLAPRFilePoolScope scope(pool);
s = apr_file_remove(filename.c_str(), scope.getVolatileAPRPool());

if (s != APR_SUCCESS)
{
ll_apr_warn_status(s);
LL_WARNS("APR") << " Attempting to remove filename: " << filename << LL_ENDL;
return false;
}
return true;
}

//static
bool LLAPRFile::rename(const std::string& filename, const std::string& newname, LLVolatileAPRPool* pool)
{
apr_status_t s;

LLAPRFilePoolScope scope(pool);
s = apr_file_rename(filename.c_str(), newname.c_str(), scope.getVolatileAPRPool());

if (s != APR_SUCCESS)
{
ll_apr_warn_status(s);
LL_WARNS("APR") << " Attempting to rename filename: " << filename << LL_ENDL;
return false;
}
return true;
}

//static
bool LLAPRFile::isExist(const std::string& filename, LLVolatileAPRPool* pool, apr_int32_t flags)
{
apr_file_t* apr_file;
apr_status_t s;

LLAPRFilePoolScope scope(pool);
s = apr_file_open(&apr_file, filename.c_str(), flags, APR_OS_DEFAULT, scope.getVolatileAPRPool());

if (s != APR_SUCCESS || !apr_file)
{
return false;
}
else
{
apr_file_close(apr_file) ;
return true;
}
}

//static
S32 LLAPRFile::size(const std::string& filename, LLVolatileAPRPool* pool)
{
apr_file_t* apr_file;
apr_finfo_t info;
apr_status_t s;

LLAPRFilePoolScope scope(pool);
s = apr_file_open(&apr_file, filename.c_str(), APR_READ, APR_OS_DEFAULT, scope.getVolatileAPRPool());

if (s != APR_SUCCESS || !apr_file)
{
return 0;
}
else
{
apr_status_t s = apr_file_info_get(&info, APR_FINFO_SIZE, apr_file);

apr_file_close(apr_file) ;

if (s == APR_SUCCESS)
{
return (S32)info.size;
}
else
{
return 0;
}
}
}

//static
bool LLAPRFile::makeDir(const std::string& dirname, LLVolatileAPRPool* pool)
{
apr_status_t s;

LLAPRFilePoolScope scope(pool);
s = apr_dir_make(dirname.c_str(), APR_FPROT_OS_DEFAULT, scope.getVolatileAPRPool());

if (s != APR_SUCCESS)
{
ll_apr_warn_status(s);
LL_WARNS("APR") << " Attempting to make directory: " << dirname << LL_ENDL;
return false;
}
return true;
}

//static
bool LLAPRFile::removeDir(const std::string& dirname, LLVolatileAPRPool* pool)
{
apr_status_t s;

LLAPRFilePoolScope scope(pool);
s = apr_file_remove(dirname.c_str(), scope.getVolatileAPRPool());

if (s != APR_SUCCESS)
{
ll_apr_warn_status(s);
LL_WARNS("APR") << " Attempting to remove directory: " << dirname << LL_ENDL;
return false;
}
return true;
}
//
//end of static components of LLAPRFile
//*******************************************************************************************************************************
Expand Down
19 changes: 19 additions & 0 deletions indra/llcommon/llapr.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@

#include "llwin32headers.h"
#include "apr_thread_proc.h"
#include "apr_getopt.h"
#include "apr_signal.h"

#include "llstring.h"

#include "mutex.h"

struct apr_dso_handle_t;
/**
Expand Down Expand Up @@ -178,7 +184,20 @@ class LL_COMMON_API LLAPRFile
static apr_file_t* open(const std::string& filename, apr_pool_t* apr_pool, apr_int32_t flags);
static apr_status_t close(apr_file_t* file) ;
static S32 seek(apr_file_t* file, apr_seek_where_t where, S32 offset);
public:
// returns false if failure:
static bool remove(const std::string& filename, LLVolatileAPRPool* pool = NULL);
static bool rename(const std::string& filename, const std::string& newname, LLVolatileAPRPool* pool = NULL);
static bool isExist(const std::string& filename, LLVolatileAPRPool* pool = NULL, apr_int32_t flags = APR_READ);
static S32 size(const std::string& filename, LLVolatileAPRPool* pool = NULL);
static bool makeDir(const std::string& dirname, LLVolatileAPRPool* pool = NULL);
static bool removeDir(const std::string& dirname, LLVolatileAPRPool* pool = NULL);

// Returns bytes read/written, 0 if read/write fails:
static S32 readEx(const std::string& filename, void *buf, S32 offset, S32 nbytes, LLVolatileAPRPool* pool = NULL);
static S32 writeEx(const std::string& filename, const void *buf, S32 offset, S32 nbytes, LLVolatileAPRPool* pool = NULL); // offset<0 means append
//*******************************************************************************************************************************
};


#endif // LL_LLAPR_H
10 changes: 7 additions & 3 deletions indra/llcommon/llerror.cpp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -435,9 +435,13 @@ namespace

std::string file = user_dir + "/logcontrol-dev.xml";

if (!LLFile::isfile(file))
{
file = app_dir + "/logcontrol.xml";
llstat stat_info;
if (LLFile::stat(file, &stat_info)) {
// NB: stat returns non-zero if it can't read the file, for example
// if it doesn't exist. LLFile has no better abstraction for
// testing for file existence.

file = app_dir + "/logcontrol.xml";
}
return * new LogControlFile(file);
// NB: This instance is never freed
Expand Down
Loading