Skip to content

fix: convert Finder lazy iterator to array before deletion #2663

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 28 additions & 26 deletions src/Task/Composer.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,35 +34,37 @@ public static function cleanup(
) {
$composer = $event->getComposer();
$extra = $composer->getPackage()->getExtra();
$servicesToKeep = isset($extra['google/apiclient-services'])
? $extra['google/apiclient-services']
: [];
if ($servicesToKeep) {
$vendorDir = $composer->getConfig()->get('vendor-dir');
$servicesToKeep = $extra['google/apiclient-services'] ?? [];
if (empty($servicesToKeep)) {
return;
}
$vendorDir = $composer->getConfig()->get('vendor-dir');
$serviceDir = sprintf(
'%s/google/apiclient-services/src/Google/Service',
$vendorDir
);
if (!is_dir($serviceDir)) {
// path for google/apiclient-services >= 0.200.0
$serviceDir = sprintf(
'%s/google/apiclient-services/src/Google/Service',
'%s/google/apiclient-services/src',
$vendorDir
);
if (!is_dir($serviceDir)) {
// path for google/apiclient-services >= 0.200.0
$serviceDir = sprintf(
'%s/google/apiclient-services/src',
$vendorDir
);
}
self::verifyServicesToKeep($serviceDir, $servicesToKeep);
$finder = self::getServicesToRemove($serviceDir, $servicesToKeep);
$filesystem = $filesystem ?: new Filesystem();
if (0 !== $count = count($finder)) {
$event->getIO()->write(
sprintf('Removing %s google services', $count)
);
foreach ($finder as $file) {
$realpath = $file->getRealPath();
$filesystem->remove($realpath);
$filesystem->remove($realpath . '.php');
}
}
}
self::verifyServicesToKeep($serviceDir, $servicesToKeep);
$finder = self::getServicesToRemove($serviceDir, $servicesToKeep);
$filesystem = $filesystem ?: new Filesystem();
$servicesToRemoveCount = $finder->count();
if (0 === $servicesToRemoveCount) {
return;
}
$event->getIO()->write(
sprintf('Removing %d google services', $servicesToRemoveCount)
);
$pathsToRemove = iterator_to_array($finder);
foreach ($pathsToRemove as $pathToRemove) {
$realpath = $pathToRemove->getRealPath();
$filesystem->remove($realpath);
$filesystem->remove($realpath . '.php');
}
}

Expand Down
Loading