1
0
Fork 0

Execute operations in batches to make sure plugins install in the expected order

pull/8952/head
Jordi Boggiano 2020-06-05 11:11:31 +02:00
parent 9f380d606c
commit 87a0fc5506
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
2 changed files with 87 additions and 63 deletions

View File

@ -62,6 +62,7 @@ abstract class ArchiveDownloader extends FileDownloader
} while (is_dir($temporaryDir));
$this->addCleanupPath($package, $temporaryDir);
$this->addCleanupPath($package, $path);
$this->filesystem->ensureDirectoryExists($temporaryDir);
$fileName = $this->getFileName($package, $path);
@ -77,6 +78,7 @@ abstract class ArchiveDownloader extends FileDownloader
$filesystem->removeDirectory($path);
$filesystem->removeDirectory($temporaryDir);
$self->removeCleanupPath($package, $temporaryDir);
$self->removeCleanupPath($package, $path);
};
$promise = null;
@ -142,6 +144,7 @@ abstract class ArchiveDownloader extends FileDownloader
$filesystem->removeDirectory($temporaryDir);
$self->removeCleanupPath($package, $temporaryDir);
$self->removeCleanupPath($package, $path);
}, function ($e) use ($cleanup) {
$cleanup();

View File

@ -272,6 +272,52 @@ class InstallationManager
$this->loop->wait($promises);
}
// execute operations in batches to make sure every plugin is installed in the
// right order and activated before the packages depending on it are installed
while ($operations) {
$batch = array();
foreach ($operations as $index => $operation) {
unset($operations[$index]);
$batch[$index] = $operation;
if (in_array($operation->getOperationType(), array('update', 'install'), true)) {
$package = $operation->getOperationType() === 'update' ? $operation->getTargetPackage() : $operation->getPackage();
if ($package->getType() === 'composer-plugin' || $package->getType() === 'composer-installer') {
break;
}
}
}
$this->executeBatch($repo, $batch, $cleanupPromises, $devMode, $runScripts);
}
} catch (\Exception $e) {
$runCleanup();
if ($handleInterruptsUnix) {
pcntl_signal(SIGINT, $prevHandler);
}
if ($handleInterruptsWindows) {
sapi_windows_set_ctrl_handler($prevHandler, false);
}
throw $e;
}
if ($handleInterruptsUnix) {
pcntl_signal(SIGINT, $prevHandler);
}
if ($handleInterruptsWindows) {
sapi_windows_set_ctrl_handler($prevHandler, false);
}
// do a last write so that we write the repository even if nothing changed
// as that can trigger an update of some files like InstalledVersions.php if
// running a new composer version
$repo->write($devMode, $this);
}
private function executeBatch(RepositoryInterface $repo, array $operations, array $cleanupPromises, $devMode, $runScripts)
{
foreach ($operations as $index => $operation) {
$opType = $operation->getOperationType();
@ -302,7 +348,6 @@ class InstallationManager
$dispatcher = $this->eventDispatcher;
$installManager = $this;
$loop = $this->loop;
$io = $this->io;
$promise = $installer->prepare($opType, $package, $initialPackage);
@ -332,7 +377,7 @@ class InstallationManager
// execute all prepare => installs/updates/removes => cleanup steps
if (!empty($promises)) {
$progress = null;
if ($io instanceof ConsoleIO && !$io->isDebug()) {
if ($io instanceof ConsoleIO && !$io->isDebug() && count($promises) > 1) {
$progress = $io->getProgressBar();
}
$this->loop->wait($promises, $progress);
@ -340,30 +385,6 @@ class InstallationManager
$progress->clear();
}
}
} catch (\Exception $e) {
$runCleanup();
if ($handleInterruptsUnix) {
pcntl_signal(SIGINT, $prevHandler);
}
if ($handleInterruptsWindows) {
sapi_windows_set_ctrl_handler($prevHandler, false);
}
throw $e;
}
if ($handleInterruptsUnix) {
pcntl_signal(SIGINT, $prevHandler);
}
if ($handleInterruptsWindows) {
sapi_windows_set_ctrl_handler($prevHandler, false);
}
// do a last write so that we write the repository even if nothing changed
// as that can trigger an update of some files like InstalledVersions.php if
// running a new composer version
$repo->write($devMode, $this);
}
/**