simplify
This commit is contained in:
@@ -66,6 +66,24 @@ static HANDLE DoFindFirstFile( const CString &sPath, WIN32_FIND_DATA *fd )
|
|||||||
return FindFirstFile( sPath, fd );
|
return FindFirstFile( sPath, fd );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int WinMoveFile( const CString sOldPath, const CString sNewPath )
|
||||||
|
{
|
||||||
|
static bool Win9x = false;
|
||||||
|
|
||||||
|
if( !Win9x )
|
||||||
|
{
|
||||||
|
if( MoveFileEx( sOldPath, sNewPath, MOVEFILE_REPLACE_EXISTING ) )
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
if( GetLastError() != ERROR_NOT_SUPPORTED )
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
Win9x = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return MoveFile( sOldPath, sNewPath );
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int DoRemove( const CString &sPath )
|
static int DoRemove( const CString &sPath )
|
||||||
@@ -500,39 +518,22 @@ RageFileObjDirect::~RageFileObjDirect()
|
|||||||
* don't know if it has similar atomicity guarantees to rename). In
|
* don't know if it has similar atomicity guarantees to rename). In
|
||||||
* 9x, we're screwed, so just delete any existing file (we aren't going
|
* 9x, we're screwed, so just delete any existing file (we aren't going
|
||||||
* to be robust on 9x anyway). */
|
* to be robust on 9x anyway). */
|
||||||
int err = MoveFileEx( sOldPath, sNewPath, MOVEFILE_REPLACE_EXISTING )? ERROR_SUCCESS:GetLastError();
|
if( WinMoveFile(sOldPath, sNewPath) )
|
||||||
|
return;
|
||||||
if( err == ERROR_ACCESS_DENIED )
|
if( GetLastError() == ERROR_ACCESS_DENIED )
|
||||||
{
|
{
|
||||||
/* Try turning off the read-only bit on the file we're overwriting. */
|
/* Try turning off the read-only bit on the file we're overwriting. */
|
||||||
SetFileAttributes( sNewPath, FILE_ATTRIBUTE_NORMAL );
|
SetFileAttributes( sNewPath, FILE_ATTRIBUTE_NORMAL );
|
||||||
|
|
||||||
err = MoveFileEx( sOldPath, sNewPath, MOVEFILE_REPLACE_EXISTING )? ERROR_SUCCESS:GetLastError();
|
if( WinMoveFile( sOldPath, sNewPath ) )
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( err == ERROR_NOT_SUPPORTED )
|
/* We failed. */
|
||||||
{
|
int err = GetLastError();
|
||||||
/* We're in 9x. Delete the old file and rename. */
|
const CString error = werr_ssprintf( err, "Error renaming \"%s\" to \"%s\"", sOldPath.c_str(), sNewPath.c_str() );
|
||||||
if( DoRemove(sOldPath) == -1 && errno != ENOENT )
|
LOG->Warn( "%s", error.c_str() );
|
||||||
{
|
SetError( error );
|
||||||
LOG->Warn( "Error removing %s: %s", sOldPath.c_str(), strerror(errno) );
|
|
||||||
SetError( strerror(errno) );
|
|
||||||
}
|
|
||||||
else if( rename( sOldPath, sNewPath ) == -1 )
|
|
||||||
{
|
|
||||||
LOG->Warn( "Error renaming \"%s\" to \"%s\": %s",
|
|
||||||
sOldPath.c_str(), sNewPath.c_str(), strerror(errno) );
|
|
||||||
SetError( strerror(errno) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if( err != ERROR_SUCCESS )
|
|
||||||
{
|
|
||||||
/* We failed. */
|
|
||||||
const CString error = werr_ssprintf( err, "Error renaming \"%s\" to \"%s\"",
|
|
||||||
sOldPath.c_str(), sNewPath.c_str() );
|
|
||||||
LOG->Warn( "%s", error.c_str() );
|
|
||||||
SetError( error );
|
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
if( rename( sOldPath, sNewPath ) == -1 )
|
if( rename( sOldPath, sNewPath ) == -1 )
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user