Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Breaking change]: InMemoryDirectoryInfo now prepends rootDir to the files instead of CWD #39189

Closed
1 of 3 tasks
jozkee opened this issue Jan 18, 2024 · 0 comments · Fixed by #39488
Closed
1 of 3 tasks
Assignees
Labels
breaking-change Indicates a .NET Core breaking change 🏁 Release: .NET 9 Work items for the .NET 9 release doc-idea Indicates issues that are suggestions for new topics [org][type][category] in-pr This issue will be closed (fixed) by an active pull request. Pri1 High priority, do before Pri2 and Pri3 📌 seQUESTered Identifies that an issue has been imported into Quest.

Comments

@jozkee
Copy link
Member

jozkee commented Jan 18, 2024

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);

Associated WorkItem - 206387

@jozkee jozkee added doc-idea Indicates issues that are suggestions for new topics [org][type][category] breaking-change Indicates a .NET Core breaking change Pri1 High priority, do before Pri2 and Pri3 labels Jan 18, 2024
@dotnet-bot dotnet-bot added the ⌚ Not Triaged Not triaged label Jan 18, 2024
@gewarren gewarren added the 🗺️ reQUEST Triggers an issue to be imported into Quest. label Feb 2, 2024
@github-actions github-actions bot added 📌 seQUESTered Identifies that an issue has been imported into Quest. and removed 🗺️ reQUEST Triggers an issue to be imported into Quest. labels Feb 2, 2024
@gewarren gewarren added 🏁 Release: .NET 8 Work items for the .NET 8 release 🏁 Release: .NET 9 Work items for the .NET 9 release and removed ⌚ Not Triaged Not triaged 🏁 Release: .NET 8 Work items for the .NET 8 release labels Feb 9, 2024
@dotnet-policy-service dotnet-policy-service bot added the in-pr This issue will be closed (fixed) by an active pull request. label Feb 13, 2024
@gewarren gewarren moved this from 🔖 Ready to 👀 In review in dotnet/docs February 2024 sprint Feb 13, 2024
@github-project-automation github-project-automation bot moved this from 👀 In review to ✅ Done in dotnet/docs February 2024 sprint Feb 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change Indicates a .NET Core breaking change 🏁 Release: .NET 9 Work items for the .NET 9 release doc-idea Indicates issues that are suggestions for new topics [org][type][category] in-pr This issue will be closed (fixed) by an active pull request. Pri1 High priority, do before Pri2 and Pri3 📌 seQUESTered Identifies that an issue has been imported into Quest.
Projects
Status: ✅ Done
Development

Successfully merging a pull request may close this issue.

3 participants