Skip to content

Commit

Permalink
Disable Net5CompatFileStream by default (#50166)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamsitnik authored Apr 8, 2021
1 parent f22214b commit 8b2ad5b
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static void LegacySwitchIsHonored()
.GetField("_strategy", BindingFlags.NonPublic | BindingFlags.Instance)
.GetValue(fileStream);

Assert.DoesNotContain("Net5Compat", strategy.GetType().FullName);
Assert.Contains("Net5Compat", strategy.GetType().FullName);
}

File.Delete(filePath);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"configProperties": {
"System.IO.UseNet5CompatFileStream": false
"System.IO.UseNet5CompatFileStream": true
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"configProperties": {
"System.IO.UseNet5CompatFileStream": false
"System.IO.UseNet5CompatFileStream": true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,7 @@ namespace System.IO.Strategies
{
internal static partial class FileStreamHelpers
{
// It's enabled by default. We are going to change that once we fix #16354, #25905 and #24847.
internal static bool UseNet5CompatStrategy { get; } = GetNet5CompatFileStreamSetting();

private static bool GetNet5CompatFileStreamSetting()
{
if (AppContext.TryGetSwitch("System.IO.UseNet5CompatFileStream", out bool fileConfig))
{
return fileConfig;
}

string? envVar = Environment.GetEnvironmentVariable("DOTNET_SYSTEM_IO_USENET5COMPATFILESTREAM");
return envVar is null
? true // Net5Compat is currently enabled by default;
: bool.IsTrueStringIgnoreCase(envVar) || envVar.Equals("1");
}
internal static bool UseNet5CompatStrategy { get; } = AppContextConfigHelper.GetBooleanConfig("System.IO.UseNet5CompatFileStream", "DOTNET_SYSTEM_IO_USENET5COMPATFILESTREAM");

internal static FileStreamStrategy ChooseStrategy(FileStream fileStream, SafeFileHandle handle, FileAccess access, FileShare share, int bufferSize, bool isAsync)
=> WrapIfDerivedType(fileStream, ChooseStrategyCore(handle, access, share, bufferSize, isAsync));
Expand Down

0 comments on commit 8b2ad5b

Please sign in to comment.