Clean up autosave file handling edge cases

(cherry picked from commit bd74489b00)
This commit is contained in:
Simon Schaak 2022-11-22 15:21:26 +00:00 committed by Wayne Stambaugh
parent 5de05312d5
commit 045633626c
1 changed files with 9 additions and 6 deletions

View File

@ -1421,12 +1421,17 @@ void SCH_EDIT_FRAME::CheckForAutoSaveFile( const wxFileName& aFileName )
" Auto save file: '%s'" ), " Auto save file: '%s'" ),
recoveredFn.GetFullPath(), backupFn.GetFullPath(), fn ); recoveredFn.GetFullPath(), backupFn.GetFullPath(), fn );
// Attempt to back up the last schematic file before overwriting it with the auto if( !wxFileExists( fn ) )
// save file.
if( !wxCopyFile( recoveredFn.GetFullPath(), backupFn.GetFullPath() ) )
{ {
unrecoveredFiles.Add( recoveredFn.GetFullPath() ); unrecoveredFiles.Add( recoveredFn.GetFullPath() );
} }
// Attempt to back up the last schematic file before overwriting it with the auto
// save file.
else if( !wxCopyFile( recoveredFn.GetFullPath(), backupFn.GetFullPath() ) )
{
unrecoveredFiles.Add( recoveredFn.GetFullPath() );
}
// Attempt to replace last saved file with auto save file
else if( !wxRenameFile( fn, recoveredFn.GetFullPath() ) ) else if( !wxRenameFile( fn, recoveredFn.GetFullPath() ) )
{ {
unrecoveredFiles.Add( recoveredFn.GetFullPath() ); unrecoveredFiles.Add( recoveredFn.GetFullPath() );
@ -1454,10 +1459,8 @@ void SCH_EDIT_FRAME::CheckForAutoSaveFile( const wxFileName& aFileName )
{ {
wxLogTrace( traceAutoSave, wxT( "Removing auto save file " ) + fn ); wxLogTrace( traceAutoSave, wxT( "Removing auto save file " ) + fn );
if( !wxRemoveFile( fn ) ) if( wxFileExists( fn ) && !wxRemoveFile( fn ) )
{
unremovedFiles.Add( fn ); unremovedFiles.Add( fn );
}
} }
if( !unremovedFiles.IsEmpty() ) if( !unremovedFiles.IsEmpty() )