8000 ignoreDotFiles(true) does not exclude folders properly · nathanlon/symfony@573c6b4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 573c6b4

Browse files
committed
ignoreDotFiles(true) does not exclude folders properly
1 parent 8b89ce3 commit 573c6b4

9 files changed

+42
-24
lines changed

src/Symfony/Component/Finder/Finder.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,12 +594,14 @@ private function searchInDirectory($dir)
594594
$this->exclude = array_merge($this->exclude, self::$vcsPatterns);
595595
}
596596

597+
$extraPatterns = array();
597598
if (static::IGNORE_DOT_FILES === (static::IGNORE_DOT_FILES & $this->ignore)) {
598599
$this->notNames[] = '/^\..+/';
600+
$extraPatterns[] = '#(^|/)\.#';
599601
}
600602

601-
if ($this->exclude) {
602-
$iterator = new Iterator\ExcludeDirectoryFilterIterator($iterator, $this->exclude);
603+
if ($this->exclude || $extraPatterns) {
604+
$iterator = new Iterator\ExcludeDirectoryFilterIterator($iterator, $this->exclude, $extraPatterns);
603605
}
604606

605607
if ($this->names || $this->notNames) {

src/Symfony/Component/Finder/Iterator/ExcludeDirectoryFilterIterator.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,23 @@ class ExcludeDirectoryFilterIterator extends \FilterIterator
2323
/**
2424
* Constructor.
2525
*
26-
* @param \Iterator $iterator The Iterator to filter
27-
* @param array $directories An array of directories to exclude
26+
* @param \Iterator $iterator The Iterator to filter
27+
* @param array $directories An array of directories to exclude
28+
* @param array $extraPatterns An array of regex patterns to exclude
2829
*/
29-
public function __construct(\Iterator $iterator, array $directories)
30+
public function __construct(\Iterator $iterator, array $directories, array $extraPatterns = null)
3031
{
3132
$this->patterns = array();
3233
foreach ($directories as $directory) {
3334
$this->patterns[] = '#(^|/)'.preg_quote($directory, '#').'(/|$)#';
3435
}
3536

37+
if (!is_null($extraPatterns)) {
38+
foreach ($extraPatterns as $pattern) {
39+
$this->patterns[] = $pattern;
< B41A /code>
40+
}
41+
}
42+
3643
parent::__construct($iterator);
3744
}
3845

src/Symfony/Component/Finder/Tests/FinderTest.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,27 +130,26 @@ public function testIgnoreVCS()
130130
{
131131
$finder = new Finder();
132132
$this->assertSame($finder, $finder->ignoreVCS(false)->ignoreDotFiles(false));
133-
$this->assertIterator($this->toAbsolute(array('.git', 'foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', '.bar', '.foo', '.foo/.bar')), $finder->in(self::$tmpDir)->getIterator());
133+
$this->assertIterator($this->toAbsolute(array('.git', 'foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', '.bar', '.foo', '.foo/.bar', '.foo/bar')), $finder->in(self::$tmpDir)->getIterator());
134134

135135
$finder = new Finder();
136136
$finder->ignoreVCS(false)->ignoreVCS(false)->ignoreDotFiles(false);
137-
$this->assertIterator($this->toAbsolute(array('.git', 'foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', '.bar', '.foo', '.foo/.bar')), $finder->in(self::$tmpDir)->getIterator());
137+
$this->assertIterator($this->toAbsolute(array('.git', 'foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', '.bar', '.foo', '.foo/.bar', '.foo/bar')), $finder->in(self::$tmpDir)->getIterator());
138138

139139
$finder = new Finder();
140140
$this->assertSame($finder, $finder->ignoreVCS(true)->ignoreDotFiles(false));
141-
$this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', '.bar', '.foo', '.foo/.bar')), $finder->in(self::$tmpDir)->getIterator());
142-
141+
$this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', '.bar', '.foo', '.foo/.bar', '.foo/bar')), $finder->in(self::$tmpDir)->getIterator());
143142
}
144143

145144
public function testIgnoreDotFiles()
146145
{
147146
$finder = new Finder();
148147
$this->assertSame($finder, $finder->ignoreDotFiles(false)->ignoreVCS(false));
149-
$this->assertIterator($this->toAbsolute(array('.git', '.bar', '.foo', '.foo/.bar', 'foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto')), $finder->in(self::$tmpDir)->getIterator());
148+
$this->assertIterator($this->toAbsolute(array('.git', '.bar', '.foo', '.foo/.bar', '.foo/bar', 'foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto')), $finder->in(self::$tmpDir)->getIterator());
150149

151150
$finder = new Finder();
152151
$finder->ignoreDotFiles(false)->ignoreDotFiles(false)->ignoreVCS(false);
153-
$this->assertIterator($this->toAbsolute(array('.git', '.bar', '.foo', '.foo/.bar', 'foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto')), $finder->in(self::$tmpDir)->getIterator());
152+
$this->assertIterator($this->toAbsolute(array('.git', '.bar', '.foo', '.foo/.bar', '.foo/bar', 'foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto')), $finder->in(self::$tmpDir)->getIterator());
154153

155154
$finder = new Finder();
156155
$this->assertSame($finder, $finder->ignoreDotFiles(true)->ignoreVCS(false));

src/Symfony/Component/Finder/Tests/Iterator/DateRangeFilterIteratorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ public function testAccept($size, $expected)
3131
public function getAcceptData()
3232
{
3333
return array(
34-
array(array(new DateComparator('since 20 years ago')), array(sys_get_temp_dir().'/symfony2_finder/.git', sys_get_temp_dir().'/symfony2_finder/test.py', sys_get_temp_dir().'/symfony2_finder/foo', sys_get_temp_dir().'/symfony2_finder/foo/bar.tmp', sys_get_temp_dir().'/symfony2_finder/test.php', sys_get_temp_dir().'/symfony2_finder/toto', sys_get_temp_dir().'/symfony2_finder/.bar', sys_get_temp_dir().'/symfony2_finder/.foo', sys_get_temp_dir().'/symfony2_finder/.foo/.bar')),
35-
array(array(new DateComparator('since 2 months ago')), array(sys_get_temp_dir().'/symfony2_finder/.git', sys_get_temp_dir().'/symfony2_finder/test.py', sys_get_temp_dir().'/symfony2_finder/foo', sys_get_temp_dir().'/symfony2_finder/toto', sys_get_temp_dir().'/symfony2_finder/.bar', sys_get_temp_dir().'/symfony2_finder/.foo', sys_get_temp_dir().'/symfony2_finder/.foo/.bar')),
34+
array(array(new DateComparator('since 20 years ago')), array(sys_get_temp_dir().'/symfony2_finder/.git', sys_get_temp_dir().'/symfony2_finder/test.py', sys_get_temp_dir().'/symfony2_finder/foo', sys_get_temp_dir().'/symfony2_finder/foo/bar.tmp', sys_get_temp_dir().'/symfony2_finder/test.php', sys_get_temp_dir().'/symfony2_finder/toto', sys_get_temp_dir().'/symfony2_finder/.bar', sys_get_temp_dir().'/symfony2_finder/.foo', sys_get_temp_dir().'/symfony2_finder/.foo/.bar', sys_get_temp_dir().'/symfony2_finder/.foo/bar')),
35+
array(array(new DateComparator('since 2 months ago')), array(sys_get_temp_dir().'/symfony2_finder/.git', sys_get_temp_dir().'/symfony2_finder/test.py', sys_get_temp_dir().'/symfony2_finder/foo', sys_get_temp_dir().'/symfony2_finder/toto', sys_get_temp_dir().'/symfony2_finder/.bar', sys_get_temp_dir().'/symfony2_finder/.foo', sys_get_temp_dir().'/symfony2_finder/.foo/.bar', sys_get_temp_dir().'/symfony2_finder/.foo/bar')),
3636
array(array(new DateComparator('until last month')), array(sys_get_temp_dir().'/symfony2_finder/.git', sys_get_temp_dir().'/symfony2_finder/foo', sys_get_temp_dir().'/symfony2_finder/foo/bar.tmp', sys_get_temp_dir().'/symfony2_finder/test.php', sys_get_temp_dir().'/symfony2_finder/toto', sys_get_temp_dir().'/symfony2_finder/.foo')),
3737
);
3838
}

src/Symfony/Component/Finder/Tests/Iterator/DepthRangeIteratorTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ public function getAcceptData()
3535
{
3636
return array(
3737
array(array(new NumberComparator('< 1')), array($this->getAbsolutePath('/.git'), $this->getAbsolutePath('/test.py'), $this->getAbsolutePath('/foo'), $this->getAbsolutePath('/test.php'), $this->getAbsolutePath('/toto'), $this->getAbsolutePath('/.foo'), $this->getAbsolutePath('/.bar'))),
38-
array(array(new NumberComparator('<= 1')), array($this->getAbsolutePath('/.git'), $this->getAbsolutePath('/test.py'), $this->getAbsolutePath('/foo'), $this->getAbsolutePath('/foo/bar.tmp'), $this->getAbsolutePath('/test.php'), $this->getAbsolutePath('/toto'), $this->getAbsolutePath('/.foo'), $this->getAbsolutePath('/.foo/.bar'), $this->getAbsolutePath('/.bar'))),
38+
array(array(new NumberComparator('<= 1')), array($this->getAbsolutePath('/.git'), $this->getAbsolutePath('/test.py'), $this->getAbsolutePath('/foo'), $this->getAbsolutePath('/foo/bar.tmp'), $this->getAbsolutePath('/test.php'), $this->getAbsolutePath('/toto'), $this->getAbsolutePath('/.foo'), $this->getAbsolutePath('/.foo/.bar'), $this->getAbsolutePath('/.foo/bar'), $this->getAbsolutePath('/.bar'))),
3939
array(array(new NumberComparator('> 1')), array()),
40-
array(array(new NumberComparator('>= 1')), array($this->getAbsolutePath('/foo/bar.tmp'), $this->getAbsolutePath('/.foo/.bar'))),
41-
array(array(new NumberComparator('1')), array($this->getAbsolutePath('/foo/bar.tmp'), $this->getAbsolutePath('/.foo/.bar'))),
40+
array(array(new NumberComparator('>= 1')), array($this->getAbsolutePath('/foo/bar.tmp'), $this->getAbsolutePath('/.foo/.bar'), $this->getAbsolutePath('/.foo/bar'))),
41+
array(array(new NumberComparator('1')), array($this->getAbsolutePath('/foo/bar.tmp'), $this->getAbsolutePath('/.foo/.bar'), $this->getAbsolutePath('/.foo/bar'))),
4242
);
4343
}
4444

src/Symfony/Component/Finder/Tests/Iterator/ExcludeDirectoryFileIteratorTest.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ class ExcludeDirectoryFilterIteratorTest extends RealIteratorTestCase
1818
/**
1919
* @dataProvider getAcceptData
2020
*/
21-
public function testAccept($directories, $expected)
21+
public function testAccept($directories, $extraPatterns, $expected)
2222
{
2323
$inner = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(sys_get_temp_dir().'/symfony2_finder', \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST);
2424

25-
$iterator = new ExcludeDirectoryFilterIterator($inner, $directories);
25+
$iterator = new ExcludeDirectoryFilterIterator($inner, $directories, $extraPatterns);
2626

2727
$this->assertIterator($expected, $iterator);
2828
}
@@ -32,26 +32,35 @@ public function getAcceptData()
3232
$tmpDir = sys_get_temp_dir().'/symfony2_finder';
3333

3434
return array(
35-
array(array('foo'), array(
35+
array(array('foo'), null, array(
3636
$tmpDir.DIRECTORY_SEPARATOR.'.bar',
3737
$tmpDir.DIRECTORY_SEPARATOR.'.foo',
3838
$tmpDir.DIRECTORY_SEPARATOR.'.foo'.DIRECTORY_SEPARATOR.'.bar',
39+
$tmpDir.DIRECTORY_SEPARATOR.'.foo'.DIRECTORY_SEPARATOR.'bar',
3940
$tmpDir.DIRECTORY_SEPARATOR.'.git',
4041
$tmpDir.DIRECTORY_SEPARATOR.'test.py',
4142
$tmpDir.DIRECTORY_SEPARATOR.'test.php',
4243
$tmpDir.DIRECTORY_SEPARATOR.'toto'
4344
)),
44-
array(array('fo'), array(
45+
array(array('fo'), null, array(
4546
$tmpDir.DIRECTORY_SEPARATOR.'.bar',
4647
$tmpDir.DIRECTORY_SEPARATOR.'.foo',
4748
$tmpDir.DIRECTORY_SEPARATOR.'.foo'.DIRECTORY_SEPARATOR.'.bar',
49+
$tmpDir.DIRECTORY_SEPARATOR.'.foo'.DIRECTORY_SEPARATOR.'bar',
4850
$tmpDir.DIRECTORY_SEPARATOR.'.git',
4951
$tmpDir.DIRECTORY_SEPARATOR.'test.py',
5052
$tmpDir.DIRECTORY_SEPARATOR.'foo',
5153
$tmpDir.DIRECTORY_SEPARATOR.'foo'.DIRECTORY_SEPARATOR.'bar.tmp',
5254
$tmpDir.DIRECTORY_SEPARATOR.'test.php',
5355
$tmpDir.DIRECTORY_SEPARATOR.'toto'
5456
)),
57+
array(array('toto'), array('#^\.#'), array(
58+
$tmpDir.DIRECTORY_SEPARATOR.'.bar',
59+
$tmpDir.DIRECTORY_SEPARATOR.'test.py',
60+
$tmpDir.DIRECTORY_SEPARATOR.'foo',
61+
$tmpDir.DIRECTORY_SEPARATOR.'foo'.DIRECTORY_SEPARATOR.'bar.tmp',
62+
$tmpDir.DIRECTORY_SEPARATOR.'test.php',
63+
)),
5564
);
5665
}
5766
}

src/Symfony/Component/Finder/Tests/Iterator/FileTypeFilterIteratorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function testAccept($mode, $expected)
3030
public function getAcceptData()
3131
{
3232
return array(
33-
array(FileTypeFilterIterator::ONLY_FILES, array(sys_get_temp_dir().'/symfony2_finder/test.py', sys_get_temp_dir().'/symfony2_finder/foo/bar.tmp', sys_get_temp_dir().'/symfony2_finder/test.php', sys_get_temp_dir().'/symfony2_finder/.bar', sys_get_temp_dir().'/symfony2_finder/.foo/.bar')),
33+
array(FileTypeFilterIterator::ONLY_FILES, array(sys_get_temp_dir().'/symfony2_finder/test.py', sys_get_temp_dir().'/symfony2_finder/foo/bar.tmp', sys_get_temp_dir().'/symfony2_finder/test.php', sys_get_temp_dir().'/symfony2_finder/.bar', sys_get_temp_dir().'/symfony2_finder/.foo/.bar', sys_get_temp_dir().'/symfony2_finder/.foo/bar')),
3434
array(FileTypeFilterIterator::ONLY_DIRECTORIES, array(sys_get_temp_dir().'/symfony2_finder/.git', sys_get_temp_dir().'/symfony2_finder/foo', sys_get_temp_dir().'/symfony2_finder/toto', sys_get_temp_dir().'/symfony2_finder/.foo')),
3535
);
3636
}

src/Symfony/Component/Finder/Tests/Iterator/RealIteratorTestCase.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ static public function setUpBeforeClass()
2222
$tmpDir.'/.git/',
2323
$tmpDir.'/.foo/',
2424
$tmpDir.'/.foo/.bar',
25+
$tmpDir.'/.foo/bar',
2526
$tmpDir.'/.bar',
2627
$tmpDir.'/test.py',
2728
$tmpDir.'/foo/',

src/Symfony/Component/Finder/Tests/Iterator/SortableIteratorTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ public function testAccept($mode, $expected)
4040
public function getAcceptData()
4141
{
4242
return array(
43-
array(SortableIterator::SORT_BY_NAME, array(sys_get_temp_dir().'/symfony2_finder/.bar', sys_get_temp_dir().'/symfony2_finder/.foo', sys_get_temp_dir().'/symfony2_finder/.foo/.bar', sys_get_temp_dir().'/symfony2_finder/.git', sys_get_temp_dir().'/symfony2_finder/foo', sys_get_temp_dir().'/symfony2_finder/foo/bar.tmp', sys_get_temp_dir().'/symfony2_finder/test.php', sys_get_temp_dir().'/symfony2_finder/test.py', sys_get_temp_dir().'/symfony2_finder/toto')),
44-
array(SortableIterator::SORT_BY_TYPE, array(sys_get_temp_dir().'/symfony2_finder/.foo', sys_get_temp_dir().'/symfony2_finder/.git', sys_get_temp_dir().'/symfony2_finder/foo', sys_get_temp_dir().'/symfony2_finder/toto', sys_get_temp_dir().'/symfony2_finder/.bar', sys_get_temp_dir().'/symfony2_finder/.foo/.bar', sys_get_temp_dir().'/symfony2_finder/foo/bar.tmp', sys_get_temp_dir().'/symfony2_finder/test.php', sys_get_temp_dir().'/symfony2_finder/test.py')),
45-
array(function (\SplFileInfo $a, \SplFileInfo $b) { return strcmp($a->getRealpath(), $b->getRealpath()); }, array(sys_get_temp_dir().'/symfony2_finder/.bar', sys_get_temp_dir().'/symfony2_finder/.foo', sys_get_temp_dir().'/symfony2_finder/.foo/.bar', sys_get_temp_dir().'/symfony2_finder/.git', sys_get_temp_dir().'/symfony2_finder/foo', sys_get_temp_dir().'/symfony2_finder/foo/bar.tmp', sys_get_temp_dir().'/symfony2_finder/test.php', sys_get_temp_dir().'/symfony2_finder/test.py', sys_get_temp_dir().'/symfony2_finder/toto')),
43+
array(SortableIterator::SORT_BY_NAME, array(sys_get_temp_dir().'/symfony2_finder/.bar', sys_get_temp_dir().'/symfony2_finder/.foo', sys_get_temp_dir().'/symfony2_finder/.foo/.bar', sys_get_temp_dir().'/symfony2_finder/.foo/bar', sys_get_temp_dir().'/symfony2_finder/.git', sys_get_temp_dir().'/symfony2_finder/foo', sys_get_temp_dir().'/symfony2_finder/foo/bar.tmp', sys_get_temp_dir().'/symfony2_finder/test.php', sys_get_temp_dir().'/symfony2_finder/test.py', sys_get_temp_dir().'/symfony2_finder/toto')),
44+
array(SortableIterator::SORT_BY_TYPE, array(sys_get_temp_dir().'/symfony2_finder/.foo', sys_get_temp_dir().'/symfony2_finder/.git', sys_get_temp_dir().'/symfony2_finder/foo', sys_get_temp_dir().'/symfony2_finder/toto', sys_get_temp_dir().'/symfony2_finder/.bar', sys_get_temp_dir().'/symfony2_finder/.foo/.bar', sys_get_temp_dir().'/symfony2_finder/.foo/bar', sys_get_temp_dir().'/symfony2_finder/foo/bar.tmp', sys_get_temp_dir().'/symfony2_finder/test.php', sys_get_temp_dir().'/symfony2_finder/test.py')),
45+
array(function (\SplFileInfo $a, \SplFileInfo $b) { return strcmp($a->getRealpath(), $b->getRealpath()); }, array(sys_get_temp_dir().'/symfony2_finder/.bar', sys_get_temp_dir().'/symfony2_finder/.foo', sys_get_temp_dir().'/symfony2_finder/.foo/.bar', sys_get_temp_dir().'/symfony2_finder/.foo/bar', sys_get_temp_dir().'/symfony2_finder/.git', sys_get_temp_dir().'/symfony2_finder/foo', sys_get_temp_dir().'/symfony2_finder/foo/bar.tmp', sys_get_temp_dir().'/symfony2_finder/test.php', sys_get_temp_dir().'/symfony2_finder/test.py', sys_get_temp_dir().'/symfony2_finder/toto')),
4646
);
4747
}
4848
}

0 commit comments

Comments
 (0)
0