Make sure cleanup is called for every package in case any operation fails to execute
parent
55f122008b
commit
8b0da77a1d
|
@ -196,6 +196,8 @@ class InstallationManager
|
||||||
$this->loop->wait($promises);
|
$this->loop->wait($promises);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$cleanupPromises = array();
|
||||||
|
try {
|
||||||
foreach ($operations as $operation) {
|
foreach ($operations as $operation) {
|
||||||
$opType = $operation->getOperationType();
|
$opType = $operation->getOperationType();
|
||||||
|
|
||||||
|
@ -234,11 +236,14 @@ class InstallationManager
|
||||||
$promise = new \React\Promise\Promise(function ($resolve, $reject) { $resolve(); });
|
$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) {
|
$promise = $promise->then(function () use ($opType, $installManager, $repo, $operation) {
|
||||||
return $installManager->$opType($repo, $operation);
|
return $installManager->$opType($repo, $operation);
|
||||||
})->then(function () use ($opType, $installer, $package, $initialPackage) {
|
})->then($cleanupPromise)
|
||||||
return $installer->cleanup($opType, $package, $initialPackage);
|
->then(function () use ($opType, $runScripts, $dispatcher, $installManager, $devMode, $repo, $operations, $operation) {
|
||||||
})->then(function () use ($opType, $runScripts, $dispatcher, $installManager, $devMode, $repo, $operations, $operation) {
|
|
||||||
$repo->write($devMode, $installManager);
|
$repo->write($devMode, $installManager);
|
||||||
|
|
||||||
$event = 'Composer\Installer\PackageEvents::POST_PACKAGE_'.strtoupper($opType);
|
$event = 'Composer\Installer\PackageEvents::POST_PACKAGE_'.strtoupper($opType);
|
||||||
|
@ -248,20 +253,37 @@ class InstallationManager
|
||||||
}, function ($e) use ($opType, $installer, $package, $initialPackage, $loop, $io) {
|
}, function ($e) use ($opType, $installer, $package, $initialPackage, $loop, $io) {
|
||||||
$io->writeError(' <error>' . ucfirst($opType) .' of '.$package->getPrettyName().' failed</error>');
|
$io->writeError(' <error>' . ucfirst($opType) .' of '.$package->getPrettyName().' failed</error>');
|
||||||
|
|
||||||
$promise = $installer->cleanup($opType, $package, $initialPackage);
|
|
||||||
if ($promise) {
|
|
||||||
$loop->wait(array($promise));
|
|
||||||
}
|
|
||||||
|
|
||||||
throw $e;
|
throw $e;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$cleanupPromises[] = $cleanupPromise;
|
||||||
$promises[] = $promise;
|
$promises[] = $promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($promises)) {
|
if (!empty($promises)) {
|
||||||
$this->loop->wait($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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue