Browse Source

Check temp folder usability before runtime to prevent weird errors.

Niels Keurentjes 9 years ago
parent
commit
28e9193e9e
1 changed files with 9 additions and 0 deletions
  1. 9 0
      src/Composer/Console/Application.php

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

@@ -148,6 +148,15 @@ class Application extends BaseApplication
                 Silencer::call('exec', 'sudo -K > /dev/null 2>&1');
             }
 
+            // Check system temp folder for usability as it can cause weird runtime issues otherwise
+            Silencer::call(function() {
+                $tempfile = sys_get_temp_dir() . '/tempchk.tmp';
+                $usable = file_put_contents($tempfile, __FILE__) && (file_get_contents($tempfile) == __FILE__) && unlink($tempfile);
+                if (!$usable || file_exists($tempfile)) {
+                    throw new \RuntimeException(sprintf('PHP temp directory "%s" does not exist or is not writable to Composer - check sys_temp_dir in your php.ini', sys_get_temp_dir()));
+                }
+            });
+
             // switch working dir
             if ($newWorkDir = $this->getNewWorkingDir($input)) {
                 $oldWorkingDir = getcwd();