Delete old files after writing, not before, to prevent data loss. (File

writing makes efforts to try to avoid data loss if we crash while saving.)
This commit is contained in:
Glenn Maynard
2005-12-06 20:44:39 +00:00
parent ab9526a9ed
commit 4bd7da7256
+10 -10
View File
@@ -265,17 +265,7 @@ bool NotesWriterSM::WriteEditFileToMachine( const Song *pSong, Steps *pSteps )
{
CString sDir = PROFILEMAN->GetProfileDir( ProfileSlot_Machine ) + EDIT_STEPS_SUBDIR;
/* If the file name of the edit has changed since the last save, then delete the old
* file before saving the new one.
*/
bool bFileNameChanged =
pSteps->GetSavedToDisk() &&
pSteps->GetFilename() != GetEditFileName(pSong,pSteps);
if( bFileNameChanged )
FILEMAN->Remove( pSteps->GetFilename() );
CString sPath = sDir + GetEditFileName(pSong,pSteps);
pSteps->SetFilename( sPath );
/* Flush dir cache when writing steps, so the old size isn't cached. */
FILEMAN->FlushDirCache( Dirname(sPath) );
@@ -299,6 +289,16 @@ bool NotesWriterSM::WriteEditFileToMachine( const Song *pSong, Steps *pSteps )
return false;
}
/* If the file name of the edit has changed since the last save, then delete the old
* file after saving the new one. If we delete it first, then we'll lose data on error. */
bool bFileNameChanged =
pSteps->GetSavedToDisk() &&
pSteps->GetFilename() != sPath;
if( bFileNameChanged )
FILEMAN->Remove( pSteps->GetFilename() );
pSteps->SetFilename( sPath );
return true;
}