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 constructor not recognizing root #93107

Closed
AnakinRaW opened this issue Oct 6, 2023 · 4 comments
Closed

InMemoryDirectoryInfo constructor not recognizing root #93107

AnakinRaW opened this issue Oct 6, 2023 · 4 comments

Comments

@AnakinRaW
Copy link
Contributor

Description

Hi,

so unless i'm totally overseeing something here, the behavior of the InMemoryDirectoryInfo constructor irritates me a lot.
It seems that the parameter rootDir is not acutally used to resolve relative path.

The documentation however states this:

param files: Collection of file names. If relative paths rootDir will be prepended to the paths.

Reproduction Steps

See the following code:

var files = new List<string>{"Test.txt", "New/../Test.txt", "new/test.txt"};
var fs = new InMemoryDirectoryInfo("x:/", files);
var i = fs.EnumerateFileSystemInfos().ToList();

Expected behavior

expected result of i is a list containing 3 items of the following file names:

{"x:/test.txt", "x:/test.txt", "x:/new/test.txt"}

Actual behavior

The actual result is empty.
In the debugger you can also see that the relative paths have been resolved to the applications current directory (so something like c:/dev/app/bin/debug/test.txt)

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

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

ghost commented Oct 6, 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

Hi,

so unless i'm totally overseeing something here, the behavior of the InMemoryDirectoryInfo constructor irritates me a lot.
It seems that the parameter rootDir is not acutally used to resolve relative path.

The documentation however states this:

param files: Collection of file names. If relative paths rootDir will be prepended to the paths.

Reproduction Steps

See the following code:

var files = new List<string>{"Test.txt", "New/../Test.txt", "new/test.txt"};
var fs = new InMemoryDirectoryInfo("x:/", files);
var i = fs.EnumerateFileSystemInfos().ToList();

Expected behavior

expected result of i is a list containing 3 items of the following file names:

{"x:/test.txt", "x:/test.txt", "x:/new/test.txt"}

Actual behavior

The actual result is empty.
In the debugger you can also see that the relative paths have been resolved to the applications current directory (so something like c:/dev/app/bin/debug/test.txt)

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Author: AnakinRaW
Assignees: -
Labels:

area-System.IO

Milestone: -

@ghost
Copy link

ghost commented Oct 6, 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

Hi,

so unless i'm totally overseeing something here, the behavior of the InMemoryDirectoryInfo constructor irritates me a lot.
It seems that the parameter rootDir is not acutally used to resolve relative path.

The documentation however states this:

param files: Collection of file names. If relative paths rootDir will be prepended to the paths.

Reproduction Steps

See the following code:

var files = new List<string>{"Test.txt", "New/../Test.txt", "new/test.txt"};
var fs = new InMemoryDirectoryInfo("x:/", files);
var i = fs.EnumerateFileSystemInfos().ToList();

Expected behavior

expected result of i is a list containing 3 items of the following file names:

{"x:/test.txt", "x:/test.txt", "x:/new/test.txt"}

Actual behavior

The actual result is empty.
In the debugger you can also see that the relative paths have been resolved to the applications current directory (so something like c:/dev/app/bin/debug/test.txt)

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Author: AnakinRaW
Assignees: -
Labels:

area-System.IO, untriaged, area-Extensions-FileSystem

Milestone: -

@krwq
Copy link
Member

krwq commented Oct 6, 2023

I think the problem is that we use GetFullPath here:
https://github.com/dotnet/runtime/blob/main/src/libraries/Microsoft.Extensions.FileSystemGlobbing/src/InMemoryDirectoryInfo.cs#L53

I think this also looks like a duplicate of #50648

Looking at the tests, this somewhat looks like scenario similar to yours:

public void VerifyInMemoryDirectoryInfo_IsNotEmpty()

Would you be interested in creating a PR with couple of tests with a fix?

@krwq
Copy link
Member

krwq commented Oct 6, 2023

I'm closing this as dup of #50648

@krwq krwq closed this as completed Oct 6, 2023
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Oct 6, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Nov 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants