mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-09-14 02:03:12 +02:00
Remove temporary file saving step
We implemented the intermediate temporary file in order to avoid issues during save. Unfortunately, this is heavily system-dependent and seems to cause problems with unusual setups. Now that we cache writing using the prettifier, the errors during output will not affect the existing file Fixes https://gitlab.com/kicad/code/kicad/-/issues/21330
This commit is contained in:
parent
5235b8e3ca
commit
f6b599e155
@ -786,8 +786,6 @@ bool SCH_EDIT_FRAME::saveSchematicFile( SCH_SHEET* aSheet, const wxString& aSave
|
||||
saveProjectSettings();
|
||||
}
|
||||
|
||||
wxString tempFile = wxFileName::CreateTempFileName( wxS( "eeschema" ) );
|
||||
|
||||
// Save
|
||||
wxLogTrace( traceAutoSave, wxS( "Saving file " ) + schematicFileName.GetFullPath() );
|
||||
|
||||
@ -804,7 +802,7 @@ bool SCH_EDIT_FRAME::saveSchematicFile( SCH_SHEET* aSheet, const wxString& aSave
|
||||
|
||||
try
|
||||
{
|
||||
pi->SaveSchematicFile( tempFile, aSheet, &Schematic() );
|
||||
pi->SaveSchematicFile( schematicFileName.GetFullPath(), aSheet, &Schematic() );
|
||||
success = true;
|
||||
}
|
||||
catch( const IO_ERROR& ioe )
|
||||
@ -814,38 +812,9 @@ bool SCH_EDIT_FRAME::saveSchematicFile( SCH_SHEET* aSheet, const wxString& aSave
|
||||
ioe.What() );
|
||||
DisplayError( this, msg );
|
||||
|
||||
msg.Printf( _( "Failed to create temporary file '%s'." ),
|
||||
tempFile );
|
||||
SetMsgPanel( wxEmptyString, msg );
|
||||
|
||||
// In case we started a file but didn't fully write it, clean up
|
||||
wxRemoveFile( tempFile );
|
||||
|
||||
success = false;
|
||||
}
|
||||
|
||||
if( success )
|
||||
{
|
||||
// Preserve the permissions of the current file
|
||||
KIPLATFORM::IO::DuplicatePermissions( schematicFileName.GetFullPath(), tempFile );
|
||||
|
||||
// Replace the original with the temporary file we just wrote
|
||||
success = wxRenameFile( tempFile, schematicFileName.GetFullPath() );
|
||||
|
||||
if( !success )
|
||||
{
|
||||
msg.Printf( _( "Error saving schematic file '%s'.\n"
|
||||
"Failed to rename temporary file '%s'." ),
|
||||
schematicFileName.GetFullPath(),
|
||||
tempFile );
|
||||
DisplayError( this, msg );
|
||||
|
||||
msg.Printf( _( "Failed to rename temporary file '%s'." ),
|
||||
tempFile );
|
||||
SetMsgPanel( wxEmptyString, msg );
|
||||
}
|
||||
}
|
||||
|
||||
if( success )
|
||||
{
|
||||
// Delete auto save file.
|
||||
@ -866,10 +835,6 @@ bool SCH_EDIT_FRAME::saveSchematicFile( SCH_SHEET* aSheet, const wxString& aSave
|
||||
msg.Printf( _( "File '%s' saved." ), screen->GetFileName() );
|
||||
SetStatusText( msg, 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
DisplayError( this, _( "File write operation failed." ) );
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
@ -1034,7 +1034,6 @@ bool PCB_EDIT_FRAME::SavePcbFile( const wxString& aFileName, bool addToHistory,
|
||||
GetBoard()->SynchronizeNetsAndNetClasses( false );
|
||||
}
|
||||
|
||||
wxString tempFile = wxFileName::CreateTempFileName( wxS( "pcbnew" ) );
|
||||
wxString upperTxt;
|
||||
wxString lowerTxt;
|
||||
|
||||
@ -1042,40 +1041,13 @@ bool PCB_EDIT_FRAME::SavePcbFile( const wxString& aFileName, bool addToHistory,
|
||||
{
|
||||
IO_RELEASER<PCB_IO> pi( PCB_IO_MGR::PluginFind( PCB_IO_MGR::KICAD_SEXP ) );
|
||||
|
||||
pi->SaveBoard( tempFile, GetBoard(), nullptr );
|
||||
pi->SaveBoard( pcbFileName.GetFullPath(), GetBoard(), nullptr );
|
||||
}
|
||||
catch( const IO_ERROR& ioe )
|
||||
{
|
||||
DisplayError( this, wxString::Format( _( "Error saving board file '%s'.\n%s" ),
|
||||
pcbFileName.GetFullPath(),
|
||||
ioe.What() ) );
|
||||
|
||||
lowerTxt.Printf( _( "Failed to create temporary file '%s'." ), tempFile );
|
||||
|
||||
SetMsgPanel( upperTxt, lowerTxt );
|
||||
|
||||
// In case we started a file but didn't fully write it, clean up
|
||||
wxRemoveFile( tempFile );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Preserve the permissions of the current file
|
||||
KIPLATFORM::IO::DuplicatePermissions( pcbFileName.GetFullPath(), tempFile );
|
||||
|
||||
// If save succeeded, replace the original with what we just wrote
|
||||
if( !wxRenameFile( tempFile, pcbFileName.GetFullPath() ) )
|
||||
{
|
||||
DisplayError( this, wxString::Format( _( "Error saving board file '%s'.\n"
|
||||
"Failed to rename temporary file '%s." ),
|
||||
pcbFileName.GetFullPath(),
|
||||
tempFile ) );
|
||||
|
||||
lowerTxt.Printf( _( "Failed to rename temporary file '%s'." ),
|
||||
tempFile );
|
||||
|
||||
SetMsgPanel( upperTxt, lowerTxt );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1084,7 +1056,10 @@ bool PCB_EDIT_FRAME::SavePcbFile( const wxString& aFileName, bool addToHistory,
|
||||
WX_STRING_REPORTER backupReporter;
|
||||
|
||||
if( !GetSettingsManager()->TriggerBackupIfNeeded( backupReporter ) )
|
||||
{
|
||||
upperTxt = backupReporter.GetMessages();
|
||||
SetStatusText( upperTxt, 1 );
|
||||
}
|
||||
}
|
||||
|
||||
GetBoard()->SetFileName( pcbFileName.GetFullPath() );
|
||||
@ -1117,6 +1092,7 @@ bool PCB_EDIT_FRAME::SavePcbFile( const wxString& aFileName, bool addToHistory,
|
||||
|
||||
GetScreen()->SetContentModified( false );
|
||||
UpdateTitle();
|
||||
UpdateStatusBar();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -124,15 +124,8 @@ void FP_CACHE::Save( FOOTPRINT* aFootprintFilter )
|
||||
// Allow file output stream to go out of scope to close the file stream before
|
||||
// renaming the file.
|
||||
{
|
||||
#ifdef USE_TMP_FILE
|
||||
fileName = wxFileName::CreateTempFileName( fn.GetPath() );
|
||||
|
||||
wxLogTrace( traceKicadPcbPlugin, wxT( "Creating temporary library file '%s'." ),
|
||||
fileName );
|
||||
#else
|
||||
wxLogTrace( traceKicadPcbPlugin, wxT( "Writing library file '%s'." ),
|
||||
fileName );
|
||||
#endif
|
||||
|
||||
PRETTIFIED_FILE_OUTPUTFORMATTER formatter( fileName );
|
||||
|
||||
@ -140,24 +133,6 @@ void FP_CACHE::Save( FOOTPRINT* aFootprintFilter )
|
||||
m_owner->Format( footprint.get() );
|
||||
}
|
||||
|
||||
#ifdef USE_TMP_FILE
|
||||
wxRemove( fn.GetFullPath() ); // it is not an error if this does not exist
|
||||
|
||||
// Even on Linux you can see an _intermittent_ error when calling wxRename(),
|
||||
// and it is fully inexplicable. See if this dodges the error.
|
||||
wxMilliSleep( 250L );
|
||||
|
||||
// Preserve the permissions of the current file
|
||||
KIPLATFORM::IO::DuplicatePermissions( fn.GetFullPath(), fileName );
|
||||
|
||||
if( !wxRenameFile( fileName, fn.GetFullPath() ) )
|
||||
{
|
||||
wxString msg = wxString::Format( _( "Cannot rename temporary file '%s' to '%s'" ),
|
||||
fileName,
|
||||
fn.GetFullPath() );
|
||||
THROW_IO_ERROR( msg );
|
||||
}
|
||||
#endif
|
||||
m_cache_timestamp += fn.GetTimestamp();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user