mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-04-11 14:20:10 +00:00
Blacklist for project file copying.
Also fix it to use the output path, if specified. Fixes https://gitlab.com/kicad/code/kicad/-/issues/19479
This commit is contained in:
parent
d4865899c5
commit
17157b82b0
@ -359,6 +359,7 @@ bool RmDirRecursive( const wxString& aFileName, wxString* aErrors )
|
||||
bool CopyDirectory( const wxString& aSourceDir, const wxString& aDestDir, wxString& aErrors )
|
||||
{
|
||||
wxDir dir( aSourceDir );
|
||||
|
||||
if( !dir.IsOpened() )
|
||||
{
|
||||
aErrors += wxString::Format( _( "Could not open source directory: %s" ), aSourceDir );
|
||||
@ -375,6 +376,7 @@ bool CopyDirectory( const wxString& aSourceDir, const wxString& aDestDir, wxStri
|
||||
|
||||
wxString filename;
|
||||
bool cont = dir.GetFirst( &filename );
|
||||
|
||||
while( cont )
|
||||
{
|
||||
wxString sourcePath = aSourceDir + wxFileName::GetPathSeparator() + filename;
|
||||
@ -384,16 +386,16 @@ bool CopyDirectory( const wxString& aSourceDir, const wxString& aDestDir, wxStri
|
||||
{
|
||||
// Recursively copy subdirectories
|
||||
if( !CopyDirectory( sourcePath, destPath, aErrors ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Copy files
|
||||
if( !wxCopyFile( sourcePath, destPath ) )
|
||||
{
|
||||
aErrors += wxString::Format( _( "Could not copy file: %s to %s" ), sourcePath, destPath );
|
||||
aErrors += wxString::Format( _( "Could not copy file: %s to %s" ),
|
||||
sourcePath,
|
||||
destPath );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -406,32 +408,45 @@ bool CopyDirectory( const wxString& aSourceDir, const wxString& aDestDir, wxStri
|
||||
|
||||
|
||||
bool CopyFilesOrDirectory( const wxString& aSourcePath, const wxString& aDestDir, wxString& aErrors,
|
||||
int& fileCopiedCount )
|
||||
int& fileCopiedCount, const std::vector<wxString>& aExclusions )
|
||||
{
|
||||
wxFileName sourceFn( aSourcePath );
|
||||
wxDir dir( sourceFn.GetPath() );
|
||||
wxFileName destFn( aDestDir );
|
||||
|
||||
if( !dir.IsOpened() )
|
||||
{
|
||||
aErrors +=
|
||||
wxString::Format( _( "Could not open source directory: %s" ), sourceFn.GetPath() );
|
||||
aErrors += wxString::Format( _( "Could not open source directory: %s" ),
|
||||
sourceFn.GetPath() );
|
||||
aErrors += wxT( "\n" );
|
||||
return false;
|
||||
}
|
||||
|
||||
if( !wxFileName::Mkdir( aDestDir, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) )
|
||||
{
|
||||
aErrors += wxString::Format( _( "Could not create destination directory: %s" ), aDestDir );
|
||||
aErrors += wxString::Format( _( "Could not create destination directory: %s" ),
|
||||
aDestDir );
|
||||
aErrors += wxT( "\n" );
|
||||
return false;
|
||||
}
|
||||
|
||||
wxString filename = sourceFn.GetFullName();
|
||||
bool cont = dir.GetFirst( &filename, sourceFn.GetFullName(), wxDIR_FILES | wxDIR_DIRS );
|
||||
|
||||
while( cont )
|
||||
{
|
||||
wxString sourcePath = sourceFn.GetPath() + wxFileName::GetPathSeparator() + filename;
|
||||
wxString destPath = aDestDir + wxFileName::GetPathSeparator() + filename;
|
||||
bool exclude = filename.Matches( wxT( "~*.lck" ) );
|
||||
|
||||
for( const wxString& exclusion : aExclusions )
|
||||
exclude |= sourcePath.Matches( exclusion );
|
||||
|
||||
if( exclude )
|
||||
{
|
||||
cont = dir.GetNext( &filename );
|
||||
continue;
|
||||
}
|
||||
|
||||
// Avoid infinite recursion on "*"
|
||||
if( sourcePath == aSourcePath )
|
||||
@ -440,7 +455,8 @@ bool CopyFilesOrDirectory( const wxString& aSourcePath, const wxString& aDestDir
|
||||
if( wxFileName::DirExists( sourcePath ) )
|
||||
{
|
||||
// Recursively copy subdirectories
|
||||
if( !CopyFilesOrDirectory( sourcePath, destPath, aErrors, fileCopiedCount ) )
|
||||
if( !CopyFilesOrDirectory( sourcePath, destPath, aErrors, fileCopiedCount,
|
||||
aExclusions ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -468,6 +484,7 @@ bool AddDirectoryToZip( wxZipOutputStream& aZip, const wxString& aSourceDir, wxS
|
||||
const wxString& aParentDir )
|
||||
{
|
||||
wxDir dir( aSourceDir );
|
||||
|
||||
if( !dir.IsOpened() )
|
||||
{
|
||||
aErrors += wxString::Format( _( "Could not open source directory: %s" ), aSourceDir );
|
||||
@ -477,6 +494,7 @@ bool AddDirectoryToZip( wxZipOutputStream& aZip, const wxString& aSourceDir, wxS
|
||||
|
||||
wxString filename;
|
||||
bool cont = dir.GetFirst( &filename );
|
||||
|
||||
while( cont )
|
||||
{
|
||||
wxString sourcePath = aSourceDir + wxFileName::GetPathSeparator() + filename;
|
||||
@ -486,22 +504,23 @@ bool AddDirectoryToZip( wxZipOutputStream& aZip, const wxString& aSourceDir, wxS
|
||||
{
|
||||
// Add directory entry to the ZIP file
|
||||
aZip.PutNextDirEntry( zipPath + "/" );
|
||||
|
||||
// Recursively add subdirectories
|
||||
if( !AddDirectoryToZip( aZip, sourcePath, aErrors, zipPath + "/" ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Add file entry to the ZIP file
|
||||
aZip.PutNextEntry( zipPath );
|
||||
wxFFileInputStream fileStream( sourcePath );
|
||||
|
||||
if( !fileStream.IsOk() )
|
||||
{
|
||||
aErrors += wxString::Format( _( "Could not read file: %s" ), sourcePath );
|
||||
return false;
|
||||
}
|
||||
|
||||
aZip.Write( fileStream );
|
||||
}
|
||||
|
||||
|
@ -118,7 +118,8 @@ KICOMMON_API bool CopyDirectory( const wxString& aSourceDir, const wxString& aDe
|
||||
wxString& aErrors );
|
||||
|
||||
KICOMMON_API bool CopyFilesOrDirectory( const wxString& aSourceDir, const wxString& aDestDir,
|
||||
wxString& aErrors, int& fileCopiedCount );
|
||||
wxString& aErrors, int& fileCopiedCount,
|
||||
const std::vector<wxString>& aExclusions );
|
||||
|
||||
/**
|
||||
* Add a directory and its contents to a zip file.
|
||||
|
@ -113,13 +113,30 @@ int JOBS_RUNNER::runSpecialCopyFiles( const JOBSET_JOB* aJob, PROJECT* aProject
|
||||
if( source.IsEmpty() )
|
||||
return CLI::EXIT_CODES::ERR_ARGS;
|
||||
|
||||
wxString projectPath = aProject->GetProjectPath();
|
||||
wxFileName sourceFn( source );
|
||||
sourceFn.MakeAbsolute( aProject->GetProjectPath() );
|
||||
sourceFn.MakeAbsolute( projectPath );
|
||||
|
||||
wxFileName destFn( job->GetFullOutputPath() );
|
||||
|
||||
if( !job->m_dest.IsEmpty() )
|
||||
destFn.AppendDir( job->m_dest );
|
||||
|
||||
std::vector<wxString> exclusions;
|
||||
|
||||
for( const JOBSET_OUTPUT& output : m_jobsFile->GetOutputs() )
|
||||
exclusions.push_back( projectPath + output.m_outputHandler->GetOutputPath() );
|
||||
|
||||
exclusions.push_back( projectPath + aProject->GetProjectName() + wxT( "-backups" ) );
|
||||
exclusions.push_back( projectPath + aProject->GetProjectName() + wxT( ".kicad_prl" ) );
|
||||
exclusions.push_back( projectPath + wxT( "fp-info-cache" ) );
|
||||
exclusions.push_back( projectPath + wxT( "*.bak" ) );
|
||||
exclusions.push_back( projectPath + wxT( "_autosave-*" ) );
|
||||
|
||||
wxString errors;
|
||||
int copyCount = 0;
|
||||
bool success = CopyFilesOrDirectory( sourceFn.GetFullPath(), job->GetFullOutputPath(),
|
||||
errors, copyCount );
|
||||
bool success = CopyFilesOrDirectory( sourceFn.GetFullPath(), destFn.GetFullPath(),
|
||||
errors, copyCount, exclusions );
|
||||
|
||||
if( !success )
|
||||
return CLI::EXIT_CODES::ERR_UNKNOWN;
|
||||
@ -127,7 +144,6 @@ int JOBS_RUNNER::runSpecialCopyFiles( const JOBSET_JOB* aJob, PROJECT* aProject
|
||||
if( job->m_generateErrorOnNoCopy && copyCount == 0 )
|
||||
return CLI::EXIT_CODES::ERR_UNKNOWN;
|
||||
|
||||
|
||||
return CLI::EXIT_CODES::OK;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user