Skip to content

Commit c92b0b7

Browse files
authored
Revert #4899 "Add more functionality to LLFile and cleanup LLAPRFile"
Interferes with linux work, will be moved to a different branch and applied separately.
1 parent dbbce56 commit c92b0b7

32 files changed

+910
-1610
lines changed

indra/llaudio/llaudiodecodemgr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ bool LLVorbisDecodeState::initDecode()
199199
LL_DEBUGS("AudioEngine") << "Initing decode from vfile: " << mUUID << LL_ENDL;
200200

201201
mInFilep = new LLFileSystem(mUUID, LLAssetType::AT_SOUND);
202-
if (!mInFilep || mInFilep->getSize() <= 0)
202+
if (!mInFilep || !mInFilep->getSize())
203203
{
204204
LL_WARNS("AudioEngine") << "unable to open vorbis source vfile for reading" << LL_ENDL;
205205
delete mInFilep;

indra/llcommon/llapp.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
#endif
3838

3939
#include "llcommon.h"
40-
40+
#include "llapr.h"
4141
#include "llerrorcontrol.h"
4242
#include "llframetimer.h"
4343
#include "lllivefile.h"
@@ -53,8 +53,6 @@
5353
//
5454
// Signal handling
5555
#ifndef LL_WINDOWS
56-
#include "apr_signal.h"
57-
5856
# include <signal.h>
5957
# include <unistd.h> // for fork()
6058
void setup_signals();

indra/llcommon/llapr.cpp

Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,226 @@ S32 LLAPRFile::seek(apr_file_t* file_handle, apr_seek_where_t where, S32 offset)
526526
}
527527
}
528528

529+
//static
530+
S32 LLAPRFile::readEx(const std::string& filename, void *buf, S32 offset, S32 nbytes, LLVolatileAPRPool* pool)
531+
{
532+
LL_PROFILE_ZONE_SCOPED;
533+
//*****************************************
534+
LLAPRFilePoolScope scope(pool);
535+
apr_file_t* file_handle = open(filename, scope.getVolatileAPRPool(), APR_READ|APR_BINARY);
536+
//*****************************************
537+
if (!file_handle)
538+
{
539+
return 0;
540+
}
541+
542+
llassert(offset >= 0);
543+
544+
if (offset > 0)
545+
offset = LLAPRFile::seek(file_handle, APR_SET, offset);
546+
547+
apr_size_t bytes_read;
548+
if (offset < 0)
549+
{
550+
bytes_read = 0;
551+
}
552+
else
553+
{
554+
bytes_read = nbytes ;
555+
apr_status_t s = apr_file_read(file_handle, buf, &bytes_read);
556+
if (s != APR_SUCCESS)
557+
{
558+
LL_WARNS("APR") << " Attempting to read filename: " << filename << LL_ENDL;
559+
ll_apr_warn_status(s);
560+
bytes_read = 0;
561+
}
562+
else
563+
{
564+
llassert_always(bytes_read <= 0x7fffffff);
565+
}
566+
}
567+
568+
//*****************************************
569+
close(file_handle) ;
570+
//*****************************************
571+
return (S32)bytes_read;
572+
}
573+
574+
//static
575+
S32 LLAPRFile::writeEx(const std::string& filename, const void *buf, S32 offset, S32 nbytes, LLVolatileAPRPool* pool)
576+
{
577+
LL_PROFILE_ZONE_SCOPED;
578+
apr_int32_t flags = APR_CREATE|APR_WRITE|APR_BINARY;
579+
if (offset < 0)
580+
{
581+
flags |= APR_APPEND;
582+
offset = 0;
583+
}
584+
585+
//*****************************************
586+
LLAPRFilePoolScope scope(pool);
587+
apr_file_t* file_handle = open(filename, scope.getVolatileAPRPool(), flags);
588+
//*****************************************
589+
if (!file_handle)
590+
{
591+
return 0;
592+
}
593+
594+
if (offset > 0)
595+
{
596+
offset = LLAPRFile::seek(file_handle, APR_SET, offset);
597+
}
598+
599+
apr_size_t bytes_written;
600+
if (offset < 0)
601+
{
602+
bytes_written = 0;
603+
}
604+
else
605+
{
606+
bytes_written = nbytes ;
607+
apr_status_t s = apr_file_write(file_handle, buf, &bytes_written);
608+
if (s != APR_SUCCESS)
609+
{
610+
LL_WARNS("APR") << "Attempting to write filename: " << filename << LL_ENDL;
611+
if (APR_STATUS_IS_ENOSPC(s))
612+
{
613+
LLApp::notifyOutOfDiskSpace();
614+
}
615+
ll_apr_warn_status(s);
616+
bytes_written = 0;
617+
}
618+
else
619+
{
620+
llassert_always(bytes_written <= 0x7fffffff);
621+
}
622+
}
623+
624+
//*****************************************
625+
LLAPRFile::close(file_handle);
626+
//*****************************************
627+
628+
return (S32)bytes_written;
629+
}
630+
631+
//static
632+
bool LLAPRFile::remove(const std::string& filename, LLVolatileAPRPool* pool)
633+
{
634+
apr_status_t s;
635+
636+
LLAPRFilePoolScope scope(pool);
637+
s = apr_file_remove(filename.c_str(), scope.getVolatileAPRPool());
638+
639+
if (s != APR_SUCCESS)
640+
{
641+
ll_apr_warn_status(s);
642+
LL_WARNS("APR") << " Attempting to remove filename: " << filename << LL_ENDL;
643+
return false;
644+
}
645+
return true;
646+
}
647+
648+
//static
649+
bool LLAPRFile::rename(const std::string& filename, const std::string& newname, LLVolatileAPRPool* pool)
650+
{
651+
apr_status_t s;
652+
653+
LLAPRFilePoolScope scope(pool);
654+
s = apr_file_rename(filename.c_str(), newname.c_str(), scope.getVolatileAPRPool());
655+
656+
if (s != APR_SUCCESS)
657+
{
658+
ll_apr_warn_status(s);
659+
LL_WARNS("APR") << " Attempting to rename filename: " << filename << LL_ENDL;
660+
return false;
661+
}
662+
return true;
663+
}
664+
665+
//static
666+
bool LLAPRFile::isExist(const std::string& filename, LLVolatileAPRPool* pool, apr_int32_t flags)
667+
{
668+
apr_file_t* apr_file;
669+
apr_status_t s;
670+
671+
LLAPRFilePoolScope scope(pool);
672+
s = apr_file_open(&apr_file, filename.c_str(), flags, APR_OS_DEFAULT, scope.getVolatileAPRPool());
673+
674+
if (s != APR_SUCCESS || !apr_file)
675+
{
676+
return false;
677+
}
678+
else
679+
{
680+
apr_file_close(apr_file) ;
681+
return true;
682+
}
683+
}
684+
685+
//static
686+
S32 LLAPRFile::size(const std::string& filename, LLVolatileAPRPool* pool)
687+
{
688+
apr_file_t* apr_file;
689+
apr_finfo_t info;
690+
apr_status_t s;
691+
692+
LLAPRFilePoolScope scope(pool);
693+
s = apr_file_open(&apr_file, filename.c_str(), APR_READ, APR_OS_DEFAULT, scope.getVolatileAPRPool());
694+
695+
if (s != APR_SUCCESS || !apr_file)
696+
{
697+
return 0;
698+
}
699+
else
700+
{
701+
apr_status_t s = apr_file_info_get(&info, APR_FINFO_SIZE, apr_file);
702+
703+
apr_file_close(apr_file) ;
704+
705+
if (s == APR_SUCCESS)
706+
{
707+
return (S32)info.size;
708+
}
709+
else
710+
{
711+
return 0;
712+
}
713+
}
714+
}
715+
716+
//static
717+
bool LLAPRFile::makeDir(const std::string& dirname, LLVolatileAPRPool* pool)
718+
{
719+
apr_status_t s;
720+
721+
LLAPRFilePoolScope scope(pool);
722+
s = apr_dir_make(dirname.c_str(), APR_FPROT_OS_DEFAULT, scope.getVolatileAPRPool());
723+
724+
if (s != APR_SUCCESS)
725+
{
726+
ll_apr_warn_status(s);
727+
LL_WARNS("APR") << " Attempting to make directory: " << dirname << LL_ENDL;
728+
return false;
729+
}
730+
return true;
731+
}
732+
733+
//static
734+
bool LLAPRFile::removeDir(const std::string& dirname, LLVolatileAPRPool* pool)
735+
{
736+
apr_status_t s;
737+
738+
LLAPRFilePoolScope scope(pool);
739+
s = apr_file_remove(dirname.c_str(), scope.getVolatileAPRPool());
740+
741+
if (s != APR_SUCCESS)
742+
{
743+
ll_apr_warn_status(s);
744+
LL_WARNS("APR") << " Attempting to remove directory: " << dirname << LL_ENDL;
745+
return false;
746+
}
747+
return true;
748+
}
529749
//
530750
//end of static components of LLAPRFile
531751
//*******************************************************************************************************************************

indra/llcommon/llapr.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@
3535

3636
#include "llwin32headers.h"
3737
#include "apr_thread_proc.h"
38+
#include "apr_getopt.h"
39+
#include "apr_signal.h"
40+
41+
#include "llstring.h"
42+
43+
#include "mutex.h"
3844

3945
struct apr_dso_handle_t;
4046
/**
@@ -178,7 +184,20 @@ class LL_COMMON_API LLAPRFile
178184
static apr_file_t* open(const std::string& filename, apr_pool_t* apr_pool, apr_int32_t flags);
179185
static apr_status_t close(apr_file_t* file) ;
180186
static S32 seek(apr_file_t* file, apr_seek_where_t where, S32 offset);
187+
public:
188+
// returns false if failure:
189+
static bool remove(const std::string& filename, LLVolatileAPRPool* pool = NULL);
190+
static bool rename(const std::string& filename, const std::string& newname, LLVolatileAPRPool* pool = NULL);
191+
static bool isExist(const std::string& filename, LLVolatileAPRPool* pool = NULL, apr_int32_t flags = APR_READ);
192+
static S32 size(const std::string& filename, LLVolatileAPRPool* pool = NULL);
193+
static bool makeDir(const std::string& dirname, LLVolatileAPRPool* pool = NULL);
194+
static bool removeDir(const std::string& dirname, LLVolatileAPRPool* pool = NULL);
195+
196+
// Returns bytes read/written, 0 if read/write fails:
197+
static S32 readEx(const std::string& filename, void *buf, S32 offset, S32 nbytes, LLVolatileAPRPool* pool = NULL);
198+
static S32 writeEx(const std::string& filename, const void *buf, S32 offset, S32 nbytes, LLVolatileAPRPool* pool = NULL); // offset<0 means append
181199
//*******************************************************************************************************************************
182200
};
183201

202+
184203
#endif // LL_LLAPR_H

indra/llcommon/llerror.cpp

100755100644
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,9 +435,13 @@ namespace
435435

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

438-
if (!LLFile::isfile(file))
439-
{
440-
file = app_dir + "/logcontrol.xml";
438+
llstat stat_info;
439+
if (LLFile::stat(file, &stat_info)) {
440+
// NB: stat returns non-zero if it can't read the file, for example
441+
// if it doesn't exist. LLFile has no better abstraction for
442+
// testing for file existence.
443+
444+
file = app_dir + "/logcontrol.xml";
441445
}
442446
return * new LogControlFile(file);
443447
// NB: This instance is never freed

0 commit comments

Comments
 (0)