Attempt to fix Coverity issue 316502.

This changes the third party project importer to fail if either the
schematic or board files cannot be copied to the project folder.
This commit is contained in:
Wayne Stambaugh 2021-02-25 12:24:57 -05:00
parent 87ea540953
commit b4741c97b6
1 changed files with 28 additions and 6 deletions

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2017-2020 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2017-2021 KiCad Developers, see AUTHORS.txt for contributors.
*
* @author Russell Oliver <roliver8143@gmail.com>
*
@ -111,7 +111,7 @@ void KICAD_MANAGER_FRAME::ImportNonKiCadProject( wxString aWindowTitle, wxString
if( !wxMkdir( pro.GetPath() ) )
{
msg = _( "Error creating new directory. Please try a different path. The "
"project was not imported." );
"project cannot be imported." );
wxMessageDialog dirErrorDlg( this, msg, _( "Error" ), wxOK_DEFAULT | wxICON_ERROR );
dirErrorDlg.ShowModal();
@ -130,14 +130,36 @@ void KICAD_MANAGER_FRAME::ImportNonKiCadProject( wxString aWindowTitle, wxString
wxFileName schCopy( pro );
schCopy.SetExt( aSchFileExtension );
if( sch.Exists() && !schCopy.SameAs( sch ) )
wxCopyFile( sch.GetFullPath(), schCopy.GetFullPath(), true );
if( sch.Exists() && !schCopy.SameAs( sch )
&& wxCopyFile( sch.GetFullPath(), schCopy.GetFullPath(), true ) )
{
///< @todo Should we remove the newly created folder?
msg.Printf( _( "Cannot copy file '%s'\n"
"to '%s'\n"
"The project cannot be imported." ),
sch.GetFullPath(), schCopy.GetFullPath() );
wxMessageDialog schCopyErrorDlg( this, msg, _( "Error" ), wxOK_DEFAULT | wxICON_ERROR );
schCopyErrorDlg.ShowModal();
return;
}
wxFileName pcbCopy( pro );
pcbCopy.SetExt( aPcbFileExtension );
if( pcb.Exists() && !pcbCopy.SameAs( pcb ) )
wxCopyFile( pcb.GetFullPath(), pcbCopy.GetFullPath(), true );
if( pcb.Exists() && !pcbCopy.SameAs( pcb )
&& wxCopyFile( pcb.GetFullPath(), pcbCopy.GetFullPath(), true ) )
{
///< @todo Should we remove copied schematic file and the newly created folder?
msg.Printf( _( "Cannot copy file '%s'\n"
"to '%s'\n"
"The project cannot be imported." ),
sch.GetFullPath(), schCopy.GetFullPath() );
wxMessageDialog brdCopyErrorDlg( this, msg, _( "Error" ), wxOK_DEFAULT | wxICON_ERROR );
brdCopyErrorDlg.ShowModal();
return;
}
// Close the project and make the new one
CloseProject( true );