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

InMemoryDirectoryInfo does not work with absolute paths on Windows #88596

Open
keyboardDrummer opened this issue Jul 10, 2023 · 4 comments
Open

Comments

@keyboardDrummer
Copy link

keyboardDrummer commented Jul 10, 2023

Description

var attempt1 = new InMemoryDirectoryInfo(@"", new[] { @"C:\my\happy\path" }); // crashes because the root is empty
var attempt2 = new InMemoryDirectoryInfo(@"C:\", new[] { @"C:\my\happy\path" });
var l = attempt2.EnumerateFileSystemInfos().ToList(); // returns "my\" instead of "C:\", so any matcher that starts with C:\ cannot be used with this
var matcher = new Matcher();
matcher.AddInclude(@"C:\my\happy\path");
Debug.Assert(matcher.Execute(attempt2).HasMatches) // fails

Reproduction Steps

See description

Expected behavior

I expect there to be a way to use absolute paths on Windows in combination with Matcher and InMemoryDirectoryInfo

Actual behavior

See description

Regression?

No response

Known Workarounds

I have to use paths relative to the root of the filesystem

var attempt3 = new InMemoryDirectoryInfo(@"C:\", new[] { @"my\happy\path" });
var matcher = new Matcher();
matcher.AddInclude(@"my\happy\path");
Debug.Assert(matcher.Execute(attempt3).HasMatches) // passes

Configuration

No response

Other information

I expect that allowing InMemoryDirectoryInfo to take an empty root is required to resolve this issue.

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Jul 10, 2023
@ghost
Copy link

ghost commented Jul 10, 2023

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

Issue Details

Description

var attempt1 = new InMemoryDirectoryInfo(@"", new[] { @"C:\my\happy\path" }); // crashes because the root is empty
var attempt2 = new InMemoryDirectoryInfo(@"C:\", new[] { @"C:\my\happy\path" });
var l = attempt2.EnumerateFileSystemInfos().ToList(); // returns "my\" instead of "C:\", so any matcher that starts with C:\ cannot be used with this
var matcher = new Matcher();
matcher.AddInclude(@"C:\my\happy\path");
Debug.Assert(matcher.Execute(attempt2).HasMatches) // fails

Reproduction Steps

See description

Expected behavior

I expect there to be a way to use absolute paths on Windows in combination with Matcher and InMemoryDirectoryInfo

Actual behavior

See description

Regression?

No response

Known Workarounds

I have to use paths relative to the root of the filesystem

var attempt2 = new InMemoryDirectoryInfo(@"C:\", new[] { @"my\happy\path" });
var matcher = new Matcher();
matcher.AddInclude(@"my\happy\path");
Debug.Assert(matcher.Execute(attempt2).HasMatches) // passes

Configuration

No response

Other information

No response

Author: keyboardDrummer
Assignees: -
Labels:

area-System.IO

Milestone: -

@keyboardDrummer keyboardDrummer changed the title InMemoryDirectoryInfo.EnumerateFileSystemInfos() never returns the root of a path, which is problematic when matching on Windows InMemoryDirectoryInfo does not work with absolute paths on Windows Jul 10, 2023
@ghost
Copy link

ghost commented Jul 10, 2023

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

Issue Details

Description

var attempt1 = new InMemoryDirectoryInfo(@"", new[] { @"C:\my\happy\path" }); // crashes because the root is empty
var attempt2 = new InMemoryDirectoryInfo(@"C:\", new[] { @"C:\my\happy\path" });
var l = attempt2.EnumerateFileSystemInfos().ToList(); // returns "my\" instead of "C:\", so any matcher that starts with C:\ cannot be used with this
var matcher = new Matcher();
matcher.AddInclude(@"C:\my\happy\path");
Debug.Assert(matcher.Execute(attempt2).HasMatches) // fails

Reproduction Steps

See description

Expected behavior

I expect there to be a way to use absolute paths on Windows in combination with Matcher and InMemoryDirectoryInfo

Actual behavior

See description

Regression?

No response

Known Workarounds

I have to use paths relative to the root of the filesystem

var attempt3 = new InMemoryDirectoryInfo(@"C:\", new[] { @"my\happy\path" });
var matcher = new Matcher();
matcher.AddInclude(@"my\happy\path");
Debug.Assert(matcher.Execute(attempt3).HasMatches) // passes

Configuration

No response

Other information

I expect that allowing InMemoryDirectoryInfo to take an empty root is required to resolve this issue.

Author: keyboardDrummer
Assignees: -
Labels:

untriaged, area-Extensions-FileSystem

Milestone: -

@jozkee
Copy link
Member

jozkee commented Jul 24, 2023

This looks like a duplicate of #50648.

@jozkee jozkee added this to the Future milestone Jul 24, 2023
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Jul 24, 2023
@keyboardDrummer
Copy link
Author

This looks like a duplicate of #50648.

I don't think it is. Another way to phrase this issue is that InMemoryDirectoryInfo does not support having multiple drives in it. My problem isn't that, but that it is unable to include the drive letter in the paths it returns, and my matchers do include the drive letter.

My perspective is that it would be simplest to consider the drive letter part of a Windows path as another directory, but InMemoryDirectoryInfo doesn't allow that.

@jozkee jozkee modified the milestones: Future, 9.0.0 Nov 22, 2023
@adamsitnik adamsitnik modified the milestones: 9.0.0, Future Jul 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants