From fa7f618aef3a228fce9b8d69ec7869589e262d3d Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Thu, 14 Nov 2019 12:35:38 -0500 Subject: [PATCH] Port missing Path changes from old shared source mirror (#41) It looks like the mirror didn't fully quiesce prior to snapping coreclr/corefx for the runtime consolidation. As a result the libraries build is breaking. --- .../System.Private.CoreLib/src/System/IO/Path.cs | 16 +++-------- .../src/System/IO/PathInternal.cs | 33 +++++++++++++++++++--- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/Path.cs b/src/libraries/System.Private.CoreLib/src/System/IO/Path.cs index 500e98f..b0cdad9 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IO/Path.cs +++ b/src/libraries/System.Private.CoreLib/src/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/src/libraries/System.Private.CoreLib/src/System/IO/PathInternal.cs b/src/libraries/System.Private.CoreLib/src/System/IO/PathInternal.cs index 11118d4..ba15705 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IO/PathInternal.cs +++ b/src/libraries/System.Private.CoreLib/src/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.7.4