This commit is contained in:
Glenn Maynard
2005-12-13 03:33:32 +00:00
parent a4e1e57123
commit 40542977f1
2 changed files with 50 additions and 50 deletions
+47 -47
View File
@@ -60,10 +60,10 @@ private:
};
RageFileDriverDirect::RageFileDriverDirect( CString root_ ):
RageFileDriver( new DirectFilenameDB(root_) )
RageFileDriverDirect::RageFileDriverDirect( CString sRoot ):
RageFileDriver( new DirectFilenameDB(sRoot) )
{
Remount( root_ );
Remount( sRoot );
}
@@ -76,12 +76,12 @@ static CString MakeTempFilename( const CString &sPath )
return Dirname(sPath) + "new." + Basename(sPath) + ".new";
}
RageFileObj *MakeFileObjDirect( CString sPath, int mode, int &err )
RageFileObj *MakeFileObjDirect( CString sPath, int iMode, int &iError )
{
int fd;
if( mode & RageFile::READ )
int iFD;
if( iMode & RageFile::READ )
{
fd = DoOpen( sPath, O_BINARY|O_RDONLY, 0666 );
iFD = DoOpen( sPath, O_BINARY|O_RDONLY, 0666 );
/* XXX: Windows returns EACCES if we try to open a file on a CDROM that isn't
* ready, instead of something like ENODEV. We want to return that case as
@@ -89,43 +89,43 @@ RageFileObj *MakeFileObjDirect( CString sPath, int mode, int &err )
}
else
{
CString out;
if( mode & RageFile::STREAMED )
out = sPath;
CString sOut;
if( iMode & RageFile::STREAMED )
sOut = sPath;
else
out = MakeTempFilename(sPath);
sOut = MakeTempFilename(sPath);
/* Open a temporary file for writing. */
fd = DoOpen( out, O_BINARY|O_WRONLY|O_CREAT|O_TRUNC, 0666 );
iFD = DoOpen( sOut, O_BINARY|O_WRONLY|O_CREAT|O_TRUNC, 0666 );
}
if( fd == -1 )
if( iFD == -1 )
{
err = errno;
iError = errno;
return NULL;
}
return new RageFileObjDirect( sPath, fd, mode );
return new RageFileObjDirect( sPath, iFD, iMode );
}
RageFileBasic *RageFileDriverDirect::Open( const CString &path, int mode, int &err )
RageFileBasic *RageFileDriverDirect::Open( const CString &sPath_, int iMode, int &iError )
{
ASSERT( path.size() && path[0] == '/' );
CString sPath = path;
CString sPath = sPath_;
ASSERT( sPath.size() && sPath[0] == '/' );
/* This partially resolves. For example, if "abc/def" exists, and we're opening
* "ABC/DEF/GHI/jkl/mno", this will resolve it to "abc/def/GHI/jkl/mno"; we'll
* create the missing parts below. */
FDB->ResolvePath( sPath );
if( mode & RageFile::WRITE )
if( iMode & RageFile::WRITE )
{
const CString dir = Dirname(sPath);
if( this->GetFileType(dir) != RageFileManager::TYPE_DIR )
CreateDirectories( root + dir );
CreateDirectories( m_sRoot + dir );
}
return MakeFileObjDirect( root + sPath, mode, err );
return MakeFileObjDirect( m_sRoot + sPath, iMode, iError );
}
bool RageFileDriverDirect::Move( const CString &sOldPath_, const CString &sNewPath_ )
@@ -138,42 +138,42 @@ bool RageFileDriverDirect::Move( const CString &sOldPath_, const CString &sNewPa
if( this->GetFileType(sOldPath) == RageFileManager::TYPE_NONE )
return false;
{
const CString dir = Dirname(sNewPath);
CreateDirectories( root + dir );
{
const CString sDir = Dirname(sNewPath);
CreateDirectories( m_sRoot + sDir );
}
LOG->Trace("rename \"%s\" -> \"%s\"", (root + sOldPath).c_str(), (root + sNewPath).c_str() );
if( DoRename(root + sOldPath, root + sNewPath) == -1 )
LOG->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", (root + sOldPath).c_str(), (root + sNewPath).c_str(), strerror(errno) );
LOG->Warn( "rename(%s,%s) failed: %s", (m_sRoot + sOldPath).c_str(), (m_sRoot + sNewPath).c_str(), strerror(errno) );
return false;
}
return true;
}
bool RageFileDriverDirect::Remove( const CString &path )
bool RageFileDriverDirect::Remove( const CString &sPath_ )
{
CString sPath = path;
CString sPath = sPath_;
FDB->ResolvePath( sPath );
switch( this->GetFileType(sPath) )
{
case RageFileManager::TYPE_FILE:
LOG->Trace("remove '%s'", (root + sPath).c_str());
if( DoRemove( root + sPath ) == -1 )
LOG->Trace("remove '%s'", (m_sRoot + sPath).c_str());
if( DoRemove(m_sRoot + sPath) == -1 )
{
LOG->Warn( "remove(%s) failed: %s", (root + sPath).c_str(), strerror(errno) );
LOG->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'", (root + sPath).c_str());
if( DoRmdir( root + sPath ) == -1 )
LOG->Trace("rmdir '%s'", (m_sRoot + sPath).c_str());
if( DoRmdir(m_sRoot + sPath) == -1 )
{
LOG->Warn( "rmdir(%s) failed: %s", (root + sPath).c_str(), strerror(errno) );
LOG->Warn( "rmdir(%s) failed: %s", (m_sRoot + sPath).c_str(), strerror(errno) );
return false;
}
FDB->DelFile( sPath );
@@ -199,11 +199,11 @@ RageFileBasic *RageFileObjDirect::Copy() const
bool RageFileDriverDirect::Remount( const CString &sPath )
{
root = sPath;
m_sRoot = sPath;
((DirectFilenameDB *) FDB)->SetRoot( sPath );
/* If the root path doesn't exist, create it. */
CreateDirectories( root );
CreateDirectories( m_sRoot );
return true;
}
@@ -268,7 +268,7 @@ bool RageFileObjDirect::FinalFlush()
RageFileObjDirect::~RageFileObjDirect()
{
bool failed = !FinalFlush();
bool bFailed = !FinalFlush();
if( m_iFD != -1 )
{
@@ -276,7 +276,7 @@ RageFileObjDirect::~RageFileObjDirect()
{
LOG->Warn( "Error closing %s: %s", this->m_sPath.c_str(), strerror(errno) );
SetError( strerror(errno) );
failed = true;
bFailed = true;
}
}
@@ -288,7 +288,7 @@ RageFileObjDirect::~RageFileObjDirect()
do
{
if( failed || WriteFailed() )
if( bFailed || WriteFailed() )
break;
/*
@@ -343,16 +343,16 @@ int RageFileObjDirect::ReadInternal( void *pBuf, size_t iBytes )
}
/* write(), but retry a couple times on EINTR. */
static int retried_write( int iFD, const void *pBuf, size_t iCount )
static int RetriedWrite( int iFD, const void *pBuf, size_t iCount )
{
int tries = 3, ret;
int iTries = 3, iRet;
do
{
ret = write( iFD, pBuf, iCount );
iRet = write( iFD, pBuf, iCount );
}
while( ret == -1 && errno == EINTR && tries-- );
while( iRet == -1 && errno == EINTR && iTries-- );
return ret;
return iRet;
}
@@ -367,7 +367,7 @@ int RageFileObjDirect::FlushInternal()
if( !m_sWriteBuf.size() )
return 0;
int iRet = retried_write( m_iFD, m_sWriteBuf.data(), m_sWriteBuf.size() );
int iRet = RetriedWrite( m_iFD, m_sWriteBuf.data(), m_sWriteBuf.size() );
if( iRet == -1 )
{
LOG->Warn("Error writing %s: %s", this->m_sPath.c_str(), strerror(errno) );
@@ -399,7 +399,7 @@ int RageFileObjDirect::WriteInternal( const void *pBuf, size_t iBytes )
* the buffer size, so just write it directly. */
if( iBytes >= BUFSIZE )
{
int iRet = retried_write( m_iFD, pBuf, iBytes );
int iRet = RetriedWrite( m_iFD, pBuf, iBytes );
if( iRet == -1 )
{
LOG->Warn("Error writing %s: %s", this->m_sPath.c_str(), strerror(errno) );