dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.26k stars 4.73k forks source link

Ordered evaluation in FileSystemGlobbing Matcher #109408

Open kasperk81 opened 6 days ago

kasperk81 commented 6 days ago

Description:

I am encountering a limitation with Microsoft.Extensions.FileSystemGlobbing where the evaluation order of include and exclude patterns does not work as expected. I would like to request an enhancement to allow includes and excludes to be evaluated in the order they are added to the Matcher.

Current Behavior

When setting up the Matcher with the following patterns:

Matcher m = new();
m.AddInclude("**/*");
m.AddExclude("ExcludeMe/**/*");
m.AddInclude("ExcludeMe/ButActuallyIncludeMe/**/*");

And executing it against the following directory structure:

root/
  - helloWorld.txt
  - ExcludeMe/
      - notIncluded.txt
      - ButActuallyIncludeMe/
          - hiEarth.txt

Actual Output:

Expected Behavior

I expect the output to be:

Expected Output:

Suggested Improvement

To achieve the expected behavior, the Matcher should respect the order of operations for includes and excludes, allowing later includes to override earlier excludes. This would provide more intuitive control over file selection.

Originally posted by @Benjin in https://github.com/dotnet/runtime/issues/21362#issuecomment-1311106263

kasperk81 commented 6 days ago

repro https://dotnetfiddle.net/qawrpG

dotnet-policy-service[bot] commented 6 days ago

Tagging subscribers to this area: @dotnet/area-extensions-filesystem See info in area-owners.md if you want to be subscribed.