Browse Source

RequireCommand - rollback if it fails (fixes #1469)

Bilal Amarni 12 years ago
parent
commit
99e4173b3d
1 changed files with 7 additions and 1 deletions
  1. 7 1
      src/Composer/Command/RequireCommand.php

+ 7 - 1
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".'<error>Installation failed, reverting '.$file.' to its original content.</error>');
+            file_put_contents($json->getPath(), $composerBackup);
+
+            return 1;
+        }
     }
 
     private function updateFileCleanly($json, array $base, array $new, $requireKey)