Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1bd1c15

Browse filesBrowse files
[Process] Fix pipes cleaning on Windows
1 parent a0cdcb0 commit 1bd1c15
Copy full SHA for 1bd1c15

File tree

1 file changed

+24
-21
lines changed
Filter options

1 file changed

+24
-21
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Process/Pipes/WindowsPipes.php
+24-21Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,24 @@ public function __construct($disableOutput, $input)
4747
// Workaround for this problem is to use temporary files instead of pipes on Windows platform.
4848
//
4949
// @see https://bugs.php.net/bug.php?id=51800
50-
$this->files = array(
51-
Process::STDOUT => tempnam(sys_get_temp_dir(), 'out_sf_proc'),
52-
Process::STDERR => tempnam(sys_get_temp_dir(), 'err_sf_proc'),
50+
$pipes = array(
51+
Process::STDOUT => Process::OUT,
52+
Process::STDERR => Process::ERR,
5353
);
54-
foreach ($this->files as $offset => $file) {
55-
if (false === $file || false === $this->fileHandles[$offset] = @fopen($file, 'rb')) {
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');
54+
$tmpDir = sys_get_temp_dir();
55+
if (!@fopen($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+
for ($i = 0;; ++$i) {
59+
foreach ($pipes as $pipe => $name) {
60+
@unlink($file = sprintf('%s\\sf_proc_%02X.%s', $tmpDir, $i, $name));
61+
$h = @fopen($file, 'xb');
62+
if (!$h || !$this->fileHandles[$pipe] = fopen($file, 'rb')) {
63+
continue 2;
64+
}
65+
$this->files[$pipe] = $file;
5766
}
67+
break;
5868
}
5969
}
6070

@@ -64,7 +74,6 @@ public function __construct($disableOutput, $input)
6474
public function __destruct()
6575
{
6676
$this->close();
67-
$this->removeFiles();
6877
}
6978

7079
/**
@@ -125,7 +134,8 @@ public function readAndWrite($blocking, $close = false)
125134
}
126135
if ($close) {
127136
fclose($fileHandle);
128-
unset($this->fileHandles[$type]);
137+
@unlink($this->files[$type]);
138+
unset($this->fileHandles[$type], $this->files[$type]);
129139
}
130140
}
131141

@@ -146,10 +156,16 @@ public function areOpen()
146156
public function close()
147157
{
148158
parent::close();
159+
149160
foreach ($this->fileHandles as $handle) {
150161
fclose($handle);
151162
}
152163
$this->fileHandles = array();
164+
165+
foreach ($this->files as $filename) {
166+
@unlink($filename);
167+
}
168+
$this->files = array();
153169
}
154170

155171
/**
@@ -164,17 +180,4 @@ public static function create(Process $process, $input)
164180
{
165181
return new static($process->isOutputDisabled(), $input);
166182
}
167-
168-
/**
169-
* Removes temporary files.
170-
*/
171-
private function removeFiles()
172-
{
173-
foreach ($this->files as $filename) {
174-
if (file_exists($filename)) {
175-
@unlink($filename);
176-
}
177-
}
178-
$this->files = array();
179-
}
180183
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.