1
0
Fork 0

Make sure cleanup is called for every package in case any operation fails to execute

pull/8754/head
Jordi Boggiano 2020-04-09 10:48:48 +02:00
parent 55f122008b
commit 8b0da77a1d
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
1 changed files with 81 additions and 59 deletions

View File

@ -196,6 +196,8 @@ class InstallationManager
$this->loop->wait($promises);
}
$cleanupPromises = array();
try {
foreach ($operations as $operation) {
$opType = $operation->getOperationType();
@ -234,11 +236,14 @@ class InstallationManager
$promise = new \React\Promise\Promise(function ($resolve, $reject) { $resolve(); });
}
$cleanupPromise = function () use ($opType, $installer, $package, $initialPackage) {
return $installer->cleanup($opType, $package, $initialPackage);
};
$promise = $promise->then(function () use ($opType, $installManager, $repo, $operation) {
return $installManager->$opType($repo, $operation);
})->then(function () use ($opType, $installer, $package, $initialPackage) {
return $installer->cleanup($opType, $package, $initialPackage);
})->then(function () use ($opType, $runScripts, $dispatcher, $installManager, $devMode, $repo, $operations, $operation) {
})->then($cleanupPromise)
->then(function () use ($opType, $runScripts, $dispatcher, $installManager, $devMode, $repo, $operations, $operation) {
$repo->write($devMode, $installManager);
$event = 'Composer\Installer\PackageEvents::POST_PACKAGE_'.strtoupper($opType);
@ -248,20 +253,37 @@ class InstallationManager
}, function ($e) use ($opType, $installer, $package, $initialPackage, $loop, $io) {
$io->writeError(' <error>' . ucfirst($opType) .' of '.$package->getPrettyName().' failed</error>');
$promise = $installer->cleanup($opType, $package, $initialPackage);
if ($promise) {
$loop->wait(array($promise));
}
throw $e;
});
$cleanupPromises[] = $cleanupPromise;
$promises[] = $promise;
}
if (!empty($promises)) {
$this->loop->wait($promises);
}
} catch (\Exception $e) {
$promises = array();
foreach ($cleanupPromises as $cleanup) {
$promises[] = new \React\Promise\Promise(function ($resolve, $reject) use ($cleanup) {
$promise = $cleanup();
if (null === $promise) {
$resolve();
} else {
$promise->then(function () use ($resolve) {
$resolve();
});
}
});
}
if (!empty($promises)) {
$this->loop->wait($promises);
}
throw $e;
}
}
/**