Skip to content

Commit 935c8b5

Browse files
committed
Fixed bug #1758 : PHPCS gets stuck creating file list when processing circular symlinks
1 parent 790c617 commit 935c8b5

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
101101
- Fixed bug #1731 : Directory exclusions do not work as expected when a single file name is passed to phpcs
102102
- Fixed bug #1746 : Very large reports can sometimes become garbled when using the parallel option
103103
- Fixed bug #1757 : Unknown type hint "object" in Squiz.Commenting.FunctionComment
104+
- Fixed bug #1758 : PHPCS gets stuck creating file list when processing circular symlinks
104105
</notes>
105106
<contents>
106107
<dir name="/">

src/Filters/Filter.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ class Filter extends \RecursiveFilterIterator
5050
*/
5151
protected $ignoreFilePatterns = null;
5252

53+
/**
54+
* A list of file paths we've already accepted.
55+
*
56+
* Used to ensure we aren't following circular symlinks.
57+
*
58+
* @var array
59+
*/
60+
protected $acceptedPaths = [];
61+
5362

5463
/**
5564
* Constructs a filter.
@@ -82,7 +91,18 @@ public function __construct($iterator, $basedir, Config $config, Ruleset $rulese
8291
public function accept()
8392
{
8493
$filePath = $this->current();
94+
$realPath = Util\Common::realpath($filePath);
8595

96+
if ($realPath !== false) {
97+
// It's a real path somewhere, so record it
98+
// to check for circular symlinks.
99+
if (isset($this->acceptedPaths[$realPath]) === true) {
100+
// We've been here before.
101+
return false;
102+
}
103+
}
104+
105+
$filePath = $this->current();
86106
if (is_dir($filePath) === true) {
87107
if ($this->config->local === true) {
88108
return false;
@@ -95,6 +115,7 @@ public function accept()
95115
return false;
96116
}
97117

118+
$this->acceptedPaths[$realPath] = true;
98119
return true;
99120

100121
}//end accept()
@@ -120,6 +141,7 @@ public function getChildren()
120141
// Set the ignore patterns so we don't have to generate them again.
121142
$children->ignoreDirPatterns = $this->ignoreDirPatterns;
122143
$children->ignoreFilePatterns = $this->ignoreFilePatterns;
144+
$children->acceptedPaths = $this->acceptedPaths;
123145
return $children;
124146

125147
}//end getChildren()

0 commit comments

Comments
 (0)