dotnet / runtime

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

FileSystemGlobbingMatcher produces wrong stems #97333

Open StefanBertels opened 10 months ago

StefanBertels commented 10 months ago

Description

When using patterns like a*\b*\c*.ext the results contain stems with increasing length, containing parts of previous results.

Reproduction Steps

var matcher = new Microsoft.Extensions.FileSystemGlobbing.Matcher(StringComparison.OrdinalIgnoreCase);
matcher.AddInclude(@"sys*\1*\*.dll");
matcher.AddExclude(@"systemtemp");
matcher.AddExclude(@"systemtemp\*");
var result = matcher.Execute(new Microsoft.Extensions.FileSystemGlobbing.Abstractions.DirectoryInfoWrapper(new DirectoryInfo(@"c:\windows")));
foreach (var element in result.Files.Take(7)) // just output first 7 lines
{
    Console.WriteLine(element.Stem + " => " + element.Path);
}

My hard disk contains these files:

C:\Windows\System32\1028\VsGraphicsResources.dll
C:\Windows\System32\1028\vsjitdebuggerui.dll
C:\Windows\System32\1029\VsGraphicsResources.dll
C:\Windows\System32\1029\vsjitdebuggerui.dll
C:\Windows\System32\1031\VsGraphicsResources.dll
C:\Windows\System32\1031\vsjitdebuggerui.dll
C:\Windows\System32\1033\VsGraphicsResources.dll
C:\Windows\System32\1033\vsjitdebuggerui.dll
...

Expected behavior

Output should look like

System32/1028/VsGraphicsResources.dll => System32/1028/VsGraphicsResources.dll
System32/1028/vsjitdebuggerui.dll => System32/1028/vsjitdebuggerui.dll                                                               
System32/1029/VsGraphicsResources.dll => System32/1029/VsGraphicsResources.dll                                                  
System32/1029/vsjitdebuggerui.dll => System32/1029/vsjitdebuggerui.dll                                                          
System32/1031/VsGraphicsResources.dll => System32/1031/VsGraphicsResources.dll                                             
System32/1031/vsjitdebuggerui.dll => System32/1031/vsjitdebuggerui.dll                                                     
System32/1033/VsGraphicsResources.dll => System32/1033/VsGraphicsResources.dll     

Actual behavior

Output looks like

System32/1028/VsGraphicsResources.dll => System32/1028/VsGraphicsResources.dll
System32/1028/vsjitdebuggerui.dll => System32/1028/vsjitdebuggerui.dll                                                               
System32/1028/1029/VsGraphicsResources.dll => System32/1029/VsGraphicsResources.dll                                                  
System32/1028/1029/vsjitdebuggerui.dll => System32/1029/vsjitdebuggerui.dll                                                          
System32/1028/1029/1031/VsGraphicsResources.dll => System32/1031/VsGraphicsResources.dll                                             
System32/1028/1029/1031/vsjitdebuggerui.dll => System32/1031/vsjitdebuggerui.dll                                                     
System32/1028/1029/1031/1033/VsGraphicsResources.dll => System32/1033/VsGraphicsResources.dll     

Regression?

No response

Known Workarounds

No response

Configuration

.NET 8.0.101 Win 10 22H2 (OS Build 19045.3930) x64 FilesystemGlobbing v8.0.0

Other information

No response

ghost commented 10 months ago

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

Issue Details
### Description When using patterns like `a*\b*\c*.ext` the results contain stems with increasing length, containing parts of previous results. ### Reproduction Steps ``` var matcher = new Microsoft.Extensions.FileSystemGlobbing.Matcher(StringComparison.OrdinalIgnoreCase); matcher.AddInclude(@"sys*\1*\*.dll"); matcher.AddExclude(@"systemtemp"); matcher.AddExclude(@"systemtemp\*"); var result = matcher.Execute(new Microsoft.Extensions.FileSystemGlobbing.Abstractions.DirectoryInfoWrapper(new DirectoryInfo(@"c:\windows"))); foreach (var element in result.Files.Take(7)) // just output first 7 lines { Console.WriteLine(element.Stem + " => " + element.Path); } ``` My hard disk contains these files: ``` C:\Windows\System32\1028\VsGraphicsResources.dll C:\Windows\System32\1028\vsjitdebuggerui.dll C:\Windows\System32\1029\VsGraphicsResources.dll C:\Windows\System32\1029\vsjitdebuggerui.dll C:\Windows\System32\1031\VsGraphicsResources.dll C:\Windows\System32\1031\vsjitdebuggerui.dll C:\Windows\System32\1033\VsGraphicsResources.dll C:\Windows\System32\1033\vsjitdebuggerui.dll ... ``` ### Expected behavior Output should look like ``` System32/1028/VsGraphicsResources.dll => System32/1028/VsGraphicsResources.dll System32/1028/vsjitdebuggerui.dll => System32/1028/vsjitdebuggerui.dll System32/1029/VsGraphicsResources.dll => System32/1029/VsGraphicsResources.dll System32/1029/vsjitdebuggerui.dll => System32/1029/vsjitdebuggerui.dll System32/1031/VsGraphicsResources.dll => System32/1031/VsGraphicsResources.dll System32/1031/vsjitdebuggerui.dll => System32/1031/vsjitdebuggerui.dll System32/1033/VsGraphicsResources.dll => System32/1033/VsGraphicsResources.dll ``` ### Actual behavior Output looks like ``` System32/1028/VsGraphicsResources.dll => System32/1028/VsGraphicsResources.dll System32/1028/vsjitdebuggerui.dll => System32/1028/vsjitdebuggerui.dll System32/1028/1029/VsGraphicsResources.dll => System32/1029/VsGraphicsResources.dll System32/1028/1029/vsjitdebuggerui.dll => System32/1029/vsjitdebuggerui.dll System32/1028/1029/1031/VsGraphicsResources.dll => System32/1031/VsGraphicsResources.dll System32/1028/1029/1031/vsjitdebuggerui.dll => System32/1031/vsjitdebuggerui.dll System32/1028/1029/1031/1033/VsGraphicsResources.dll => System32/1033/VsGraphicsResources.dll ``` ### Regression? _No response_ ### Known Workarounds _No response_ ### Configuration .NET 8.0.101 Win 10 22H2 (OS Build 19045.3930) x64 FilesystemGlobbing v8.0.0 ### Other information _No response_
Author: StefanBertels
Assignees: -
Labels: `untriaged`, `area-Extensions-FileSystem`
Milestone: -