Use a temp file for saving the fp-info-cache for now

This commit is contained in:
Marek Roszko 2020-12-10 23:07:49 -05:00
parent 3613bca5ea
commit 17c4e21f34
1 changed files with 11 additions and 2 deletions

View File

@ -343,7 +343,8 @@ FOOTPRINT_LIST_IMPL::~FOOTPRINT_LIST_IMPL()
void FOOTPRINT_LIST_IMPL::WriteCacheToFile( const wxString& aFilePath )
{
wxFFileOutputStream outStream( aFilePath );
wxFileName tmpFileName = wxFileName::CreateTempFileName( aFilePath );
wxFFileOutputStream outStream( tmpFileName.GetFullPath() );
wxTextOutputStream txtStream( outStream );
if( !outStream.IsOk() )
@ -365,6 +366,14 @@ void FOOTPRINT_LIST_IMPL::WriteCacheToFile( const wxString& aFilePath )
}
txtStream.Flush();
outStream.Close();
if( !wxRenameFile( tmpFileName.GetFullPath(), aFilePath, true ) )
{
// cleanup incase rename failed
// its also not the end of the world since this is just a cache file
wxRemoveFile( tmpFileName.GetFullPath() );
}
}