Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 5.6k
Remove isAsync flag validation from FileStream constructors#123761
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
Merged
+27
−44
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b669408
Initial plan
Copilot 4b253cc
Remove isAsync flag validation from FileStream constructors
Copilot 0d106df
Fix unused parameter issue in ValidateHandle
Copilot 9e8d786
Add assertions to verify FileStream uses handle's IsAsync value
Copilot 7fb921f
Address review feedback: convert test to theory and add async I/O ver…
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
6 changes: 0 additions & 6 deletions
6 src/libraries/System.Private.CoreLib/src/Resources/Strings.resx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 4 additions & 18 deletions
22 src/libraries/System.Private.CoreLib/src/System/IO/FileStream.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 0 additions & 12 deletions
12 src/libraries/System.Private.CoreLib/src/System/ThrowHelper.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 23 additions & 8 deletions
31 ...es/System.Runtime/tests/System.IO.FileSystem.Tests/FileStream/ctor_sfh_fa_buffer_async.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| using System.Threading.Tasks; | ||
| using Microsoft.Win32.SafeHandles; | ||
| using Xunit; | ||
| @@ -28,17 +29,31 @@ public void MatchedAsync() | ||
| } | ||
| } | ||
| [Fact] | ||
| public void UnmatchedAsyncThrows() | ||
| [Theory] | ||
| [InlineData(true)] | ||
| [InlineData(false)] | ||
| public async Task UnmatchedAsyncIsAllowed(bool isAsync) | ||
| { | ||
| using (FileStream fs = new FileStream(GetTestFilePath(), FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite | FileShare.Delete, 4096, true)) | ||
| using (FileStream fs = new FileStream(GetTestFilePath(), FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite | FileShare.Delete, 4096, isAsync)) | ||
| { | ||
| Assert.Throws<ArgumentException>(() => CreateFileStream(fs.SafeFileHandle, FileAccess.ReadWrite, 4096, false)); | ||
| } | ||
| // isAsync parameter is now ignored, handle.IsAsync is used instead | ||
| using (FileStream newFs = CreateFileStream(fs.SafeFileHandle, FileAccess.ReadWrite, 4096, !isAsync)) | ||
| { | ||
| // Verify that the new FileStream uses handle's IsAsync, not the parameter | ||
| Assert.Equal(isAsync, newFs.IsAsync); | ||
| using (FileStream fs = new FileStream(GetTestFilePath(), FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite | FileShare.Delete, 4096, false)) | ||
| { | ||
| Assert.Throws<ArgumentException>(() => CreateFileStream(fs.SafeFileHandle, FileAccess.ReadWrite, 4096, true)); | ||
| // Perform async write, seek to beginning, and async read to verify functionality | ||
| byte[] writeBuffer = new byte[] { 1, 2, 3, 4, 5 }; | ||
| await newFs.WriteAsync(writeBuffer, 0, writeBuffer.Length); | ||
| newFs.Seek(0, SeekOrigin.Begin); | ||
| byte[] readBuffer = new byte[writeBuffer.Length]; | ||
| int bytesRead = await newFs.ReadAsync(readBuffer, 0, readBuffer.Length); | ||
stephentoub marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. stephentoub marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. stephentoub marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| Assert.Equal(writeBuffer.Length, bytesRead); | ||
| Assert.Equal(writeBuffer, readBuffer); | ||
| } | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.