diff --git a/src/Ramstack.FileProviders.Globbing/GlobbingFileProvider.cs b/src/Ramstack.FileProviders.Globbing/GlobbingFileProvider.cs
index 634f735..6021836 100644
--- a/src/Ramstack.FileProviders.Globbing/GlobbingFileProvider.cs
+++ b/src/Ramstack.FileProviders.Globbing/GlobbingFileProvider.cs
@@ -71,8 +71,14 @@ public IDirectoryContents GetDirectoryContents(string subpath)
{
subpath = FilePath.Normalize(subpath);
- var directory = _provider.GetDirectoryContents(subpath);
- return new GlobbingDirectoryContents(this, subpath, directory);
+ if (!IsExcluded(subpath))
+ {
+ var directory = _provider.GetDirectoryContents(subpath);
+ if (directory is not NotFoundDirectoryContents)
+ return new GlobbingDirectoryContents(this, subpath, directory);
+ }
+
+ return NotFoundDirectoryContents.Singleton;
}
///
@@ -109,7 +115,7 @@ private sealed class GlobbingDirectoryContents : IDirectoryContents
private readonly IDirectoryContents _directory;
///
- public bool Exists => !_provider.IsExcluded(_directoryPath) && _directory.Exists;
+ public bool Exists => _directory.Exists;
///
/// Initializes a new instance of the class.
diff --git a/tests/Ramstack.FileProviders.Tests/GlobbingFileProviderTests.cs b/tests/Ramstack.FileProviders.Tests/GlobbingFileProviderTests.cs
index 14373df..1c6f7fd 100644
--- a/tests/Ramstack.FileProviders.Tests/GlobbingFileProviderTests.cs
+++ b/tests/Ramstack.FileProviders.Tests/GlobbingFileProviderTests.cs
@@ -27,6 +27,57 @@ public void Setup()
public void Cleanup() =>
_storage.Dispose();
+ [Test]
+ public void ExcludedDirectory_HasNoFileNodes()
+ {
+ using var storage = new TempFileStorage();
+ var fs = new GlobbingFileProvider(new PhysicalFileProvider(storage.Root), "**", exclude: "/project/src/**");
+
+ var directories = new[]
+ {
+ "/project/src",
+ "/project/src/App",
+ "/project/src/Modules",
+ "/project/src/Modules/Module1",
+ "/project/src/Modules/Module1/Submodule",
+ "/project/src/Modules/Module2"
+ };
+
+ foreach (var path in directories)
+ {
+ var directory = fs.GetDirectory(path);
+
+ Assert.That(
+ directory.Exists,
+ Is.False);
+
+ Assert.That(
+ directory.EnumerateFileNodes("**").Count(),
+ Is.Zero);
+ }
+
+ var files = new[]
+ {
+ "/project/src/App/App.csproj",
+ "/project/src/App/Program.cs",
+ "/project/src/App/Utils.cs",
+ "/project/src/Modules/Module1/Module1.cs",
+ "/project/src/Modules/Module1/Module1.csproj",
+ "/project/src/Modules/Module1/Submodule/Submodule1.cs",
+ "/project/src/Modules/Module1/Submodule/Submodule2.cs",
+ "/project/src/Modules/Module1/Submodule/Submodule.csproj",
+ "/project/src/Modules/Module2/Module2.cs",
+ "/project/src/Modules/Module2/Module2.csproj",
+ "/project/src/App.sln"
+ };
+
+ foreach (var path in files)
+ {
+ var file = fs.GetFile(path);
+ Assert.That(file.Exists, Is.False);
+ }
+ }
+
protected override IFileProvider GetFileProvider()
{
var provider = new PhysicalFileProvider(_storage.Root);