[Process] Strengthen Windows pipe files opening (again...)

This commit is contained in:
Nicolas Grekas 2016-08-09 16:15:57 +02:00
parent f8764736bd
commit a7a2d16511
1 changed files with 8 additions and 3 deletions

View File

@ -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));
}