Skip to content

Commit

Permalink
[BUGFIX] Skip invalid files in RecursiveCallbackFilterIterator
Browse files Browse the repository at this point in the history
  • Loading branch information
o-ba committed Dec 2, 2020
1 parent 5277199 commit b9dd72c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion conf/ExcludeFromPackaging.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
'directories' => [
'bin',
'build',
'.build',
'.ddev',
'.git',
'.github',
Expand Down Expand Up @@ -42,7 +43,7 @@
'Makefile',
'package-lock.json',
'package.json',
'php_cs.dist',
'php_cs',
'phplint.yml',
'phpstan.neon',
'phpunit.xml',
Expand Down
13 changes: 11 additions & 2 deletions src/Service/VersionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,27 @@ public function createZipArchiveFromPath(string $path): string
$files = new RecursiveIteratorIterator(
new RecursiveCallbackFilterIterator($iterator, function ($current) use ($fullPath) {
// @todo Find a more performant way for filtering
$path = substr($current->getRealPath(), strlen($fullPath) + 1);

$filepath = $current->getRealPath();
$filename = $current->getFilename();

if (!$filepath || !$filename || !($path = substr($filepath, strlen($fullPath) + 1))) {
return false;
}

// check directories
foreach ($this->excludeConfiguration['directories'] as $excludeDirectory) {
if (preg_match('/^' . $excludeDirectory . '/i', $path)) {
return false;
}
}
$filename = $current->getFilename();
// check files
foreach ($this->excludeConfiguration['files'] as $excludeFile) {
if (preg_match('/' . $excludeFile . '$/i', $filename)) {
return false;
}
}

return true;
}),
RecursiveIteratorIterator::LEAVES_ONLY
Expand Down

0 comments on commit b9dd72c

Please sign in to comment.