Unify and correct Autosave functions

Autosave was not working correctly, partly due to different
implementations in eeschema and pcbnew and partly due to a mistaken
refactor at some point during v5 development.  This unifies the expected
autosave prefix to _autosave- for both pcbnew and eeschema.  It also
unifies the expected suffix for the backup files to -bak.

Fixes: lp:1820433
* https://bugs.launchpad.net/kicad/+bug/1820433

(cherry picked from commit 078320e2fb)
This commit is contained in:
Seth Hillbrand
2019-03-18 10:27:09 -07:00
parent 4facd57cb7
commit 168fa09f5f
8 changed files with 45 additions and 66 deletions
+4 -10
View File
@@ -582,16 +582,14 @@ bool EDA_BASE_FRAME::IsWritable( const wxFileName& aFileName )
}
void EDA_BASE_FRAME::CheckForAutoSaveFile( const wxFileName& aFileName,
const wxString& aBackupFileExtension )
void EDA_BASE_FRAME::CheckForAutoSaveFile( const wxFileName& aFileName )
{
wxCHECK_RET( aFileName.IsOk(), wxT( "Invalid file name!" ) );
wxCHECK_RET( !aBackupFileExtension.IsEmpty(), wxT( "Invalid backup file extension!" ) );
wxFileName autoSaveFileName = aFileName;
// Check for auto save file.
autoSaveFileName.SetName( AUTOSAVE_PREFIX_FILENAME + aFileName.GetName() );
autoSaveFileName.SetName( GetAutoSaveFilePrefix() + aFileName.GetName() );
wxLogTrace( traceAutoSave,
wxT( "Checking for auto save file " ) + autoSaveFileName.GetFullPath() );
@@ -615,18 +613,14 @@ void EDA_BASE_FRAME::CheckForAutoSaveFile( const wxFileName& aFileName,
{
// Get the backup file name.
wxFileName backupFileName = aFileName;
backupFileName.SetExt( aBackupFileExtension );
backupFileName.SetExt( aFileName.GetExt() + GetBackupSuffix() );
// If an old backup file exists, delete it. If an old copy of the file exists, rename
// it to the backup file name
if( aFileName.FileExists() )
{
// Remove the old file backup file.
if( backupFileName.FileExists() )
wxRemoveFile( backupFileName.GetFullPath() );
// Rename the old file to the backup file name.
if( !wxRenameFile( aFileName.GetFullPath(), backupFileName.GetFullPath() ) )
if( !wxRenameFile( aFileName.GetFullPath(), backupFileName.GetFullPath(), true ) )
{
msg.Printf( _( "Could not create backup file \"%s\"" ),
GetChars( backupFileName.GetFullPath() ) );