From 913bae49082eeb65cbe81df58c0cf5eeb4664b61 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Thu, 11 Feb 2021 12:10:49 +0100 Subject: [PATCH] Make DevtoolsPackageArchive::openArchive() more efficient Resolves #3830 --- .../package/DevtoolsPackageArchive.class.php | 56 ++++++++++++++++--- 1 file changed, 48 insertions(+), 8 deletions(-) diff --git a/wcfsetup/install/files/lib/system/devtools/package/DevtoolsPackageArchive.class.php b/wcfsetup/install/files/lib/system/devtools/package/DevtoolsPackageArchive.class.php index a824a7aafe..bbb540bce2 100644 --- a/wcfsetup/install/files/lib/system/devtools/package/DevtoolsPackageArchive.class.php +++ b/wcfsetup/install/files/lib/system/devtools/package/DevtoolsPackageArchive.class.php @@ -6,8 +6,6 @@ use wcf\system\package\PackageArchive; use wcf\system\package\plugin\ACPTemplatePackageInstallationPlugin; use wcf\system\package\plugin\FilePackageInstallationPlugin; use wcf\system\package\plugin\TemplatePackageInstallationPlugin; -use wcf\system\Regex; -use wcf\util\DirectoryUtil; use wcf\util\FileUtil; /** @@ -39,13 +37,55 @@ class DevtoolsPackageArchive extends PackageArchive $projectDir = FileUtil::addTrailingSlash( FileUtil::unifyDirSeparator(\realpath(\dirname($this->packageXmlPath))) ); - $readFiles = DirectoryUtil::getInstance($projectDir)->getFiles( - \SORT_ASC, - // ignore folders whose contents are delivered as archives by default - // and ignore dotfiles and dotdirectories - Regex::compile('^' . \preg_quote($projectDir) . '(acptemplates|files|templates|\.)'), - true + + $it = new \RecursiveIteratorIterator( + new \RecursiveCallbackFilterIterator( + new \RecursiveDirectoryIterator($projectDir), + static function (\SplFileInfo $current, string $key, \RecursiveDirectoryIterator $it) { + // Skip '.' and '..'. + if ($it->isDot()) { + return false; + } + + // Skip hidden files. + if ($current->getFilename()[0] === '.') { + return false; + } + + if ($current->isDir()) { + // Check if we are in the project root. + if ($it->getSubPath() === '') { + // Skip acptemplates / files / templates. + if ( + \preg_match( + '/^(acptemplates|files|templates)(_[a-z0-9]+)?$/', + $current->getFilename() + ) + ) { + return false; + } + + // Skip node_modules and vendor. + if (\preg_match('/^(node_modules|vendor)$/', $current->getFilename())) { + return false; + } + + // Skip TypeScript source files. + if (\preg_match('/^ts$/', $current->getFilename())) { + return false; + } + } + + return true; + } + + return true; + } + ) ); + $readFiles = \array_map(static function (\SplFileInfo $f) { + return $f->getPathname(); + }, \iterator_to_array($it)); $files = []; foreach ($readFiles as $file) { -- 2.20.1