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

Skip to content

Commit 36e67f5

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

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,27 +52,30 @@ 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+
$error = '';
56+
set_error_handler(function ($type, $msg) use (&$error) { $error = $msg; });
5957
for ($i = 0;; ++$i) {
6058
foreach ($pipes as $pipe => $name) {
6159
$file = sprintf('%s\\sf_proc_%02X.%s', $tmpDir, $i, $name);
62-
if (file_exists($file) && !@unlink($file)) {
60+
if (file_exists($file) && !unlink($file)) {
6361
continue 2;
6462
}
65-
$h = @fopen($file, 'xb');
63+
$h = fopen($file, 'xb');
64+
if (!$h && false === strpos($error, '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+
}
6668
if (!$h || !$this->fileHandles[$pipe] = fopen($file, 'rb')) {
6769
continue 2;
6870
}
6971
if (isset($this->files[$pipe])) {
70-
@unlink($this->files[$pipe]);
72+
unlink($this->files[$pipe]);
7173
}
7274
$this->files[$pipe] = $file;
7375
}
7476
break;
7577
}
78+
restore_error_handler();
7679
}
7780

7881
parent::__construct($input);

0 commit comments

Comments
 (0)
0