8000 [Process] Fix write access check for pipes on Windows · symfony/symfony@8a1ac8d · GitHub
[go: up one dir, main page]

Skip to content

Commit 8a1ac8d

Browse files
[Process] Fix write access check for pipes on Windows
1 parent eccbe67 commit 8a1ac8d

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/Symfony/Component/Process/Pipes/WindowsPipes.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,20 @@ public function __construct($input, $haveReadSupport)
5252
Process::STDERR => Process::ERR,
5353
);
5454
$tmpDir = sys_get_temp_dir();
55-
if (!@fopen($file = $tmpDir.'\\sf_proc_00.check', 'wb')) {
56-
throw new RuntimeException('A temporary file could not be opened to write the process output to, verify that your TEMP environment variable is writable');
57-
}
58-
@unlink($file);
55+
set_error_handler(function () { return false; });
5956
for ($i = 0;; ++$i) {
6057
foreach ($pipes as $pipe => $name) {
6158
$file = sprintf('%s\\sf_proc_%02X.%s', $tmpDir, $i, $name);
6259
if (file_exists($file) && !@unlink($file)) {
6360
continue 2;
6461
}
65-
$h = @fopen($file, 'xb');
62+
if (!$h = @fopen($file, 'xb')) {
63+
$e = error_get_last();
64+
if (!$e || false === strpos($e['message'], 'File exists')) {
65+
restore_error_handler();
66+
throw new RuntimeException('A temporary file could not be opened to write the process output to, verify that your TEMP environment variable is writable');
67+
}
68+
}
6669
if (!$h || !$this->fileHandles[$pipe] = fopen($file, 'rb')) {
6770
continue 2;
6871
}
@@ -73,6 +76,7 @@ public function __construct($input, $haveReadSupport)
7376
}
7477
break;
7578
}
79+
restore_error_handler();
7680
}
7781

7882
parent::__construct($input);

0 commit comments

Comments
 (0)
0