Add recursion guard to project Save As.

This keeps us from copying files that have just been copied when
a project is Saved As inside itself (which is a useful thing to do
when versioning backups or the like).

Fixes https://gitlab.com/kicad/code/kicad/issues/6388
This commit is contained in:
Jeff Young 2020-11-22 11:46:52 +00:00
parent 2932fe1e64
commit e5ddfe13f2
1 changed files with 11 additions and 4 deletions

View File

@ -349,6 +349,10 @@ public:
virtual wxDirTraverseResult OnFile( const wxString& aSrcFilePath ) override virtual wxDirTraverseResult OnFile( const wxString& aSrcFilePath ) override
{ {
// Recursion guard for a Save As to a location inside the source project.
if( aSrcFilePath.StartsWith( m_newProjectDirPath ) )
return wxDIR_CONTINUE;
wxFileName destFile( aSrcFilePath ); wxFileName destFile( aSrcFilePath );
wxString ext = destFile.GetExt(); wxString ext = destFile.GetExt();
bool atRoot = destFile.GetPath() == m_projectDirPath; bool atRoot = destFile.GetPath() == m_projectDirPath;
@ -438,9 +442,13 @@ public:
return wxDIR_CONTINUE; return wxDIR_CONTINUE;
} }
virtual wxDirTraverseResult OnDir( const wxString& dirPath ) override virtual wxDirTraverseResult OnDir( const wxString& aSrcDirPath ) override
{ {
wxFileName destDir( dirPath ); // Recursion guard for a Save As to a location inside the source project.
if( aSrcDirPath.StartsWith( m_newProjectDirPath ) )
return wxDIR_CONTINUE;
wxFileName destDir( aSrcDirPath );
wxString destDirPath = destDir.GetPathWithSep(); wxString destDirPath = destDir.GetPathWithSep();
wxUniChar pathSep = wxFileName::GetPathSeparator(); wxUniChar pathSep = wxFileName::GetPathSeparator();
@ -542,8 +550,7 @@ int KICAD_MANAGER_CONTROL::SaveProjectAs( const TOOL_EVENT& aEvent )
const wxString& newProjectName = newProjectDir.GetName(); const wxString& newProjectName = newProjectDir.GetName();
wxDir currentProjectDir( currentProjectDirPath ); wxDir currentProjectDir( currentProjectDirPath );
SAVE_AS_TRAVERSER traverser( m_frame, SAVE_AS_TRAVERSER traverser( m_frame, currentProjectDirPath, currentProjectName,
currentProjectDirPath, currentProjectName,
newProjectDirPath, newProjectName ); newProjectDirPath, newProjectName );
currentProjectDir.Traverse( traverser ); currentProjectDir.Traverse( traverser );