Browse Source

Rollback changes in case the installer fails in remove/require commands, fixes #3464

Jordi Boggiano 9 years ago
parent
commit
823266407f
2 changed files with 18 additions and 2 deletions
  1. 9 1
      src/Composer/Command/RemoveCommand.php
  2. 9 1
      src/Composer/Command/RequireCommand.php

+ 9 - 1
src/Composer/Command/RemoveCommand.php

@@ -116,11 +116,19 @@ EOT
             ->setIgnorePlatformRequirements($input->getOption('ignore-platform-reqs'))
         ;
 
-        $status = $install->run();
+        $exception = null;
+        try {
+            $status = $install->run();
+        } catch (\Exception $exception) {
+            $status = 1;
+        }
         if ($status !== 0) {
             $io->writeError("\n".'<error>Removal failed, reverting '.$file.' to its original content.</error>');
             file_put_contents($jsonFile->getPath(), $composerBackup);
         }
+        if ($exception) {
+            throw $exception;
+        }
 
         return $status;
     }

+ 9 - 1
src/Composer/Command/RequireCommand.php

@@ -165,7 +165,12 @@ EOT
             ->setIgnorePlatformRequirements($input->getOption('ignore-platform-reqs'))
         ;
 
-        $status = $install->run();
+        $exception = null;
+        try {
+            $status = $install->run();
+        } catch (\Exception $exception) {
+            $status = 1;
+        }
         if ($status !== 0) {
             if ($newlyCreated) {
                 $io->writeError("\n".'<error>Installation failed, deleting '.$file.'.</error>');
@@ -175,6 +180,9 @@ EOT
                 file_put_contents($json->getPath(), $composerBackup);
             }
         }
+        if ($exception) {
+            throw $exception;
+        }
 
         return $status;
     }