The file drivers are one of the few things that can be accessed before LOG is set up, guard all accesses.
This commit is contained in:
@@ -23,6 +23,8 @@
|
||||
#include <zlib.h>
|
||||
#endif
|
||||
|
||||
#define Trace(args...) if( LOG ) LOG->Trace( args ); else fprintf( stderr, args )
|
||||
|
||||
RageFileObjInflate::RageFileObjInflate( RageFileBasic *pFile, int iUncompressedSize )
|
||||
{
|
||||
m_bFileOwned = false;
|
||||
@@ -37,7 +39,7 @@ RageFileObjInflate::RageFileObjInflate( RageFileBasic *pFile, int iUncompressedS
|
||||
if( err == Z_MEM_ERROR )
|
||||
RageException::Throw( "inflateInit2( %i ): out of memory.", -MAX_WBITS );
|
||||
if( err != Z_OK )
|
||||
LOG->Trace( "Huh? inflateInit2() err = %i", err );
|
||||
Trace( "Huh? inflateInit2() err = %i", err );
|
||||
|
||||
decomp_buf_ptr = decomp_buf;
|
||||
m_iFilePos = 0;
|
||||
@@ -73,7 +75,7 @@ RageFileObjInflate::~RageFileObjInflate()
|
||||
|
||||
int err = inflateEnd( m_pInflate );
|
||||
if( err != Z_OK )
|
||||
LOG->Trace( "Huh? inflateEnd() err = %i", err );
|
||||
Trace( "Huh? inflateEnd() err = %i", err );
|
||||
|
||||
delete m_pInflate;
|
||||
}
|
||||
@@ -128,7 +130,7 @@ int RageFileObjInflate::ReadInternal( void *buf, size_t bytes )
|
||||
case Z_OK:
|
||||
break;
|
||||
default:
|
||||
LOG->Trace( "Huh? inflate err %i", err );
|
||||
Trace( "Huh? inflate err %i", err );
|
||||
}
|
||||
|
||||
const int used = (char *)m_pInflate->next_in - decomp_buf_ptr;
|
||||
@@ -205,7 +207,7 @@ RageFileObjDeflate::RageFileObjDeflate( RageFileBasic *pFile )
|
||||
if( err == Z_MEM_ERROR )
|
||||
RageException::Throw( "inflateInit2( %i ): out of memory.", -MAX_WBITS );
|
||||
if( err != Z_OK )
|
||||
LOG->Trace( "Huh? inflateInit2() err = %i", err );
|
||||
Trace( "Huh? inflateInit2() err = %i", err );
|
||||
|
||||
}
|
||||
|
||||
@@ -218,7 +220,7 @@ RageFileObjDeflate::~RageFileObjDeflate()
|
||||
|
||||
int err = deflateEnd( m_pDeflate );
|
||||
if( err != Z_OK )
|
||||
LOG->Trace( "Huh? deflateEnd() err = %i", err );
|
||||
Trace( "Huh? deflateEnd() err = %i", err );
|
||||
|
||||
delete m_pDeflate;
|
||||
}
|
||||
|
||||
@@ -22,6 +22,9 @@
|
||||
#include <io.h>
|
||||
#endif
|
||||
|
||||
#define Trace(args...) if( LOG ) LOG->Trace( args ); else fprintf( stderr, args )
|
||||
#define Warn(args...) if( LOG ) LOG->Warn( args ); else fprintf( stderr, args )
|
||||
|
||||
static struct FileDriverEntry_DIR: public FileDriverEntry
|
||||
{
|
||||
FileDriverEntry_DIR(): FileDriverEntry( "DIR" ) { }
|
||||
@@ -143,10 +146,10 @@ bool RageFileDriverDirect::Move( const RString &sOldPath_, const RString &sNewPa
|
||||
CreateDirectories( m_sRoot + sDir );
|
||||
}
|
||||
|
||||
LOG->Trace("rename \"%s\" -> \"%s\"", (m_sRoot + sOldPath).c_str(), (m_sRoot + sNewPath).c_str() );
|
||||
Trace("rename \"%s\" -> \"%s\"", (m_sRoot + sOldPath).c_str(), (m_sRoot + sNewPath).c_str() );
|
||||
if( DoRename(m_sRoot + sOldPath, m_sRoot + sNewPath) == -1 )
|
||||
{
|
||||
LOG->Warn( "rename(%s,%s) failed: %s", (m_sRoot + sOldPath).c_str(), (m_sRoot + sNewPath).c_str(), strerror(errno) );
|
||||
Warn( "rename(%s,%s) failed: %s", (m_sRoot + sOldPath).c_str(), (m_sRoot + sNewPath).c_str(), strerror(errno) );
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -160,20 +163,20 @@ bool RageFileDriverDirect::Remove( const RString &sPath_ )
|
||||
switch( this->GetFileType(sPath) )
|
||||
{
|
||||
case RageFileManager::TYPE_FILE:
|
||||
LOG->Trace("remove '%s'", (m_sRoot + sPath).c_str());
|
||||
Trace("remove '%s'", (m_sRoot + sPath).c_str());
|
||||
if( DoRemove(m_sRoot + sPath) == -1 )
|
||||
{
|
||||
LOG->Warn( "remove(%s) failed: %s", (m_sRoot + sPath).c_str(), strerror(errno) );
|
||||
Warn( "remove(%s) failed: %s", (m_sRoot + sPath).c_str(), strerror(errno) );
|
||||
return false;
|
||||
}
|
||||
FDB->DelFile( sPath );
|
||||
return true;
|
||||
|
||||
case RageFileManager::TYPE_DIR:
|
||||
LOG->Trace("rmdir '%s'", (m_sRoot + sPath).c_str());
|
||||
Trace("rmdir '%s'", (m_sRoot + sPath).c_str());
|
||||
if( DoRmdir(m_sRoot + sPath) == -1 )
|
||||
{
|
||||
LOG->Warn( "rmdir(%s) failed: %s", (m_sRoot + sPath).c_str(), strerror(errno) );
|
||||
Warn( "rmdir(%s) failed: %s", (m_sRoot + sPath).c_str(), strerror(errno) );
|
||||
return false;
|
||||
}
|
||||
FDB->DelFile( sPath );
|
||||
@@ -237,7 +240,7 @@ bool RageFileObjDirect::FinalFlush()
|
||||
/* Force a kernel buffer flush. */
|
||||
if( fsync( m_iFD ) == -1 )
|
||||
{
|
||||
LOG->Warn( "Error synchronizing %s: %s", this->m_sPath.c_str(), strerror(errno) );
|
||||
Warn( "Error synchronizing %s: %s", this->m_sPath.c_str(), strerror(errno) );
|
||||
SetError( strerror(errno) );
|
||||
return false;
|
||||
}
|
||||
@@ -247,14 +250,14 @@ bool RageFileObjDirect::FinalFlush()
|
||||
int dirfd = open( Dirname(m_sPath), O_RDONLY );
|
||||
if( dirfd == -1 )
|
||||
{
|
||||
LOG->Warn( "Error synchronizing open(%s dir): %s", this->m_sPath.c_str(), strerror(errno) );
|
||||
Warn( "Error synchronizing open(%s dir): %s", this->m_sPath.c_str(), strerror(errno) );
|
||||
SetError( strerror(errno) );
|
||||
return false;
|
||||
}
|
||||
|
||||
if( fsync( dirfd ) == -1 )
|
||||
{
|
||||
LOG->Warn( "Error synchronizing fsync(%s dir): %s", this->m_sPath.c_str(), strerror(errno) );
|
||||
Warn( "Error synchronizing fsync(%s dir): %s", this->m_sPath.c_str(), strerror(errno) );
|
||||
SetError( strerror(errno) );
|
||||
close( dirfd );
|
||||
return false;
|
||||
@@ -274,7 +277,7 @@ RageFileObjDirect::~RageFileObjDirect()
|
||||
{
|
||||
if( close( m_iFD ) == -1 )
|
||||
{
|
||||
LOG->Warn( "Error closing %s: %s", this->m_sPath.c_str(), strerror(errno) );
|
||||
Warn( "Error closing %s: %s", this->m_sPath.c_str(), strerror(errno) );
|
||||
SetError( strerror(errno) );
|
||||
bFailed = true;
|
||||
}
|
||||
@@ -309,13 +312,13 @@ RageFileObjDirect::~RageFileObjDirect()
|
||||
/* We failed. */
|
||||
int err = GetLastError();
|
||||
const RString error = werr_ssprintf( err, "Error renaming \"%s\" to \"%s\"", sOldPath.c_str(), sNewPath.c_str() );
|
||||
LOG->Warn( "%s", error.c_str() );
|
||||
Warn( "%s", error.c_str() );
|
||||
SetError( error );
|
||||
break;
|
||||
#else
|
||||
if( rename( sOldPath, sNewPath ) == -1 )
|
||||
{
|
||||
LOG->Warn( "Error renaming \"%s\" to \"%s\": %s",
|
||||
Warn( "Error renaming \"%s\" to \"%s\": %s",
|
||||
sOldPath.c_str(), sNewPath.c_str(), strerror(errno) );
|
||||
SetError( strerror(errno) );
|
||||
break;
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
#include <io.h>
|
||||
#endif
|
||||
|
||||
#define Warn(args...) if( LOG ) LOG->Warn( args ); else fprintf( stderr, args )
|
||||
|
||||
#if defined(_XBOX)
|
||||
/* Wrappers for low-level file functions, to work around Xbox issues: */
|
||||
int DoMkdir( const RString &sPath, int perm )
|
||||
@@ -150,14 +152,15 @@ bool CreateDirectories( RString Path )
|
||||
* returning ENOENT instead of EEXIST. */
|
||||
/* I can't reproduce this anymore. If we get ENOENT, log it but keep
|
||||
* going. */
|
||||
if( errno == ENOENT && LOG )
|
||||
LOG->Warn("Couldn't create %s: %s", curpath.c_str(), strerror(errno) );
|
||||
if( errno == ENOENT )
|
||||
Warn( "Couldn't create %s: %s", curpath.c_str(), strerror(errno) );
|
||||
if( errno == EEXIST || errno == ENOENT )
|
||||
continue; // we expect to see these errors
|
||||
|
||||
// XXX: This doesn't make sense. Why do we return if LOG is present here?
|
||||
if( LOG )
|
||||
{
|
||||
LOG->Warn("Couldn't create %s: %s", curpath.c_str(), strerror(errno) );
|
||||
Warn( "Couldn't create %s: %s", curpath.c_str(), strerror(errno) );
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -166,8 +169,7 @@ bool CreateDirectories( RString Path )
|
||||
DoStat( curpath, &st );
|
||||
if( !(st.st_mode & S_IFDIR) )
|
||||
{
|
||||
if( LOG )
|
||||
LOG->Warn("Couldn't create %s: path exists and is not a directory", curpath.c_str() );
|
||||
Warn( "Couldn't create %s: path exists and is not a directory", curpath.c_str() );
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -268,9 +270,8 @@ void DirectFilenameDB::PopulateFileSet( FileSet &fs, const RString &path )
|
||||
continue;
|
||||
|
||||
/* Huh? */
|
||||
if( LOG )
|
||||
LOG->Warn( "Got file '%s' in '%s' from list, but can't stat? (%s)",
|
||||
pEnt->d_name, sPath.c_str(), strerror(errno) );
|
||||
Warn( "Got file '%s' in '%s' from list, but can't stat? (%s)",
|
||||
pEnt->d_name, sPath.c_str(), strerror(errno) );
|
||||
continue;
|
||||
}
|
||||
else
|
||||
|
||||
@@ -49,6 +49,8 @@
|
||||
#include "RageLog.h"
|
||||
#include <errno.h>
|
||||
|
||||
#define Warn(args...) if( LOG ) LOG->Warn( args ); else fprintf( stderr, args )
|
||||
|
||||
enum ThreadRequest
|
||||
{
|
||||
REQ_OPEN,
|
||||
@@ -157,7 +159,7 @@ ThreadedFileWorker::ThreadedFileWorker( RString sPath ):
|
||||
/* Grab a reference to the child driver. We'll operate on it directly. */
|
||||
m_pChildDriver = FILEMAN->GetFileDriver( sPath );
|
||||
if( m_pChildDriver == NULL )
|
||||
LOG->Warn( "ThreadedFileWorker: Mountpoint \"%s\" not found", sPath.c_str() );
|
||||
Warn( "ThreadedFileWorker: Mountpoint \"%s\" not found", sPath.c_str() );
|
||||
|
||||
m_pResultFile = NULL;
|
||||
m_pRequestFile = NULL;
|
||||
@@ -862,7 +864,7 @@ bool RageFileDriverTimeout::Move( const RString &sOldPath, const RString &sNewPa
|
||||
int iRet = m_pWorker->Move( sOldPath, sNewPath );
|
||||
if( iRet == -1 )
|
||||
{
|
||||
LOG->Warn( "RageFileDriverTimeout::Move(%s,%s) failed", sOldPath.c_str(), sNewPath.c_str() );
|
||||
Warn( "RageFileDriverTimeout::Move(%s,%s) failed", sOldPath.c_str(), sNewPath.c_str() );
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -874,7 +876,7 @@ bool RageFileDriverTimeout::Remove( const RString &sPath )
|
||||
int iRet = m_pWorker->Remove( sPath );
|
||||
if( iRet == -1 )
|
||||
{
|
||||
LOG->Warn( "RageFileDriverTimeout::Remove(%s) failed", sPath.c_str() );
|
||||
Warn( "RageFileDriverTimeout::Remove(%s) failed", sPath.c_str() );
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
#include "RageUtil_FileDB.h"
|
||||
#include <cerrno>
|
||||
|
||||
#define Warn(args...) if( LOG ) LOG->Warn( args ); else fprintf( stderr, args )
|
||||
|
||||
static struct FileDriverEntry_ZIP: public FileDriverEntry
|
||||
{
|
||||
FileDriverEntry_ZIP(): FileDriverEntry( "ZIP" ) { }
|
||||
@@ -48,7 +50,7 @@ bool RageFileDriverZip::Load( const RString &sPath )
|
||||
|
||||
if( !pFile->Open(sPath) )
|
||||
{
|
||||
LOG->Warn( "Couldn't open %s: %s", sPath.c_str(), pFile->GetError().c_str() );
|
||||
Warn( "Couldn't open %s: %s", sPath.c_str(), pFile->GetError().c_str() );
|
||||
delete pFile;
|
||||
return false;
|
||||
}
|
||||
@@ -85,7 +87,7 @@ bool RageFileDriverZip::ReadEndCentralRecord( int &iTotalEntries, int &iCentralD
|
||||
|
||||
if( sError != "" )
|
||||
{
|
||||
LOG->Warn( "%s: %s", m_sPath.c_str(), sError.c_str() );
|
||||
Warn( "%s: %s", m_sPath.c_str(), sError.c_str() );
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -110,7 +112,7 @@ bool RageFileDriverZip::SeekToEndCentralRecord()
|
||||
int iGot = m_pZip->Read( buf, sizeof(buf) );
|
||||
if( iGot == -1 )
|
||||
{
|
||||
LOG->Warn( "%s: %s", m_sPath.c_str(), m_pZip->GetError().c_str() );
|
||||
Warn( "%s: %s", m_sPath.c_str(), m_pZip->GetError().c_str() );
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -131,7 +133,7 @@ bool RageFileDriverZip::ParseZipfile()
|
||||
{
|
||||
if( !SeekToEndCentralRecord() )
|
||||
{
|
||||
LOG->Warn( "Couldn't open %s: couldn't find end of central directory record", m_sPath.c_str() );
|
||||
Warn( "Couldn't open %s: couldn't find end of central directory record", m_sPath.c_str() );
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -160,7 +162,7 @@ bool RageFileDriverZip::ParseZipfile()
|
||||
}
|
||||
|
||||
if( m_pFiles.size() == 0 )
|
||||
LOG->Warn( "%s: no files found in central file header", m_sPath.c_str() );
|
||||
Warn( "%s: no files found in central file header", m_sPath.c_str() );
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -171,7 +173,7 @@ int RageFileDriverZip::ProcessCdirFileHdr( FileInfo &info )
|
||||
RString sSig = FileReading::ReadString( *m_pZip, 4, sError );
|
||||
if( sSig != "\x50\x4B\x01\x02" )
|
||||
{
|
||||
LOG->Warn( "%s: central directory record signature not found", m_sPath.c_str() );
|
||||
Warn( "%s: central directory record signature not found", m_sPath.c_str() );
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -196,7 +198,7 @@ int RageFileDriverZip::ProcessCdirFileHdr( FileInfo &info )
|
||||
/* Check for errors before reading variable-length fields. */
|
||||
if( sError != "" )
|
||||
{
|
||||
LOG->Warn( "%s: %s", m_sPath.c_str(), sError.c_str() );
|
||||
Warn( "%s: %s", m_sPath.c_str(), sError.c_str() );
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -206,7 +208,7 @@ int RageFileDriverZip::ProcessCdirFileHdr( FileInfo &info )
|
||||
|
||||
if( sError != "" )
|
||||
{
|
||||
LOG->Warn( "%s: %s", m_sPath.c_str(), sError.c_str() );
|
||||
Warn( "%s: %s", m_sPath.c_str(), sError.c_str() );
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -214,7 +216,7 @@ int RageFileDriverZip::ProcessCdirFileHdr( FileInfo &info )
|
||||
* file pointer in the middle of a record. */
|
||||
if( iGeneralPurpose & 1 )
|
||||
{
|
||||
LOG->Warn( "Skipped encrypted \"%s\" in \"%s\"", info.m_sName.c_str(), m_sPath.c_str() );
|
||||
Warn( "Skipped encrypted \"%s\" in \"%s\"", info.m_sName.c_str(), m_sPath.c_str() );
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -233,7 +235,7 @@ int RageFileDriverZip::ProcessCdirFileHdr( FileInfo &info )
|
||||
|
||||
if( info.m_iCompressionMethod != STORED && info.m_iCompressionMethod != DEFLATED )
|
||||
{
|
||||
LOG->Warn( "File \"%s\" in \"%s\" uses unsupported compression method %i",
|
||||
Warn( "File \"%s\" in \"%s\" uses unsupported compression method %i",
|
||||
info.m_sName.c_str(), m_sPath.c_str(), info.m_iCompressionMethod );
|
||||
|
||||
return 0;
|
||||
@@ -252,13 +254,13 @@ bool RageFileDriverZip::ReadLocalFileHeader( FileInfo &info )
|
||||
|
||||
if( sError != "" )
|
||||
{
|
||||
LOG->Warn( "%s: error opening \"%s\": %s", m_sPath.c_str(), info.m_sName.c_str(), sError.c_str() );
|
||||
Warn( "%s: error opening \"%s\": %s", m_sPath.c_str(), info.m_sName.c_str(), sError.c_str() );
|
||||
return false;
|
||||
}
|
||||
|
||||
if( sSig != "\x50\x4B\x03\x04" )
|
||||
{
|
||||
LOG->Warn( "%s: local file header not found for \"%s\"", m_sPath.c_str(), info.m_sName.c_str() );
|
||||
Warn( "%s: local file header not found for \"%s\"", m_sPath.c_str(), info.m_sName.c_str() );
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -270,7 +272,7 @@ bool RageFileDriverZip::ReadLocalFileHeader( FileInfo &info )
|
||||
|
||||
if( sError != "" )
|
||||
{
|
||||
LOG->Warn( "%s: %s", m_sPath.c_str(), sError.c_str() );
|
||||
Warn( "%s: %s", m_sPath.c_str(), sError.c_str() );
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user