Skip to content

Commit

Permalink
Fixed bug #1758 : PHPCS gets stuck creating file list when processing…
Browse files Browse the repository at this point in the history
… circular symlinks
  • Loading branch information
gsherwood committed Nov 23, 2017
1 parent 790c617 commit 935c8b5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
- Fixed bug #1731 : Directory exclusions do not work as expected when a single file name is passed to phpcs
- Fixed bug #1746 : Very large reports can sometimes become garbled when using the parallel option
- Fixed bug #1757 : Unknown type hint "object" in Squiz.Commenting.FunctionComment
- Fixed bug #1758 : PHPCS gets stuck creating file list when processing circular symlinks
</notes>
<contents>
<dir name="/">
Expand Down
22 changes: 22 additions & 0 deletions src/Filters/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ class Filter extends \RecursiveFilterIterator
*/
protected $ignoreFilePatterns = null;

/**
* A list of file paths we've already accepted.
*
* Used to ensure we aren't following circular symlinks.
*
* @var array
*/
protected $acceptedPaths = [];


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

if ($realPath !== false) {
// It's a real path somewhere, so record it
// to check for circular symlinks.
if (isset($this->acceptedPaths[$realPath]) === true) {
// We've been here before.
return false;
}
}

$filePath = $this->current();
if (is_dir($filePath) === true) {
if ($this->config->local === true) {
return false;
Expand All @@ -95,6 +115,7 @@ public function accept()
return false;
}

$this->acceptedPaths[$realPath] = true;
return true;

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

}//end getChildren()
Expand Down

0 comments on commit 935c8b5

Please sign in to comment.