From 28e9193e9ebde743c19f334a7294830fc6429d06 Mon Sep 17 00:00:00 2001 From: Niels Keurentjes Date: Sat, 16 Apr 2016 21:01:10 +0200 Subject: [PATCH 1/2] Check temp folder usability before runtime to prevent weird errors. --- src/Composer/Console/Application.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Composer/Console/Application.php b/src/Composer/Console/Application.php index bcc0582df..60b3eef14 100644 --- a/src/Composer/Console/Application.php +++ b/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(); From 43eb471ec293822d377b618a4a14d8d3651f5d13 Mon Sep 17 00:00:00 2001 From: Niels Keurentjes Date: Tue, 19 Apr 2016 01:39:32 +0200 Subject: [PATCH 2/2] Code cleanup and ensure checked file is unique. --- src/Composer/Console/Application.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Composer/Console/Application.php b/src/Composer/Console/Application.php index 60b3eef14..0ac9c92c7 100644 --- a/src/Composer/Console/Application.php +++ b/src/Composer/Console/Application.php @@ -150,9 +150,8 @@ class Application extends BaseApplication // 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)) { + $tempfile = sys_get_temp_dir() . '/temp-' . md5(microtime()); + if (!(file_put_contents($tempfile, __FILE__) && (file_get_contents($tempfile) == __FILE__) && unlink($tempfile) && !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())); } });