add optional RageFileDriver::MoveFile override; implement for RageFileDriverDirect and RageFileDriverTimeout
This commit is contained in:
@@ -19,6 +19,7 @@ public:
|
|||||||
virtual int GetFileHash( const CString &sPath );
|
virtual int GetFileHash( const CString &sPath );
|
||||||
virtual int GetPathValue( const CString &path );
|
virtual int GetPathValue( const CString &path );
|
||||||
virtual void FlushDirCache( const CString &sPath );
|
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; }
|
virtual bool Remove( const CString &sPath ) { return false; }
|
||||||
|
|
||||||
/* Optional: Move to a different place, as if reconstructed with a different path. */
|
/* Optional: Move to a different place, as if reconstructed with a different path. */
|
||||||
|
|||||||
@@ -122,6 +122,31 @@ RageFileBasic *RageFileDriverDirect::Open( const CString &path, int mode, int &e
|
|||||||
return MakeFileObjDirect( root + sPath, mode, err );
|
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 )
|
bool RageFileDriverDirect::Remove( const CString &path )
|
||||||
{
|
{
|
||||||
CString sPath = path;
|
CString sPath = path;
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ public:
|
|||||||
RageFileDriverDirect( CString root );
|
RageFileDriverDirect( CString root );
|
||||||
|
|
||||||
RageFileBasic *Open( const CString &path, int mode, int &err );
|
RageFileBasic *Open( const CString &path, int mode, int &err );
|
||||||
|
bool MoveFile( const CString &sOldPath, const CString &sNewPath );
|
||||||
bool Remove( const CString &sPath );
|
bool Remove( const CString &sPath );
|
||||||
bool Remount( 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 );
|
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 )
|
int DoRemove( const CString &sPath )
|
||||||
{
|
{
|
||||||
return remove( DoPathReplace(sPath) );
|
return remove( DoPathReplace(sPath) );
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
int DoMkdir( const CString &sPath, int perm );
|
int DoMkdir( const CString &sPath, int perm );
|
||||||
int DoOpen( const CString &sPath, int flags, int perm );
|
int DoOpen( const CString &sPath, int flags, int perm );
|
||||||
int DoStat( const CString &sPath, struct stat *st );
|
int DoStat( const CString &sPath, struct stat *st );
|
||||||
|
int DoRename( const CString &sOldPath, const CString &sNewPath );
|
||||||
int DoRemove( const CString &sPath );
|
int DoRemove( const CString &sPath );
|
||||||
int DoRmdir( const CString &sPath );
|
int DoRmdir( const CString &sPath );
|
||||||
HANDLE DoFindFirstFile( const CString &sPath, WIN32_FIND_DATA *fd );
|
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 DoStat stat
|
||||||
#define DoMkdir mkdir
|
#define DoMkdir mkdir
|
||||||
#define DoFindFirstFile FindFirstFile
|
#define DoFindFirstFile FindFirstFile
|
||||||
|
#define DoRename rename
|
||||||
#define DoRemove remove
|
#define DoRemove remove
|
||||||
#define DoRmdir rmdir
|
#define DoRmdir rmdir
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ enum ThreadRequest
|
|||||||
REQ_COPY,
|
REQ_COPY,
|
||||||
REQ_POPULATE_FILE_SET,
|
REQ_POPULATE_FILE_SET,
|
||||||
REQ_FLUSH_DIR_CACHE,
|
REQ_FLUSH_DIR_CACHE,
|
||||||
|
REQ_MOVE_FILE,
|
||||||
REQ_REMOVE,
|
REQ_REMOVE,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -84,6 +85,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 MoveFile( const CString &sOldPath, const CString &sNewPath );
|
||||||
int Remove( const CString &sPath );
|
int Remove( const CString &sPath );
|
||||||
bool PopulateFileSet( FileSet &fs, const CString &sPath );
|
bool PopulateFileSet( FileSet &fs, const CString &sPath );
|
||||||
|
|
||||||
@@ -100,9 +102,12 @@ 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_REMOVE: */
|
/* REQ_OPEN, REQ_POPULATE_FILE_SET, REQ_FLUSH_DIR_CACHE, REQ_REMOVE, REQ_MOVE_FILE: */
|
||||||
CString m_sRequestPath; /* in */
|
CString m_sRequestPath; /* in */
|
||||||
|
|
||||||
|
/* REQ_MOVE_FILE: */
|
||||||
|
CString m_sRequestPath2; /* in */
|
||||||
|
|
||||||
/* REQ_OPEN, REQ_COPY: */
|
/* REQ_OPEN, REQ_COPY: */
|
||||||
RageFileBasic *m_pResultFile; /* out */
|
RageFileBasic *m_pResultFile; /* out */
|
||||||
|
|
||||||
@@ -267,6 +272,12 @@ void ThreadedFileWorker::HandleRequest( int iRequest )
|
|||||||
m_iResultRequest = m_pChildDriver->Remove( m_sRequestPath )? 0:-1;
|
m_iResultRequest = m_pChildDriver->Remove( m_sRequestPath )? 0:-1;
|
||||||
break;
|
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:
|
default:
|
||||||
FAIL_M( ssprintf("%i", iRequest) );
|
FAIL_M( ssprintf("%i", iRequest) );
|
||||||
}
|
}
|
||||||
@@ -576,6 +587,26 @@ bool ThreadedFileWorker::PopulateFileSet( FileSet &fs, const CString &sPath )
|
|||||||
return true;
|
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 )
|
int ThreadedFileWorker::Remove( const CString &sPath )
|
||||||
{
|
{
|
||||||
ASSERT( m_pChildDriver != NULL ); /* how did you get a file to begin with? */
|
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 );
|
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 )
|
bool RageFileDriverTimeout::Remove( const CString &sPath )
|
||||||
{
|
{
|
||||||
int iRet = m_pWorker->Remove( sPath );
|
int iRet = m_pWorker->Remove( sPath );
|
||||||
|
|||||||
@@ -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 MoveFile( const CString &sOldPath, const CString &sNewPath );
|
||||||
bool Remove( const CString &sPath );
|
bool Remove( const CString &sPath );
|
||||||
|
|
||||||
static void SetTimeout( float fSeconds );
|
static void SetTimeout( float fSeconds );
|
||||||
|
|||||||
Reference in New Issue
Block a user