-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Fix File.Exists for pipe paths on Windows
#117333
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
base: main
Are you sure you want to change the base?
Conversation
|
@dotnet/area-system-io Can someone look at the PR? |
|
I was full of expectations, but I had been waiting for a long time. LoL |
|
@lindexi Yeah, same for me. It seems that |
|
@jozkee PTAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies for the delay.
| /// </item> | ||
| /// </list> | ||
| /// </summary> | ||
| private static bool IsPipePath([NotNullWhen(true)] string? path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider moving this method to PathInternal.Windows.cs
| } | ||
|
|
||
| [Fact] | ||
| [PlatformSpecific(TestPlatforms.Windows)] // Windows-specific pipes behavior |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| [PlatformSpecific(TestPlatforms.Windows)] // Windows-specific pipes behavior | |
| [PlatformSpecific(TestPlatforms.Windows)] |
I think the test name + this attribute is self-explanatory, consider removing these comments.
| [PlatformSpecific(TestPlatforms.Windows)] // Windows-specific pipes behavior | ||
| public void CheckPipeExistsViaFileApi() | ||
| { | ||
| var pipeName = GetNamedPipeServerStreamName(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just by looking at GetNamedPipeServerStreamName
runtime/src/libraries/Common/tests/TestUtilities/System/IO/FileCleanupTestBase.cs
Line 154 in b876d3d
| return @"LOCAL\" + Guid.NewGuid().ToString("N"); |
The IsInAppContainer scenarios will be adding another segment to pipe names meaning IsPipePath as is won't work. It may be tricky to figure out how to test that one.
I suspect is related to UWP cc @adamsitnik @danmoseley.
| var pipeName = GetNamedPipeServerStreamName(); | ||
| new NamedPipeServerStream(pipeName).Dispose(); | ||
| Assert.False(Exists(@$"\\.\pipe\{pipeName}")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| var pipeName = GetNamedPipeServerStreamName(); | |
| new NamedPipeServerStream(pipeName).Dispose(); | |
| Assert.False(Exists(@$"\\.\pipe\{pipeName}")); | |
| Assert.False(Exists(@$"\\.\pipe\{pipeName}")); |
No need to create/delete the pipe?
| } | ||
|
|
||
| ReadOnlySpan<char> pathSpan = path.AsSpan(); | ||
| if (!pathSpan.StartsWith(@"\\")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the method should also handle forward slashes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FillAttributeInfo also impacts FIle.GetAttributes, can you please add tests for that?
| // 1) '.' or 'serverName' | ||
| // 2) Constant 'pipe' segment | ||
| // 3) Pipe name | ||
| return written == 3 && pathSpan[segments[1]].SequenceEqual("pipe"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be a case insensitive comparison.

Fixes: #69604
Also while working on a core fix (commit 1) I noticed that
dwFileAttributesis often compared to-1. Windows documentation reffers to it asINVALID_FILE_ATTRIBUTES, so I decided to name this constant for clarity