Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/Ramstack.FileProviders.Globbing/GlobbingFileProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/// <inheritdoc />
Expand Down Expand Up @@ -109,7 +115,7 @@ private sealed class GlobbingDirectoryContents : IDirectoryContents
private readonly IDirectoryContents _directory;

/// <inheritdoc />
public bool Exists => !_provider.IsExcluded(_directoryPath) && _directory.Exists;
public bool Exists => _directory.Exists;

/// <summary>
/// Initializes a new instance of the <see cref="GlobbingDirectoryContents"/> class.
Expand Down
51 changes: 51 additions & 0 deletions tests/Ramstack.FileProviders.Tests/GlobbingFileProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down