Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14103981
D18979.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D18979.diff
View Options
diff --git a/src/filesystem/FileFinder.php b/src/filesystem/FileFinder.php
--- a/src/filesystem/FileFinder.php
+++ b/src/filesystem/FileFinder.php
@@ -107,38 +107,56 @@
* @task internal
*/
public function validateFile($file) {
- $matches = !count($this->name) && !count($this->suffix);
- foreach ($this->name as $curr_name) {
- if (basename($file) === $curr_name) {
- $matches = true;
- break;
+
+ if ($this->name) {
+ $matches = false;
+ foreach ($this->name as $curr_name) {
+ if (basename($file) === $curr_name) {
+ $matches = true;
+ break;
+ }
}
- }
- foreach ($this->suffix as $curr_suffix) {
- if (fnmatch($curr_suffix, $file)) {
- $matches = true;
- break;
+
+ if (!$matches) {
+ return false;
}
}
- if (!$matches) {
- return false;
+
+ if ($this->suffix) {
+ $matches = false;
+ foreach ($this->suffix as $curr_suffix) {
+ if (fnmatch($curr_suffix, $file)) {
+ $matches = true;
+ break;
+ }
+ }
+
+ if (!$matches) {
+ return false;
+ }
}
- $matches = (count($this->paths) == 0);
- foreach ($this->paths as $path) {
- if (fnmatch($path, $this->root.'/'.$file)) {
- $matches = true;
- break;
+ if ($this->paths) {
+ $matches = false;
+ foreach ($this->paths as $path) {
+ if (fnmatch($path, $this->root.'/'.$file)) {
+ $matches = true;
+ break;
+ }
+ }
+
+ if (!$matches) {
+ return false;
}
}
$fullpath = $this->root.'/'.ltrim($file, '/');
if (($this->type == 'f' && is_dir($fullpath))
|| ($this->type == 'd' && !is_dir($fullpath))) {
- $matches = false;
+ return false;
}
- return $matches;
+ return true;
}
/**
@@ -225,10 +243,12 @@
$args[] = $this->type;
}
- if ($this->name || $this->suffix) {
- $command[] = $this->generateList('name', array_merge(
- $this->name,
- $this->suffix));
+ if ($this->name) {
+ $command[] = $this->generateList('name', $this->name);
+ }
+
+ if ($this->suffix) {
+ $command[] = $this->generateList('name', $this->suffix);
}
if ($this->paths) {
diff --git a/src/filesystem/__tests__/FileFinderTestCase.php b/src/filesystem/__tests__/FileFinderTestCase.php
--- a/src/filesystem/__tests__/FileFinderTestCase.php
+++ b/src/filesystem/__tests__/FileFinderTestCase.php
@@ -162,4 +162,20 @@
}
}
+ public function testFinderWithNameAndSuffix() {
+ foreach (array('php', 'shell') as $mode) {
+ $files = $this->getFinder()
+ ->withType('f')
+ ->withName('alsoinclude.txt')
+ ->withSuffix('txt')
+ ->setForceMode($mode)
+ ->find();
+
+ $this->assertEqual(
+ array(
+ 'include_dir.txt/subdir.txt/alsoinclude.txt',
+ ),
+ $files);
+ }
+ }
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Nov 27, 11:15 PM (2 h, 29 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6797125
Default Alt Text
D18979.diff (2 KB)
Attached To
Mode
D18979: Make FileFinder's withName() + withSuffix() work like every other Query class
Attached
Detach File
Event Timeline
Log In to Comment