-
Notifications
You must be signed in to change notification settings - Fork 5.2k
FileStream rewrite part II #48813
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
adamsitnik
merged 31 commits into
dotnet:main
from
adamsitnik:newWindowsFileStreamStrategy
Mar 17, 2021
Merged
FileStream rewrite part II #48813
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
cd1698d
introduce WindowsFileStreamStrategy
adamsitnik ad5b455
introduce SyncWindowsFileStreamStrategy
adamsitnik a5ff09c
introduce AsyncWindowsFileStreamStrategy
adamsitnik 5a64215
some minor improvements after reading the code again
adamsitnik e27ce6c
only DerivedFileStreamStrategy needs to have a reference to FileStream
adamsitnik 3f84bd5
implement ReadByte and WriteByte to make new windows strategies fully…
adamsitnik 402cf65
implement FlushAsync for no buffering strategies as nop to get Flush_…
adamsitnik 9a30387
use the new strategies when buffering is not enabled
adamsitnik f34cb02
introduce BufferedFileStreamStrategy
adamsitnik fb5b611
fix the Mono build
adamsitnik b1decbf
use the Legacy strategy by default for now, add tests for the other i…
adamsitnik 8d58437
restore old file name to make it easier to review the code (as diff w…
adamsitnik 33e6b8e
Don't set the buffer to null, to avoid a NullReferenceException
adamsitnik 77b6d97
fix the browser build?
adamsitnik 33c7c83
reverting the flushing changes as it looks that they have introduced …
adamsitnik 60cd6e7
0 bytes reads are OK only for FileStream when the read buffer is empty
adamsitnik e8d6f77
simplify the source code by removing some of the optimizations that a…
adamsitnik 7913ebf
Apply suggestions from code review
adamsitnik 3f6b541
address code review feedback
adamsitnik 75569e3
use ThrowHelper in other places in System.IO
adamsitnik 9a4c15a
Merge remote-tracking branch 'upstream/main' into newWindowsFileStrea…
adamsitnik 19bb524
update test projects based on most recent changes in main branch
adamsitnik dd8c4b9
fix a path that I've broken in previous commit
adamsitnik 737c73c
revert the ResourceReader change that broke Mono build
adamsitnik 4a5497a
restore old test behavior, but keep it only for Legacy FileStream
adamsitnik f01948d
move buffering logic to BufferedFileStreamStrategy
adamsitnik 3c152b7
use buffering code from LegacyFileStream
adamsitnik d52293b
Merge remote-tracking branch 'upstream/main' into newWindowsFileStrea…
adamsitnik e54edc5
set `_writePos = 0` in explicit way in Dispose so WriteByte hot path …
adamsitnik 0294191
fix ReadAsync and WriteAsync bugs that were discovered by the checked…
adamsitnik c73558a
move the finalization logic to the finalizer
adamsitnik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
29 changes: 29 additions & 0 deletions
29
src/libraries/System.IO.FileSystem/tests/LegacyTests/LegacySwitchTests.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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Reflection; | ||
using Xunit; | ||
|
||
namespace System.IO.Tests | ||
{ | ||
public class LegacySwitchTests | ||
{ | ||
[Fact] | ||
public static void LegacySwitchIsHonored() | ||
{ | ||
string filePath = Path.Combine(Path.GetTempPath(), Path.GetTempFileName()); | ||
|
||
using (FileStream fileStream = File.Create(filePath)) | ||
{ | ||
object strategy = fileStream | ||
.GetType() | ||
.GetField("_strategy", BindingFlags.NonPublic | BindingFlags.Instance) | ||
.GetValue(fileStream); | ||
|
||
Assert.DoesNotContain(strategy.GetType().FullName, "Legacy"); | ||
} | ||
|
||
File.Delete(filePath); | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...libraries/System.IO.FileSystem/tests/LegacyTests/System.IO.FileSystem.Legacy.Tests.csproj
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
<IncludeRemoteExecutor>true</IncludeRemoteExecutor> | ||
<!-- currently we have non Legacy strategy only for Windows, so we run the tests only on Windows --> | ||
<TargetFrameworks>$(NetCoreAppCurrent)-windows</TargetFrameworks> | ||
|
||
<RunTestsJSArguments>--working-dir=/test-dir</RunTestsJSArguments> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="..\**\*.cs" /> | ||
</ItemGroup> | ||
<ItemGroup Condition="'$(TargetsUnix)' == 'true'"> | ||
<Compile Remove="..\**\*.Windows.cs" /> | ||
<Compile Remove="..\**\*.Browser.cs" /> | ||
</ItemGroup> | ||
<ItemGroup Condition="'$(TargetsWindows)' == 'true'"> | ||
<Compile Remove="..\**\*.Unix.cs" /> | ||
<Compile Remove="..\**\*.Browser.cs" /> | ||
</ItemGroup> | ||
<ItemGroup Condition="'$(TargetsBrowser)' == 'true'"> | ||
<Compile Remove="..\**\*.Unix.cs" /> | ||
<Compile Remove="..\**\*.Windows.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<!-- Helpers --> | ||
<Compile Include="$(CommonPath)Interop\Windows\Kernel32\Interop.GenericOperations.cs" Link="Interop\Windows\Interop.GenericOperations.cs" /> | ||
<Compile Include="$(CommonTestPath)System\Buffers\NativeMemoryManager.cs" Link="Common\System\Buffers\NativeMemoryManager.cs" /> | ||
<Compile Include="$(CommonTestPath)System\IO\TempFile.cs" Link="Common\System\IO\TempFile.cs" /> | ||
<Compile Include="$(CommonTestPath)System\IO\PathFeatures.cs" Link="Common\System\IO\PathFeatures.cs" /> | ||
<Content Include="..\DirectoryInfo\test-dir\dummy.txt" Link="test-dir\dummy.txt" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="$(CommonTestPath)StreamConformanceTests\StreamConformanceTests.csproj" /> | ||
</ItemGroup> | ||
</Project> |
5 changes: 5 additions & 0 deletions
5
src/libraries/System.IO.FileSystem/tests/LegacyTests/runtimeconfig.template.json
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"configProperties": { | ||
"System.IO.UseLegacyFileStream": true | ||
adamsitnik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
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
25 changes: 25 additions & 0 deletions
25
src/libraries/System.IO/tests/LegacyTests/System.IO.Legacy.Tests.csproj
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<RootNamespace>System.IO</RootNamespace> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
<TestRuntime>true</TestRuntime> | ||
<IncludeRemoteExecutor>true</IncludeRemoteExecutor> | ||
<!-- currently we have non Legacy strategy only for Windows, so we run the tests only on Windows --> | ||
adamsitnik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<TargetFrameworks>$(NetCoreAppCurrent)-windows</TargetFrameworks> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="..\**\*.cs" /> | ||
<!-- Helpers --> | ||
<Compile Include="$(CommonTestPath)System\Buffers\NativeMemoryManager.cs" Link="Common\System\Buffers\NativeMemoryManager.cs" /> | ||
<Compile Include="$(CommonTestPath)System\IO\CallTrackingStream.cs" Link="Common\System\IO\CallTrackingStream.cs" /> | ||
<Compile Include="$(CommonTestPath)System\IO\DelegateStream.cs" Link="Common\System\IO\DelegateStream.cs" /> | ||
<Compile Include="$(CommonTestPath)System\IO\WrappedMemoryStream.cs" Link="Common\System\IO\WrappedMemoryStream.cs" /> | ||
<Compile Include="$(CommonTestPath)System\IO\ConnectedStreams.cs" Link="Common\System\IO\ConnectedStreams.cs" /> | ||
<Compile Include="$(CommonPath)System\Net\MultiArrayBuffer.cs" Link="ProductionCode\Common\System\Net\MultiArrayBuffer.cs" /> | ||
<Compile Include="$(CommonPath)System\Net\StreamBuffer.cs" Link="ProductionCode\Common\System\Net\StreamBuffer.cs" /> | ||
<Compile Include="$(CommonPath)System\Threading\Tasks\TaskToApm.cs" Link="Common\System\Threading\Tasks\TaskToApm.cs" /> | ||
adamsitnik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="$(CommonTestPath)StreamConformanceTests\StreamConformanceTests.csproj" /> | ||
</ItemGroup> | ||
</Project> |
5 changes: 5 additions & 0 deletions
5
src/libraries/System.IO/tests/LegacyTests/runtimeconfig.template.json
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"configProperties": { | ||
"System.IO.UseLegacyFileStream": true | ||
} | ||
} |
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
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
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
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
Oops, something went wrong.
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.