From 93b5f5d2091f95bb4a31c7d0b4ea80ff65cad2b2 Mon Sep 17 00:00:00 2001 From: Nicholas Narsing Date: Sun, 11 Jun 2017 16:57:27 -0400 Subject: [PATCH 1/2] Exclude directories from file system search Directories can also match the glob search pattern if their names end in ".php", which will cause a read error later since the ContentRetriever implementers are expecting files. As far as I know, the only way to fix this is to do an additional check to ensure the URI is not of a directory. This resolves #306. --- src/FilesFinder/ClientFilesFinder.php | 3 ++- src/FilesFinder/FileSystemFilesFinder.php | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/FilesFinder/ClientFilesFinder.php b/src/FilesFinder/ClientFilesFinder.php index 4315edee..799f0662 100644 --- a/src/FilesFinder/ClientFilesFinder.php +++ b/src/FilesFinder/ClientFilesFinder.php @@ -39,7 +39,8 @@ public function find(string $glob): Promise $uris = []; foreach ($textDocuments as $textDocument) { $path = Uri\parse($textDocument->uri)['path']; - if (Glob::match($path, $glob)) { + // Also exclude any directories that also match the glob pattern + if (Glob::match($path, $glob) && !is_dir($path)) { $uris[] = $textDocument->uri; } } diff --git a/src/FilesFinder/FileSystemFilesFinder.php b/src/FilesFinder/FileSystemFilesFinder.php index 52df4b61..a26b5d89 100644 --- a/src/FilesFinder/FileSystemFilesFinder.php +++ b/src/FilesFinder/FileSystemFilesFinder.php @@ -22,7 +22,11 @@ public function find(string $glob): Promise return coroutine(function () use ($glob) { $uris = []; foreach (new GlobIterator($glob) as $path) { - $uris[] = pathToUri($path); + // Exclude any directories that also match the glob pattern + if (!is_dir($path)) { + $uris[] = pathToUri($path); + } + yield timeout(); } return $uris; From ff2191f765da356c751ab4c9daff529520b4bd74 Mon Sep 17 00:00:00 2001 From: Nicholas Narsing Date: Sun, 11 Jun 2017 17:12:27 -0400 Subject: [PATCH 2/2] Undo directory check in ClientFilesFinder Upon further inspection, it seems that the workspace should never contain a directory, so it should be safe. --- src/FilesFinder/ClientFilesFinder.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/FilesFinder/ClientFilesFinder.php b/src/FilesFinder/ClientFilesFinder.php index 799f0662..4315edee 100644 --- a/src/FilesFinder/ClientFilesFinder.php +++ b/src/FilesFinder/ClientFilesFinder.php @@ -39,8 +39,7 @@ public function find(string $glob): Promise $uris = []; foreach ($textDocuments as $textDocument) { $path = Uri\parse($textDocument->uri)['path']; - // Also exclude any directories that also match the glob pattern - if (Glob::match($path, $glob) && !is_dir($path)) { + if (Glob::match($path, $glob)) { $uris[] = $textDocument->uri; } }