Update require message and delete empty file at the end in case of failure, fixes #3260
parent
109f4ffd5e
commit
2e1373b339
|
@ -139,7 +139,7 @@ php composer.phar update vendor/*
|
||||||
## require
|
## require
|
||||||
|
|
||||||
The `require` command adds new packages to the `composer.json` file from
|
The `require` command adds new packages to the `composer.json` file from
|
||||||
the current directory.
|
the current directory. If no file exists one will be created on the fly.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
php composer.phar require
|
php composer.phar require
|
||||||
|
|
|
@ -59,6 +59,7 @@ EOT
|
||||||
{
|
{
|
||||||
$file = Factory::getComposerFile();
|
$file = Factory::getComposerFile();
|
||||||
|
|
||||||
|
$newlyCreated = !file_exists($file);
|
||||||
if (!file_exists($file) && !file_put_contents($file, "{\n}\n")) {
|
if (!file_exists($file) && !file_put_contents($file, "{\n}\n")) {
|
||||||
$output->writeln('<error>'.$file.' could not be created.</error>');
|
$output->writeln('<error>'.$file.' could not be created.</error>');
|
||||||
|
|
||||||
|
@ -105,7 +106,7 @@ EOT
|
||||||
$json->write($composer);
|
$json->write($composer);
|
||||||
}
|
}
|
||||||
|
|
||||||
$output->writeln('<info>'.$file.' has been updated</info>');
|
$output->writeln('<info>'.$file.' has been '.($newlyCreated ? 'created' : 'updated').'</info>');
|
||||||
|
|
||||||
if ($input->getOption('no-update')) {
|
if ($input->getOption('no-update')) {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -134,8 +135,13 @@ EOT
|
||||||
|
|
||||||
$status = $install->run();
|
$status = $install->run();
|
||||||
if ($status !== 0) {
|
if ($status !== 0) {
|
||||||
$output->writeln("\n".'<error>Installation failed, reverting '.$file.' to its original content.</error>');
|
if ($newlyCreated) {
|
||||||
file_put_contents($json->getPath(), $composerBackup);
|
$output->writeln("\n".'<error>Installation failed, deleting '.$file.'.</error>');
|
||||||
|
unlink($json->getPath());
|
||||||
|
} else {
|
||||||
|
$output->writeln("\n".'<error>Installation failed, reverting '.$file.' to its original content.</error>');
|
||||||
|
file_put_contents($json->getPath(), $composerBackup);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $status;
|
return $status;
|
||||||
|
|
Loading…
Reference in New Issue