1
0
Fork 0

Fix exit codes, cc @tyrael

pull/2452/merge
Jordi Boggiano 2013-11-22 16:17:02 +01:00
parent 99e260adf0
commit e126c92525
6 changed files with 19 additions and 16 deletions

View File

@ -173,8 +173,9 @@ EOT
$installer->disablePlugins(); $installer->disablePlugins();
} }
if (!$installer->run()) { $status = $installer->run();
return 1; if (0 !== $status) {
return $status;
} }
} }

View File

@ -107,6 +107,6 @@ EOT
$install->disablePlugins(); $install->disablePlugins();
} }
return $install->run() ? 0 : 1; return $install->run();
} }
} }

View File

@ -123,14 +123,13 @@ EOT
->setUpdateWhitelist(array_keys($requirements)); ->setUpdateWhitelist(array_keys($requirements));
; ;
if (!$install->run()) { $status = $install->run();
if ($status !== 0) {
$output->writeln("\n".'<error>Installation failed, reverting '.$file.' to its original content.</error>'); $output->writeln("\n".'<error>Installation failed, reverting '.$file.' to its original content.</error>');
file_put_contents($json->getPath(), $composerBackup); file_put_contents($json->getPath(), $composerBackup);
return 1;
} }
return 0; return $status;
} }
private function updateFileCleanly($json, array $base, array $new, $requireKey) private function updateFileCleanly($json, array $base, array $new, $requireKey)

View File

@ -115,6 +115,6 @@ EOT
$install->disablePlugins(); $install->disablePlugins();
} }
return $install->run() ? 0 : 1; return $install->run();
} }
} }

View File

@ -146,6 +146,8 @@ class Installer
/** /**
* Run installation (or update) * Run installation (or update)
*
* @return int 0 on success or a positive error code on failure
*/ */
public function run() public function run()
{ {
@ -205,8 +207,9 @@ class Installer
try { try {
$this->suggestedPackages = array(); $this->suggestedPackages = array();
if (!$this->doInstall($localRepo, $installedRepo, $platformRepo, $aliases, $this->devMode)) { $res = $this->doInstall($localRepo, $installedRepo, $platformRepo, $aliases, $this->devMode);
return false; if ($res !== 0) {
return $res;
} }
} catch (\Exception $e) { } catch (\Exception $e) {
$this->installationManager->notifyInstalls(); $this->installationManager->notifyInstalls();
@ -286,7 +289,7 @@ class Installer
} }
} }
return true; return 0;
} }
protected function doInstall($localRepo, $installedRepo, $platformRepo, $aliases, $withDevReqs) protected function doInstall($localRepo, $installedRepo, $platformRepo, $aliases, $withDevReqs)
@ -448,7 +451,7 @@ class Installer
$this->io->write('<error>Your requirements could not be resolved to an installable set of packages.</error>'); $this->io->write('<error>Your requirements could not be resolved to an installable set of packages.</error>');
$this->io->write($e->getMessage()); $this->io->write($e->getMessage());
return false; return max(1, $e->getCode());
} }
// force dev packages to be updated if we update or install from a (potentially new) lock // force dev packages to be updated if we update or install from a (potentially new) lock
@ -533,7 +536,7 @@ class Installer
} }
} }
return true; return 0;
} }
/** /**

View File

@ -72,7 +72,7 @@ class InstallerTest extends TestCase
$installer = new Installer($io, $config, clone $rootPackage, $downloadManager, $repositoryManager, $locker, $installationManager, $eventDispatcher, $autoloadGenerator); $installer = new Installer($io, $config, clone $rootPackage, $downloadManager, $repositoryManager, $locker, $installationManager, $eventDispatcher, $autoloadGenerator);
$result = $installer->run(); $result = $installer->run();
$this->assertTrue($result); $this->assertSame(0, $result);
$expectedInstalled = isset($options['install']) ? $options['install'] : array(); $expectedInstalled = isset($options['install']) ? $options['install'] : array();
$expectedUpdated = isset($options['update']) ? $options['update'] : array(); $expectedUpdated = isset($options['update']) ? $options['update'] : array();
@ -206,7 +206,7 @@ class InstallerTest extends TestCase
->setDevMode($input->getOption('dev')) ->setDevMode($input->getOption('dev'))
->setDryRun($input->getOption('dry-run')); ->setDryRun($input->getOption('dry-run'));
return $installer->run() ? 0 : 1; return $installer->run();
}); });
$application->get('update')->setCode(function ($input, $output) use ($installer) { $application->get('update')->setCode(function ($input, $output) use ($installer) {
@ -217,7 +217,7 @@ class InstallerTest extends TestCase
->setUpdateWhitelist($input->getArgument('packages')) ->setUpdateWhitelist($input->getArgument('packages'))
->setWhitelistDependencies($input->getOption('with-dependencies')); ->setWhitelistDependencies($input->getOption('with-dependencies'));
return $installer->run() ? 0 : 1; return $installer->run();
}); });
if (!preg_match('{^(install|update)\b}', $run)) { if (!preg_match('{^(install|update)\b}', $run)) {