From 8b2ad5bccff29715d924d0c2d191bc978aaaf320 Mon Sep 17 00:00:00 2001 From: Adam Sitnik Date: Thu, 8 Apr 2021 12:40:17 +0200 Subject: [PATCH] Disable Net5CompatFileStream by default (#50166) --- .../Net5CompatTests/Net5CompatSwitchTests.cs | 2 +- .../Net5CompatTests/runtimeconfig.template.json | 2 +- .../Net5CompatTests/runtimeconfig.template.json | 2 +- .../System/IO/Strategies/FileStreamHelpers.cs | 16 +--------------- 4 files changed, 4 insertions(+), 18 deletions(-) diff --git a/src/libraries/System.IO.FileSystem/tests/Net5CompatTests/Net5CompatSwitchTests.cs b/src/libraries/System.IO.FileSystem/tests/Net5CompatTests/Net5CompatSwitchTests.cs index bb2d05086cf0a..24f9026b54dff 100644 --- a/src/libraries/System.IO.FileSystem/tests/Net5CompatTests/Net5CompatSwitchTests.cs +++ b/src/libraries/System.IO.FileSystem/tests/Net5CompatTests/Net5CompatSwitchTests.cs @@ -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); diff --git a/src/libraries/System.IO.FileSystem/tests/Net5CompatTests/runtimeconfig.template.json b/src/libraries/System.IO.FileSystem/tests/Net5CompatTests/runtimeconfig.template.json index 0c1a3482aba4f..6e843517fe47a 100644 --- a/src/libraries/System.IO.FileSystem/tests/Net5CompatTests/runtimeconfig.template.json +++ b/src/libraries/System.IO.FileSystem/tests/Net5CompatTests/runtimeconfig.template.json @@ -1,5 +1,5 @@ { "configProperties": { - "System.IO.UseNet5CompatFileStream": false + "System.IO.UseNet5CompatFileStream": true } } diff --git a/src/libraries/System.IO/tests/Net5CompatTests/runtimeconfig.template.json b/src/libraries/System.IO/tests/Net5CompatTests/runtimeconfig.template.json index 0c1a3482aba4f..6e843517fe47a 100644 --- a/src/libraries/System.IO/tests/Net5CompatTests/runtimeconfig.template.json +++ b/src/libraries/System.IO/tests/Net5CompatTests/runtimeconfig.template.json @@ -1,5 +1,5 @@ { "configProperties": { - "System.IO.UseNet5CompatFileStream": false + "System.IO.UseNet5CompatFileStream": true } } diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/Strategies/FileStreamHelpers.cs b/src/libraries/System.Private.CoreLib/src/System/IO/Strategies/FileStreamHelpers.cs index d64677b48efe8..1ca2e563998ca 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IO/Strategies/FileStreamHelpers.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IO/Strategies/FileStreamHelpers.cs @@ -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));