From d3fbf4a1d3ad98a73d57726bbb7be5a1d61abfff Mon Sep 17 00:00:00 2001 From: Carlos Sanchez Lopez <1175054+carlossanlop@users.noreply.github.com> Date: Wed, 13 Nov 2019 12:26:12 -0800 Subject: [PATCH] Fix NetStandard issue in System.IO.FileSystem.AccessControl in 5.0 (#42546) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Fix NetStandard issue in System.IO.FileSystem.AccessControl We built the fix incorrectly so that it would only apply for netcoreapp3.0 but customer needs it on netstandard2.0 (desktop + core). Customer impact is that they’ll see a PlatformNotSupported exception rather than the new API. Signed-off-by: dotnet-bot --- .../shared/System/IO/Path.cs | 16 +++-------- .../shared/System/IO/PathInternal.cs | 33 +++++++++++++++++++--- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/netcore/System.Private.CoreLib/shared/System/IO/Path.cs b/netcore/System.Private.CoreLib/shared/System/IO/Path.cs index 500e98f0732..b0cdad93bc7 100644 --- a/netcore/System.Private.CoreLib/shared/System/IO/Path.cs +++ b/netcore/System.Private.CoreLib/shared/System/IO/Path.cs @@ -910,29 +910,21 @@ namespace System.IO /// /// Trims one trailing directory separator beyond the root of the path. /// - public static string TrimEndingDirectorySeparator(string path) => - EndsInDirectorySeparator(path) && !PathInternal.IsRoot(path.AsSpan()) ? - path.Substring(0, path.Length - 1) : - path; + public static string TrimEndingDirectorySeparator(string path) => PathInternal.TrimEndingDirectorySeparator(path); /// /// Trims one trailing directory separator beyond the root of the path. /// - public static ReadOnlySpan TrimEndingDirectorySeparator(ReadOnlySpan path) => - EndsInDirectorySeparator(path) && !PathInternal.IsRoot(path) ? - path.Slice(0, path.Length - 1) : - path; + public static ReadOnlySpan TrimEndingDirectorySeparator(ReadOnlySpan path) => PathInternal.TrimEndingDirectorySeparator(path); /// /// Returns true if the path ends in a directory separator. /// - public static bool EndsInDirectorySeparator(ReadOnlySpan path) - => path.Length > 0 && PathInternal.IsDirectorySeparator(path[path.Length - 1]); + public static bool EndsInDirectorySeparator(ReadOnlySpan path) => PathInternal.EndsInDirectorySeparator(path); /// /// Returns true if the path ends in a directory separator. /// - public static bool EndsInDirectorySeparator(string path) - => !string.IsNullOrEmpty(path) && PathInternal.IsDirectorySeparator(path[path.Length - 1]); + public static bool EndsInDirectorySeparator(string path) => PathInternal.EndsInDirectorySeparator(path); } } diff --git a/netcore/System.Private.CoreLib/shared/System/IO/PathInternal.cs b/netcore/System.Private.CoreLib/shared/System/IO/PathInternal.cs index 11118d43da2..47839718227 100644 --- a/netcore/System.Private.CoreLib/shared/System/IO/PathInternal.cs +++ b/netcore/System.Private.CoreLib/shared/System/IO/PathInternal.cs @@ -18,12 +18,9 @@ namespace System.IO #if MS_IO_REDIST internal static string EnsureTrailingSeparator(string path) => EndsInDirectorySeparator(path) ? path : path + DirectorySeparatorCharAsString; - - internal static bool EndsInDirectorySeparator(string path) - => !string.IsNullOrEmpty(path) && IsDirectorySeparator(path[path.Length - 1]); #else internal static string EnsureTrailingSeparator(string path) - => Path.EndsInDirectorySeparator(path.AsSpan()) ? path : path + DirectorySeparatorCharAsString; + => EndsInDirectorySeparator(path.AsSpan()) ? path : path + DirectorySeparatorCharAsString; #endif internal static bool IsRoot(ReadOnlySpan path) @@ -219,5 +216,33 @@ namespace System.IO return true; } + + /// + /// Trims one trailing directory separator beyond the root of the path. + /// + internal static string TrimEndingDirectorySeparator(string path) => + EndsInDirectorySeparator(path) && !IsRoot(path.AsSpan()) ? + path.Substring(0, path.Length - 1) : + path; + + /// + /// Returns true if the path ends in a directory separator. + /// + internal static bool EndsInDirectorySeparator(string path) + => !string.IsNullOrEmpty(path) && IsDirectorySeparator(path[path.Length - 1]); + + /// + /// Trims one trailing directory separator beyond the root of the path. + /// + internal static ReadOnlySpan TrimEndingDirectorySeparator(ReadOnlySpan path) => + EndsInDirectorySeparator(path) && !IsRoot(path) ? + path.Slice(0, path.Length - 1) : + path; + + /// + /// Returns true if the path ends in a directory separator. + /// + internal static bool EndsInDirectorySeparator(ReadOnlySpan path) + => path.Length > 0 && IsDirectorySeparator(path[path.Length - 1]); } } -- 2.11.4.GIT