From 99e4173b3d2e6018b40958e5c306931855f76fd2 Mon Sep 17 00:00:00 2001 From: Bilal Amarni Date: Fri, 1 Feb 2013 10:24:05 +0100 Subject: [PATCH] RequireCommand - rollback if it fails (fixes #1469) --- src/Composer/Command/RequireCommand.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Composer/Command/RequireCommand.php b/src/Composer/Command/RequireCommand.php index 425481572..10522aee7 100644 --- a/src/Composer/Command/RequireCommand.php +++ b/src/Composer/Command/RequireCommand.php @@ -69,6 +69,7 @@ EOT $json = new JsonFile($file); $composer = $json->read(); + $composerBackup = file_get_contents($json->getPath()); $requirements = $this->determineRequirements($input, $output, $input->getArgument('packages')); @@ -106,7 +107,12 @@ EOT ->setUpdateWhitelist($requirements); ; - return $install->run() ? 0 : 1; + if (!$install->run()) { + $output->writeln("\n".'Installation failed, reverting '.$file.' to its original content.'); + file_put_contents($json->getPath(), $composerBackup); + + return 1; + } } private function updateFileCleanly($json, array $base, array $new, $requireKey)