implement RageFileDriverTimeout::Remove; fixes temp file being left behind on memory card

This commit is contained in:
Glenn Maynard
2005-04-25 02:23:01 +00:00
parent 6d3f1d7e2b
commit 0af0e63fc8
2 changed files with 42 additions and 3 deletions
+41 -3
View File
@@ -60,6 +60,7 @@ enum ThreadRequest
REQ_COPY, REQ_COPY,
REQ_POPULATE_FILE_SET, REQ_POPULATE_FILE_SET,
REQ_FLUSH_DIR_CACHE, REQ_FLUSH_DIR_CACHE,
REQ_REMOVE,
}; };
/* This is the class that does most of the work. */ /* This is the class that does most of the work. */
@@ -82,6 +83,7 @@ public:
RageFileBasic *Copy( RageFileBasic *&pFile, CString &sError ); RageFileBasic *Copy( RageFileBasic *&pFile, CString &sError );
bool FlushDirCache( const CString &sPath ); bool FlushDirCache( const CString &sPath );
int Remove( const CString &sPath );
bool PopulateFileSet( FileSet &fs, const CString &sPath ); bool PopulateFileSet( FileSet &fs, const CString &sPath );
protected: protected:
@@ -97,7 +99,7 @@ private:
vector<RageFileBasic *> m_apDeletedFiles; vector<RageFileBasic *> m_apDeletedFiles;
RageMutex m_DeletedFilesLock; RageMutex m_DeletedFilesLock;
/* REQ_OPEN, REQ_POPULATE_FILE_SET, REQ_FLUSH_DIR_CACHE: */ /* REQ_OPEN, REQ_POPULATE_FILE_SET, REQ_FLUSH_DIR_CACHE, REQ_REMOVE: */
CString m_sRequestPath; /* in */ CString m_sRequestPath; /* in */
/* REQ_OPEN, REQ_COPY: */ /* REQ_OPEN, REQ_COPY: */
@@ -208,7 +210,6 @@ void ThreadedFileWorker::HandleRequest( int iRequest )
ASSERT( m_pRequestFile != NULL ); ASSERT( m_pRequestFile != NULL );
delete m_pRequestFile; delete m_pRequestFile;
m_pRequestFile = NULL; m_pRequestFile = NULL;
break; break;
case REQ_GET_FILE_SIZE: case REQ_GET_FILE_SIZE:
@@ -221,6 +222,7 @@ void ThreadedFileWorker::HandleRequest( int iRequest )
m_iResultRequest = m_pRequestFile->Seek( m_iRequestPos ); m_iResultRequest = m_pRequestFile->Seek( m_iRequestPos );
m_sResultError = m_pRequestFile->GetError(); m_sResultError = m_pRequestFile->GetError();
break; break;
case REQ_READ: case REQ_READ:
ASSERT( m_pRequestFile != NULL ); ASSERT( m_pRequestFile != NULL );
ASSERT( m_pResultBuffer != NULL ); ASSERT( m_pResultBuffer != NULL );
@@ -248,15 +250,20 @@ void ThreadedFileWorker::HandleRequest( int iRequest )
case REQ_POPULATE_FILE_SET: case REQ_POPULATE_FILE_SET:
ASSERT( !m_sRequestPath.empty() ); ASSERT( !m_sRequestPath.empty() );
m_ResultFileSet = FileSet(); m_ResultFileSet = FileSet();
m_pChildDriver->FDB->GetFileSetCopy( m_sRequestPath, m_ResultFileSet ); m_pChildDriver->FDB->GetFileSetCopy( m_sRequestPath, m_ResultFileSet );
break; break;
case REQ_FLUSH_DIR_CACHE: case REQ_FLUSH_DIR_CACHE:
ASSERT( !m_sRequestPath.empty() );
m_pChildDriver->FlushDirCache( m_sRequestPath ); m_pChildDriver->FlushDirCache( m_sRequestPath );
break; break;
case REQ_REMOVE:
ASSERT( !m_sRequestPath.empty() );
m_iResultRequest = m_pChildDriver->Remove( m_sRequestPath )? 0:-1;
break;
default: default:
FAIL_M( ssprintf("%i", iRequest) ); FAIL_M( ssprintf("%i", iRequest) );
} }
@@ -552,6 +559,25 @@ bool ThreadedFileWorker::PopulateFileSet( FileSet &fs, const CString &sPath )
return true; return true;
} }
int ThreadedFileWorker::Remove( const CString &sPath )
{
ASSERT( m_pChildDriver != NULL ); /* how did you get a file to begin with? */
/* If we're currently in a timed-out state, fail. */
if( IsTimedOut() )
return -1;
m_sRequestPath = sPath;
if( !DoRequest(REQ_REMOVE) )
{
/* If we time out, we can no longer access pFile. */
return -1;
}
return m_iResultRequest;
}
bool ThreadedFileWorker::FlushDirCache( const CString &sPath ) bool ThreadedFileWorker::FlushDirCache( const CString &sPath )
{ {
if( m_pChildDriver == NULL ) if( m_pChildDriver == NULL )
@@ -760,6 +786,18 @@ void RageFileDriverTimeout::FlushDirCache( const CString &sPath )
m_pWorker->FlushDirCache( sPath ); m_pWorker->FlushDirCache( sPath );
} }
bool RageFileDriverTimeout::Remove( const CString &sPath )
{
int iRet = m_pWorker->Remove( sPath );
if( iRet == -1 )
{
LOG->Warn( "RageFileDriverTimeout::Remove(%s) failed", sPath.c_str() );
return false;
}
return true;
}
RageFileDriverTimeout::~RageFileDriverTimeout() RageFileDriverTimeout::~RageFileDriverTimeout()
{ {
delete m_pWorker; delete m_pWorker;
+1
View File
@@ -15,6 +15,7 @@ public:
RageFileBasic *Open( const CString &path, int mode, int &err ); RageFileBasic *Open( const CString &path, int mode, int &err );
void FlushDirCache( const CString &sPath ); void FlushDirCache( const CString &sPath );
bool Remove( const CString &sPath );
static void SetTimeout( float fSeconds ); static void SetTimeout( float fSeconds );
static void ResetTimeout() { SetTimeout( -1 ); } static void ResetTimeout() { SetTimeout( -1 ); }