瀏覽代碼

Output error if the disk is full, fixes #1952

Jordi Boggiano 12 年之前
父節點
當前提交
3057949a2e
共有 2 個文件被更改,包括 37 次插入0 次删除
  1. 15 0
      src/Composer/Command/DiagnoseCommand.php
  2. 22 0
      src/Composer/Console/Application.php

+ 15 - 0
src/Composer/Command/DiagnoseCommand.php

@@ -81,6 +81,9 @@ EOT
             }
         }
 
+        $output->write('Checking disk free space: ');
+        $this->outputResult($output, $this->checkDiskSpace($config));
+
         $output->write('Checking composer version: ');
         $this->outputResult($output, $this->checkVersion());
 
@@ -213,6 +216,18 @@ EOT
         }
     }
 
+    private function checkDiskSpace($config)
+    {
+        $minSpaceFree = 1024*1024;
+        if ((($df = disk_free_space($dir = $config->get('home'))) !== false && $df < $minSpaceFree)
+            || (($df = disk_free_space($dir = $config->get('vendor-dir'))) !== false && $df < $minSpaceFree)
+        ) {
+            return '<error>The disk hosting '.$dir.' is full, this may be the cause of the following exception</error>';
+        }
+
+        return true;
+    }
+
     private function checkVersion()
     {
         $protocol = extension_loaded('openssl') ? 'https' : 'http';

+ 22 - 0
src/Composer/Console/Application.php

@@ -141,6 +141,28 @@ class Application extends BaseApplication
         return $workingDir;
     }
 
+    /**
+     * {@inheritDoc}
+     */
+    public function renderException($e, $output)
+    {
+        try {
+            $composer = $this->getComposer(false);
+            if ($composer) {
+                $config = $composer->getConfig();
+
+                $minSpaceFree = 1024*1024;
+                if ((($df = disk_free_space($dir = $config->get('home'))) !== false && $df < $minSpaceFree)
+                    || (($df = disk_free_space($dir = $config->get('vendor-dir'))) !== false && $df < $minSpaceFree)
+                ) {
+                    $output->writeln('<error>The disk hosting '.$dir.' is full, this may be the cause of the following exception</error>');
+                }
+            }
+        } catch (\Exception $e) {}
+
+        return parent::renderException($e, $output);
+    }
+
     /**
      * @param  bool                    $required
      * @throws JsonValidationException