Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f9ba34f

Browse files
bug #19428 [Process] Fix write access check for pipes on Windows (nicolas-grekas)
This PR was merged into the 2.7 branch. Discussion ---------- [Process] Fix write access check for pipes on Windows | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #19336, #19416 | License | MIT | Doc PR | - Commits ------- 66e694e [Process] Fix write access check for pipes on Windows
2 parents 76dbd3c + 66e694e commit f9ba34f

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($disableOutput, $input)
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 = 'unknown reason';
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(sprintf('A temporary file could not be opened to write the process output: %s', $error));
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)