From 66e694ed57ed76cf0b2d8b960ee505a87a8fd054 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 25 Jul 2016 22:35:22 +0200 Subject: [PATCH] [Process] Fix write access check for pipes on Windows --- .../Component/Process/Pipes/WindowsPipes.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Symfony/Component/Process/Pipes/WindowsPipes.php b/src/Symfony/Component/Process/Pipes/WindowsPipes.php index 071dd0334a74..db66c672a7da 100644 --- a/src/Symfony/Component/Process/Pipes/WindowsPipes.php +++ b/src/Symfony/Component/Process/Pipes/WindowsPipes.php @@ -52,27 +52,30 @@ public function __construct($disableOutput, $input) Process::STDERR => Process::ERR, ); $tmpDir = sys_get_temp_dir(); - if (!@fopen($file = $tmpDir.'\\sf_proc_00.check', 'wb')) { - throw new RuntimeException('A temporary file could not be opened to write the process output to, verify that your TEMP environment variable is writable'); - } - @unlink($file); + $error = 'unknown reason'; + set_error_handler(function ($type, $msg) use (&$error) { $error = $msg; }); for ($i = 0;; ++$i) { foreach ($pipes as $pipe => $name) { $file = sprintf('%s\\sf_proc_%02X.%s', $tmpDir, $i, $name); - if (file_exists($file) && !@unlink($file)) { + if (file_exists($file) && !unlink($file)) { continue 2; } - $h = @fopen($file, 'xb'); + $h = fopen($file, 'xb'); + if (!$h && false === strpos($error, 'File exists')) { + restore_error_handler(); + throw new RuntimeException(sprintf('A temporary file could not be opened to write the process output: %s', $error)); + } if (!$h || !$this->fileHandles[$pipe] = fopen($file, 'rb')) { continue 2; } if (isset($this->files[$pipe])) { - @unlink($this->files[$pipe]); + unlink($this->files[$pipe]); } $this->files[$pipe] = $file; } break; } + restore_error_handler(); } parent::__construct($input);