Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/corefx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSantiago Fernandez Madero <safern@microsoft.com>2017-04-28 02:17:34 +0300
committerGitHub <noreply@github.com>2017-04-28 02:17:34 +0300
commit134cc0df801938a4ba3e58f902a58cec09b744ef (patch)
tree5ad23fb80a117f9635d8ce37ad269e347418afb4 /src/System.IO.FileSystem
parentc8413f506307108a4688486525b1f927d76cc9cb (diff)
Fix some System.IO.PathTests on Desktop to support legacy path behavior (#19012)
* Fix System.IO.PathTests
Diffstat (limited to 'src/System.IO.FileSystem')
-rw-r--r--src/System.IO.FileSystem/tests/PathFeatures.cs99
-rw-r--r--src/System.IO.FileSystem/tests/Performance/System.IO.FileSystem.Performance.Tests.csproj4
-rw-r--r--src/System.IO.FileSystem/tests/System.IO.FileSystem.Tests.csproj4
3 files changed, 6 insertions, 101 deletions
diff --git a/src/System.IO.FileSystem/tests/PathFeatures.cs b/src/System.IO.FileSystem/tests/PathFeatures.cs
deleted file mode 100644
index 7062d9ee1a..0000000000
--- a/src/System.IO.FileSystem/tests/PathFeatures.cs
+++ /dev/null
@@ -1,99 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System.Reflection;
-using System.Runtime.InteropServices;
-
-namespace System.IO
-{
- public static class PathFeatures
- {
- private enum State
- {
- Uninitialized,
- True,
- False
- }
-
- // Note that this class is using APIs that allow it to run on all platforms (including Core 5.0)
- // That is why we have .GetTypeInfo(), don't use the Registry, etc...
-
- private static State s_osEnabled;
- private static State s_onCore;
-
- /// <summary>
- /// Returns true if you can use long paths, including long DOS style paths (e.g. over 260 without \\?\).
- /// </summary>
- public static bool AreAllLongPathsAvailable()
- {
- // We have support built-in for all platforms in Core
- if (RunningOnCoreLib)
- return true;
-
- // Otherwise we're running on Windows, see if we've got the capability in .NET, and that the feature is enabled in the OS
- return !AreLongPathsBlocked() && AreOsLongPathsEnabled();
- }
-
- public static bool IsUsingLegacyPathNormalization()
- {
- return HasLegacyIoBehavior("UseLegacyPathHandling");
- }
-
- /// <summary>
- /// Returns true if > MAX_PATH (260) character paths are blocked.
- /// Note that this doesn't reflect that you can actually use long paths without device syntax when on Windows.
- /// Use AreAllLongPathsAvailable() to see that you can use long DOS style paths if on Windows.
- /// </summary>
- public static bool AreLongPathsBlocked()
- {
- return HasLegacyIoBehavior("BlockLongPaths");
- }
-
- private static bool HasLegacyIoBehavior(string propertyName)
- {
- // Core doesn't have legacy behaviors
- if (RunningOnCoreLib)
- return false;
-
- Type t = typeof(object).GetTypeInfo().Assembly.GetType("System.AppContextSwitches");
- var p = t.GetProperty(propertyName, BindingFlags.Static | BindingFlags.Public);
-
- // If the switch actually exists use it, otherwise we predate the switch and are effectively on
- return (bool)(p?.GetValue(null) ?? true);
- }
-
- private static bool RunningOnCoreLib
- {
- get
- {
- // Not particularly elegant
- if (s_onCore == State.Uninitialized)
- s_onCore = typeof(object).GetTypeInfo().Assembly.GetName().Name == "System.Private.CoreLib" ? State.True : State.False;
-
- return s_onCore == State.True;
- }
- }
-
- private static bool AreOsLongPathsEnabled()
- {
- if (s_osEnabled == State.Uninitialized)
- {
- // No official way to check yet this is good enough for tests
- try
- {
- s_osEnabled = RtlAreLongPathsEnabled() ? State.True : State.False;
- }
- catch
- {
- s_osEnabled = State.False;
- }
- }
-
- return s_osEnabled == State.True;
- }
-
- [DllImport("ntdll", ExactSpelling = true)]
- private static extern bool RtlAreLongPathsEnabled();
- }
-}
diff --git a/src/System.IO.FileSystem/tests/Performance/System.IO.FileSystem.Performance.Tests.csproj b/src/System.IO.FileSystem/tests/Performance/System.IO.FileSystem.Performance.Tests.csproj
index 7df96f1f2d..2d9fd50a0f 100644
--- a/src/System.IO.FileSystem/tests/Performance/System.IO.FileSystem.Performance.Tests.csproj
+++ b/src/System.IO.FileSystem/tests/Performance/System.IO.FileSystem.Performance.Tests.csproj
@@ -16,7 +16,6 @@
<Compile Include="..\PortedCommon\ReparsePointUtilities.cs" />
<Compile Include="..\TestData.cs" />
<Compile Include="..\FileSystemTest.cs" />
- <Compile Include="..\PathFeatures.cs" />
<Compile Include="Perf.Directory.cs" />
<Compile Include="Perf.File.cs" />
<Compile Include="Perf.FileInfo.cs" />
@@ -27,6 +26,9 @@
<Compile Include="$(CommonTestPath)\System\IO\FileCleanupTestBase.cs">
<Link>Common\System\IO\FileCleanupTestBase.cs</Link>
</Compile>
+ <Compile Include="$(CommonTestPath)\System\IO\PathFeatures.cs">
+ <Link>Common\System\IO\PathFeatures.cs</Link>
+ </Compile>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(CommonPath)\..\perf\PerfRunner\PerfRunner.csproj">
diff --git a/src/System.IO.FileSystem/tests/System.IO.FileSystem.Tests.csproj b/src/System.IO.FileSystem/tests/System.IO.FileSystem.Tests.csproj
index d265aaf3a2..109b8c4975 100644
--- a/src/System.IO.FileSystem/tests/System.IO.FileSystem.Tests.csproj
+++ b/src/System.IO.FileSystem/tests/System.IO.FileSystem.Tests.csproj
@@ -97,7 +97,6 @@
<Compile Include="File\Move.cs" />
<Compile Include="File\ReadWriteAllText.cs" />
<Compile Include="File\ReadWriteAllLines.cs" />
- <Compile Include="PathFeatures.cs" />
<Compile Include="TestData.cs" />
<Compile Include="UnseekableFileStream.cs" />
<Compile Include="FSAssert.cs" />
@@ -160,6 +159,9 @@
<Compile Include="$(CommonTestPath)\System\IO\TempFile.cs">
<Link>Common\System\IO\TempFile.cs</Link>
</Compile>
+ <Compile Include="$(CommonTestPath)\System\IO\PathFeatures.cs">
+ <Link>Common\System\IO\PathFeatures.cs</Link>
+ </Compile>
<Compile Include="$(CommonTestPath)\System\PlatformDetection.cs">
<Link>Common\System\PlatformDetection.cs</Link>
</Compile>