add optional RageFileDriver::MoveFile override; implement for RageFileDriverDirect and RageFileDriverTimeout

This commit is contained in:
Glenn Maynard
2005-09-28 22:59:12 +00:00
parent 6698a2ba91
commit 04ec4e66f4
7 changed files with 81 additions and 1 deletions
+1
View File
@@ -19,6 +19,7 @@ public:
virtual int GetFileHash( const CString &sPath );
virtual int GetPathValue( const CString &path );
virtual void FlushDirCache( const CString &sPath );
virtual bool MoveFile( const CString &sOldPath, const CString &sNewPath ) { return false; }
virtual bool Remove( const CString &sPath ) { return false; }
/* Optional: Move to a different place, as if reconstructed with a different path. */
+25
View File
@@ -122,6 +122,31 @@ RageFileBasic *RageFileDriverDirect::Open( const CString &path, int mode, int &e
return MakeFileObjDirect( root + sPath, mode, err );
}
bool RageFileDriverDirect::MoveFile( const CString &sOldPath_, const CString &sNewPath_ )
{
CString sOldPath = sOldPath_;
CString sNewPath = sNewPath_;
FDB->ResolvePath( sOldPath );
FDB->ResolvePath( sNewPath );
if( this->GetFileType(sOldPath) == RageFileManager::TYPE_NONE )
return false;
{
const CString dir = Dirname(sNewPath);
CreateDirectories( root + dir );
}
LOG->Trace("rename \"%s\" -> \"%s\"", (root + sOldPath).c_str(), (root + sNewPath).c_str() );
if( DoRename(root + sOldPath, root + sNewPath) == -1 )
{
LOG->Warn( "rename(%s,%s) failed: %s", (root + sOldPath).c_str(), (root + sNewPath).c_str(), strerror(errno) );
return false;
}
return true;
}
bool RageFileDriverDirect::Remove( const CString &path )
{
CString sPath = path;
+1
View File
@@ -11,6 +11,7 @@ public:
RageFileDriverDirect( CString root );
RageFileBasic *Open( const CString &path, int mode, int &err );
bool MoveFile( const CString &sOldPath, const CString &sNewPath );
bool Remove( const CString &sPath );
bool Remount( const CString &sPath );
@@ -34,6 +34,13 @@ int DoStat( const CString &sPath, struct stat *st )
return stat( DoPathReplace(sPath), st );
}
int DoRename( const CString &sOldPath, const CString &sNewPath )
{
CString TempPath = sPath;
TempPath.Replace( "/", "\\" );
return rename( sPath );
}
int DoRemove( const CString &sPath )
{
return remove( DoPathReplace(sPath) );
@@ -9,6 +9,7 @@
int DoMkdir( const CString &sPath, int perm );
int DoOpen( const CString &sPath, int flags, int perm );
int DoStat( const CString &sPath, struct stat *st );
int DoRename( const CString &sOldPath, const CString &sNewPath );
int DoRemove( const CString &sPath );
int DoRmdir( const CString &sPath );
HANDLE DoFindFirstFile( const CString &sPath, WIN32_FIND_DATA *fd );
@@ -17,6 +18,7 @@ HANDLE DoFindFirstFile( const CString &sPath, WIN32_FIND_DATA *fd );
#define DoStat stat
#define DoMkdir mkdir
#define DoFindFirstFile FindFirstFile
#define DoRename rename
#define DoRemove remove
#define DoRmdir rmdir
#endif
+44 -1
View File
@@ -61,6 +61,7 @@ enum ThreadRequest
REQ_COPY,
REQ_POPULATE_FILE_SET,
REQ_FLUSH_DIR_CACHE,
REQ_MOVE_FILE,
REQ_REMOVE,
};
@@ -84,6 +85,7 @@ public:
RageFileBasic *Copy( RageFileBasic *&pFile, CString &sError );
bool FlushDirCache( const CString &sPath );
int MoveFile( const CString &sOldPath, const CString &sNewPath );
int Remove( const CString &sPath );
bool PopulateFileSet( FileSet &fs, const CString &sPath );
@@ -100,9 +102,12 @@ private:
vector<RageFileBasic *> m_apDeletedFiles;
RageMutex m_DeletedFilesLock;
/* REQ_OPEN, REQ_POPULATE_FILE_SET, REQ_FLUSH_DIR_CACHE, REQ_REMOVE: */
/* REQ_OPEN, REQ_POPULATE_FILE_SET, REQ_FLUSH_DIR_CACHE, REQ_REMOVE, REQ_MOVE_FILE: */
CString m_sRequestPath; /* in */
/* REQ_MOVE_FILE: */
CString m_sRequestPath2; /* in */
/* REQ_OPEN, REQ_COPY: */
RageFileBasic *m_pResultFile; /* out */
@@ -267,6 +272,12 @@ void ThreadedFileWorker::HandleRequest( int iRequest )
m_iResultRequest = m_pChildDriver->Remove( m_sRequestPath )? 0:-1;
break;
case REQ_MOVE_FILE:
ASSERT( !m_sRequestPath.empty() );
ASSERT( !m_sRequestPath2.empty() );
m_iResultRequest = m_pChildDriver->MoveFile( m_sRequestPath, m_sRequestPath2 )? 0:-1;
break;
default:
FAIL_M( ssprintf("%i", iRequest) );
}
@@ -576,6 +587,26 @@ bool ThreadedFileWorker::PopulateFileSet( FileSet &fs, const CString &sPath )
return true;
}
int ThreadedFileWorker::MoveFile( const CString &sOldPath, const CString &sNewPath )
{
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 = sOldPath;
m_sRequestPath2 = sNewPath;
if( !DoRequest(REQ_MOVE_FILE) )
{
/* If we time out, we can no longer access pFile. */
return -1;
}
return m_iResultRequest;
}
int ThreadedFileWorker::Remove( const CString &sPath )
{
ASSERT( m_pChildDriver != NULL ); /* how did you get a file to begin with? */
@@ -815,6 +846,18 @@ void RageFileDriverTimeout::FlushDirCache( const CString &sPath )
m_pWorker->FlushDirCache( sPath );
}
bool RageFileDriverTimeout::MoveFile( const CString &sOldPath, const CString &sNewPath )
{
int iRet = m_pWorker->MoveFile( sOldPath, sNewPath );
if( iRet == -1 )
{
LOG->Warn( "RageFileDriverTimeout::MoveFile(%s,%s) failed", sOldPath.c_str(), sNewPath.c_str() );
return false;
}
return true;
}
bool RageFileDriverTimeout::Remove( const CString &sPath )
{
int iRet = m_pWorker->Remove( sPath );
+1
View File
@@ -15,6 +15,7 @@ public:
RageFileBasic *Open( const CString &path, int mode, int &err );
void FlushDirCache( const CString &sPath );
bool MoveFile( const CString &sOldPath, const CString &sNewPath );
bool Remove( const CString &sPath );
static void SetTimeout( float fSeconds );