From a7a2d16511f6f932007f54e187d84572b87c8909 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 9 Aug 2016 16:15:57 +0200 Subject: [PATCH] [Process] Strengthen Windows pipe files opening (again...) --- src/Symfony/Component/Process/Pipes/WindowsPipes.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Process/Pipes/WindowsPipes.php b/src/Symfony/Component/Process/Pipes/WindowsPipes.php index db66c672a7..7b2e5b4b23 100644 --- a/src/Symfony/Component/Process/Pipes/WindowsPipes.php +++ b/src/Symfony/Component/Process/Pipes/WindowsPipes.php @@ -51,9 +51,10 @@ class WindowsPipes extends AbstractPipes Process::STDOUT => Process::OUT, Process::STDERR => Process::ERR, ); + $tmpCheck = false; $tmpDir = sys_get_temp_dir(); - $error = 'unknown reason'; - set_error_handler(function ($type, $msg) use (&$error) { $error = $msg; }); + $lastError = 'unknown reason'; + set_error_handler(function ($type, $msg) use (&$lastError) { $lastError = $msg; }); for ($i = 0;; ++$i) { foreach ($pipes as $pipe => $name) { $file = sprintf('%s\\sf_proc_%02X.%s', $tmpDir, $i, $name); @@ -61,7 +62,11 @@ class WindowsPipes extends AbstractPipes continue 2; } $h = fopen($file, 'xb'); - if (!$h && false === strpos($error, 'File exists')) { + if (!$h) { + $error = $lastError; + if ($tmpCheck || $tmpCheck = unlink(tempnam(false, 'sf_check_'))) { + continue; + } restore_error_handler(); throw new RuntimeException(sprintf('A temporary file could not be opened to write the process output: %s', $error)); }