Description
Description
InMemoryDirectoryInfo
now prepends rootDir
to the files
.
InMemoryDirectoryInfo
is used by MatcherExtensions.Match
which enables the Matcher
to execute glob matching patterns without hitting disk.
This new behavior was already stated in the documentation, but it was not happening in practice.
Version
.NET 8 GA
Previous behavior
Before .NET 9, relative paths in files
were prepending the CWD, this caused an unnecessary dependency on the CWD for a type that is supposed to work in-memory.
New behavior
Now, relative paths in files
will be prepended with rootDir
as described in the documentation.
Type of breaking change
- Binary incompatible: Existing binaries may encounter a breaking change in behavior, such as failure to load or execute, and if so, require recompilation.
- Source incompatible: When recompiled using the new SDK or component or to target the new runtime, existing source code may require source changes to compile successfully.
- Behavioral change: Existing binaries may behave differently at run time.
Reason for change
There were blocked scenarios with in-memory paths using a drive letter other than the one used by the CWD, see dotnet/runtime#93107 for an example.
Recommended action
Users depending on the previous behavior must adjust their code to account for the files now being prepended with rootDir
in a similar way to the following:
-string rootDir = "dir1"; // Since rootDir is also relative, it could've been used to filter the matching scope of `files`.
+string rootDir = "root"; // Now that is not possible, everything in `files` will be under `root`.
string[] files = ["dir1/test.0", "dir1/subdir/test.1", "dir2/test.2"];
-PatternMatchingResult result = new Matcher().AddInclude("**/*").Match(rootDir, files);
+PatternMatchingResult result = new Matcher().AddInclude("dir1/**/*").Match(rootDir, files); // Now you need to adjust the pattern if you want to scope down to dir1.
Console.WriteLine(string.Join(", ", result.Files.Select(x => x.Path)));
// prints
// dir1/test.0
// dir1/subdir/test.1
Feature area
Core .NET libraries
Affected APIs
public InMemoryDirectoryInfo (string rootDir, System.Collections.Generic.IEnumerable<string>? files);
public static Microsoft.Extensions.FileSystemGlobbing.PatternMatchingResult Match (this Microsoft.Extensions.FileSystemGlobbing.Matcher matcher, string rootDir, System.Collections.Generic.IEnumerable<string>? files);
public static Microsoft.Extensions.FileSystemGlobbing.PatternMatchingResult Match (this Microsoft.Extensions.FileSystemGlobbing.Matcher matcher, string rootDir, string file);