diff options
author | Jeremy Kuhne <jeremy.kuhne@microsoft.com> | 2018-08-11 03:06:39 +0300 |
---|---|---|
committer | Jan Kotas <jkotas@microsoft.com> | 2018-08-11 04:39:02 +0300 |
commit | 38a69d03d365a8c55984b1243528a07c22d82e14 (patch) | |
tree | 2ef7683bd6041a2ffb00228cb6486038ffd0a19a /src | |
parent | 106c32100761ef21d67b74e59fa509fd81312d65 (diff) |
Create Microsoft.IO.Redist (dotnet/corefx#31679)
* Create Microsoft.Internal.IO
Includes all of Path, Directory, *Info, etc. from System.IO with targets of NetFX 4.6.1 and NetCore 2.1.
* Tweaks / minor fixes
* Remove netstandard build.
* Add package
Update to build for 4.7.2 only
* Rename folder to prepare for project rename
* Change the name to Microsoft.IO.Redist
* Namespace tweaks
* Use open key, tweak references
* More tweaks on feedback
Also grab latest build tools for 4.7.x RIDs
Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
Diffstat (limited to 'src')
7 files changed, 69 insertions, 36 deletions
diff --git a/src/System.Private.CoreLib/shared/System/IO/DisableMediaInsertionPrompt.cs b/src/System.Private.CoreLib/shared/System/IO/DisableMediaInsertionPrompt.cs index aa10e8d88..a3a2d2983 100644 --- a/src/System.Private.CoreLib/shared/System/IO/DisableMediaInsertionPrompt.cs +++ b/src/System.Private.CoreLib/shared/System/IO/DisableMediaInsertionPrompt.cs @@ -2,7 +2,13 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if MS_IO_REDIST +using System; + +namespace Microsoft.IO +#else namespace System.IO +#endif { /// <summary> /// Simple wrapper to safely disable the normal media insertion prompt for diff --git a/src/System.Private.CoreLib/shared/System/IO/Path.Windows.cs b/src/System.Private.CoreLib/shared/System/IO/Path.Windows.cs index f22a9913e..1c27e0cf1 100644 --- a/src/System.Private.CoreLib/shared/System/IO/Path.Windows.cs +++ b/src/System.Private.CoreLib/shared/System/IO/Path.Windows.cs @@ -5,7 +5,14 @@ using System.Diagnostics; using System.Text; +#if MS_IO_REDIST +using System; +using System.IO; + +namespace Microsoft.IO +#else namespace System.IO +#endif { public static partial class Path { @@ -34,7 +41,7 @@ namespace System.IO throw new ArgumentNullException(nameof(path)); // If the path would normalize to string empty, we'll consider it empty - if (PathInternal.IsEffectivelyEmpty(path)) + if (PathInternal.IsEffectivelyEmpty(path.AsSpan())) throw new ArgumentException(SR.Arg_PathEmpty, nameof(path)); // Embedded null characters are the only invalid character case we trully care about. @@ -43,7 +50,7 @@ namespace System.IO if (path.IndexOf('\0') != -1) throw new ArgumentException(SR.Argument_InvalidPathChars, nameof(path)); - if (PathInternal.IsExtended(path)) + if (PathInternal.IsExtended(path.AsSpan())) { // \\?\ paths are considered normalized by definition. Windows doesn't normalize \\?\ // paths and neither should we. Even if we wanted to GetFullPathName does not work @@ -72,7 +79,7 @@ namespace System.IO if (IsPathFullyQualified(path)) return GetFullPath(path); - if (PathInternal.IsEffectivelyEmpty(path)) + if (PathInternal.IsEffectivelyEmpty(path.AsSpan())) return basePath; int length = path.Length; @@ -90,23 +97,23 @@ namespace System.IO // Drive relative paths Debug.Assert(length == 2 || !PathInternal.IsDirectorySeparator(path[2])); - if (GetVolumeName(path).EqualsOrdinal(GetVolumeName(basePath))) + if (GetVolumeName(path.AsSpan()).EqualsOrdinal(GetVolumeName(basePath.AsSpan()))) { // Matching root // "C:Foo" and "C:\Bar" => "C:\Bar\Foo" // "C:Foo" and "\\?\C:\Bar" => "\\?\C:\Bar\Foo" - combinedPath = Join(basePath, path.AsSpan(2)); + combinedPath = Join(basePath.AsSpan(), path.AsSpan(2)); } else { // No matching root, root to specified drive // "D:Foo" and "C:\Bar" => "D:Foo" // "D:Foo" and "\\?\C:\Bar" => "\\?\D:\Foo" - combinedPath = !PathInternal.IsDevice(basePath) + combinedPath = !PathInternal.IsDevice(basePath.AsSpan()) ? path.Insert(2, @"\") : length == 2 - ? JoinInternal(basePath.AsSpan(0, 4), path, @"\") - : JoinInternal(basePath.AsSpan(0, 4), path.AsSpan(0, 2), @"\", path.AsSpan(2)); + ? JoinInternal(basePath.AsSpan(0, 4), path.AsSpan(), @"\".AsSpan()) + : JoinInternal(basePath.AsSpan(0, 4), path.AsSpan(0, 2), @"\".AsSpan(), path.AsSpan(2)); } } else @@ -114,15 +121,15 @@ namespace System.IO // "Simple" relative path // "Foo" and "C:\Bar" => "C:\Bar\Foo" // "Foo" and "\\?\C:\Bar" => "\\?\C:\Bar\Foo" - combinedPath = JoinInternal(basePath, path); + combinedPath = JoinInternal(basePath.AsSpan(), path.AsSpan()); } // Device paths are normalized by definition, so passing something of this format (i.e. \\?\C:\.\tmp, \\.\C:\foo) // to Windows APIs won't do anything by design. Additionally, GetFullPathName() in Windows doesn't root // them properly. As such we need to manually remove segments and not use GetFullPath(). - return PathInternal.IsDevice(combinedPath) - ? PathInternal.RemoveRelativeSegments(combinedPath, PathInternal.GetRootLength(combinedPath)) + return PathInternal.IsDevice(combinedPath.AsSpan()) + ? PathInternal.RemoveRelativeSegments(combinedPath, PathInternal.GetRootLength(combinedPath.AsSpan())) : GetFullPath(combinedPath); } @@ -205,14 +212,14 @@ namespace System.IO // only contains whitespace characters an ArgumentException gets thrown. public static string GetPathRoot(string path) { - if (PathInternal.IsEffectivelyEmpty(path)) + if (PathInternal.IsEffectivelyEmpty(path.AsSpan())) return null; ReadOnlySpan<char> result = GetPathRoot(path.AsSpan()); if (path.Length == result.Length) return PathInternal.NormalizeDirectorySeparators(path); - return PathInternal.NormalizeDirectorySeparators(new string(result)); + return PathInternal.NormalizeDirectorySeparators(result.ToString()); } /// <remarks> @@ -273,11 +280,11 @@ namespace System.IO { bool isDevice = PathInternal.IsDevice(path); - if (!isDevice && path.Slice(0, 2).EqualsOrdinal(@"\\") ) + if (!isDevice && path.Slice(0, 2).EqualsOrdinal(@"\\".AsSpan()) ) return 2; else if (isDevice && path.Length >= 8 - && (path.Slice(0, 8).EqualsOrdinal(PathInternal.UncExtendedPathPrefix) - || path.Slice(5, 4).EqualsOrdinal(@"UNC\"))) + && (path.Slice(0, 8).EqualsOrdinal(PathInternal.UncExtendedPathPrefix.AsSpan()) + || path.Slice(5, 4).EqualsOrdinal(@"UNC\".AsSpan()))) return 8; return -1; diff --git a/src/System.Private.CoreLib/shared/System/IO/Path.cs b/src/System.Private.CoreLib/shared/System/IO/Path.cs index e619ecd8c..7b4565a13 100644 --- a/src/System.Private.CoreLib/shared/System/IO/Path.cs +++ b/src/System.Private.CoreLib/shared/System/IO/Path.cs @@ -6,7 +6,14 @@ using System.Diagnostics; using System.Runtime.InteropServices; using System.Text; +#if MS_IO_REDIST +using System; +using System.IO; + +namespace Microsoft.IO +#else namespace System.IO +#endif { // Provides methods for processing file system strings in a cross-platform manner. // Most of the methods don't do a complete parsing (such as examining a UNC hostname), @@ -79,10 +86,10 @@ namespace System.IO /// </remarks> public static string GetDirectoryName(string path) { - if (path == null || PathInternal.IsEffectivelyEmpty(path)) + if (path == null || PathInternal.IsEffectivelyEmpty(path.AsSpan())) return null; - int end = GetDirectoryNameOffset(path); + int end = GetDirectoryNameOffset(path.AsSpan()); return end >= 0 ? PathInternal.NormalizeDirectorySeparators(path.Substring(0, end)) : null; } @@ -130,7 +137,7 @@ namespace System.IO if (path == null) return null; - return new string(GetExtension(path.AsSpan())); + return GetExtension(path.AsSpan()).ToString(); } /// <summary> @@ -173,7 +180,7 @@ namespace System.IO if (path.Length == result.Length) return path; - return new string(result); + return result.ToString(); } /// <summary> @@ -204,7 +211,7 @@ namespace System.IO if (path.Length == result.Length) return path; - return new string(result); + return result.ToString(); } /// <summary> @@ -388,9 +395,9 @@ namespace System.IO public static string Join(ReadOnlySpan<char> path1, ReadOnlySpan<char> path2) { if (path1.Length == 0) - return new string(path2); + return path2.ToString(); if (path2.Length == 0) - return new string(path1); + return path1.ToString(); return JoinInternal(path1, path2); } @@ -498,7 +505,7 @@ namespace System.IO if (IsPathRooted(second.AsSpan())) return second; - return JoinInternal(first, second); + return JoinInternal(first.AsSpan(), second.AsSpan()); } private static string CombineInternal(string first, string second, string third) @@ -515,7 +522,7 @@ namespace System.IO if (IsPathRooted(second.AsSpan())) return CombineInternal(second, third); - return JoinInternal(first, second, third); + return JoinInternal(first.AsSpan(), second.AsSpan(), third.AsSpan()); } private static string CombineInternal(string first, string second, string third, string fourth) @@ -536,7 +543,7 @@ namespace System.IO if (IsPathRooted(second.AsSpan())) return CombineInternal(second, third, fourth); - return JoinInternal(first, second, third, fourth); + return JoinInternal(first.AsSpan(), second.AsSpan(), third.AsSpan(), fourth.AsSpan()); } private static unsafe string JoinInternal(ReadOnlySpan<char> first, ReadOnlySpan<char> second) @@ -548,7 +555,11 @@ namespace System.IO fixed (char* f = &MemoryMarshal.GetReference(first), s = &MemoryMarshal.GetReference(second)) { +#if MS_IO_REDIST + return StringExtensions.Create( +#else return string.Create( +#endif first.Length + second.Length + (hasSeparator ? 0 : 1), (First: (IntPtr)f, FirstLength: first.Length, Second: (IntPtr)s, SecondLength: second.Length, HasSeparator: hasSeparator), (destination, state) => @@ -572,7 +583,11 @@ namespace System.IO fixed (char* f = &MemoryMarshal.GetReference(first), s = &MemoryMarshal.GetReference(second), t = &MemoryMarshal.GetReference(third)) { +#if MS_IO_REDIST + return StringExtensions.Create( +#else return string.Create( +#endif first.Length + second.Length + third.Length + (firstHasSeparator ? 0 : 1) + (thirdHasSeparator ? 0 : 1), (First: (IntPtr)f, FirstLength: first.Length, Second: (IntPtr)s, SecondLength: second.Length, Third: (IntPtr)t, ThirdLength: third.Length, FirstHasSeparator: firstHasSeparator, ThirdHasSeparator: thirdHasSeparator), @@ -602,7 +617,12 @@ namespace System.IO fixed (char* f = &MemoryMarshal.GetReference(first), s = &MemoryMarshal.GetReference(second), t = &MemoryMarshal.GetReference(third), u = &MemoryMarshal.GetReference(fourth)) { + +#if MS_IO_REDIST + return StringExtensions.Create( +#else return string.Create( +#endif first.Length + second.Length + third.Length + fourth.Length + (firstHasSeparator ? 0 : 1) + (thirdHasSeparator ? 0 : 1) + (fourthHasSeparator ? 0 : 1), (First: (IntPtr)f, FirstLength: first.Length, Second: (IntPtr)s, SecondLength: second.Length, Third: (IntPtr)t, ThirdLength: third.Length, Fourth: (IntPtr)u, FourthLength:fourth.Length, @@ -697,7 +717,7 @@ namespace System.IO private static string GetRelativePath(string relativeTo, string path, StringComparison comparisonType) { if (string.IsNullOrEmpty(relativeTo)) throw new ArgumentNullException(nameof(relativeTo)); - if (PathInternal.IsEffectivelyEmpty(path)) throw new ArgumentNullException(nameof(path)); + if (PathInternal.IsEffectivelyEmpty(path.AsSpan())) throw new ArgumentNullException(nameof(path)); Debug.Assert(comparisonType == StringComparison.Ordinal || comparisonType == StringComparison.OrdinalIgnoreCase); relativeTo = GetFullPath(relativeTo); @@ -715,10 +735,10 @@ namespace System.IO // Trailing separators aren't significant for comparison int relativeToLength = relativeTo.Length; - if (PathInternal.EndsInDirectorySeparator(relativeTo)) + if (PathInternal.EndsInDirectorySeparator(relativeTo.AsSpan())) relativeToLength--; - bool pathEndsInSeparator = PathInternal.EndsInDirectorySeparator(path); + bool pathEndsInSeparator = PathInternal.EndsInDirectorySeparator(path.AsSpan()); int pathLength = path.Length; if (pathEndsInSeparator) pathLength--; diff --git a/src/System.Private.CoreLib/shared/System/IO/PathHelper.Windows.cs b/src/System.Private.CoreLib/shared/System/IO/PathHelper.Windows.cs index ed49422c1..bada2f5cd 100644 --- a/src/System.Private.CoreLib/shared/System/IO/PathHelper.Windows.cs +++ b/src/System.Private.CoreLib/shared/System/IO/PathHelper.Windows.cs @@ -243,7 +243,7 @@ namespace System.IO ReadOnlySpan<char> output = builderToUse.AsSpan(rootDifference); string returnValue = ((originalPath != null) && output.Equals(originalPath.AsSpan(), StringComparison.Ordinal)) - ? originalPath : new string(output); + ? originalPath : output.ToString(); inputBuilder.Dispose(); return returnValue; diff --git a/src/System.Private.CoreLib/shared/System/IO/PathInternal.Windows.cs b/src/System.Private.CoreLib/shared/System/IO/PathInternal.Windows.cs index b01482abd..5f9ee0e02 100644 --- a/src/System.Private.CoreLib/shared/System/IO/PathInternal.Windows.cs +++ b/src/System.Private.CoreLib/shared/System/IO/PathInternal.Windows.cs @@ -130,7 +130,7 @@ namespace System.IO // In any case, all internal usages should be hitting normalize path (Path.GetFullPath) before they hit this // shimming method. (Or making a change that doesn't impact normalization, such as adding a filename to a // normalized base path.) - if (IsPartiallyQualified(path) || IsDevice(path)) + if (IsPartiallyQualified(path.AsSpan()) || IsDevice(path.AsSpan())) return path; // Given \\server\share in longpath becomes \\?\UNC\server\share diff --git a/src/System.Private.CoreLib/shared/System/IO/PathInternal.cs b/src/System.Private.CoreLib/shared/System/IO/PathInternal.cs index c9defac1f..1b08a2612 100644 --- a/src/System.Private.CoreLib/shared/System/IO/PathInternal.cs +++ b/src/System.Private.CoreLib/shared/System/IO/PathInternal.cs @@ -22,10 +22,10 @@ namespace System.IO internal static bool StartsWithDirectorySeparator(ReadOnlySpan<char> path) => path.Length > 0 && IsDirectorySeparator(path[0]); internal static string EnsureTrailingSeparator(string path) - => EndsInDirectorySeparator(path) ? path : path + DirectorySeparatorCharAsString; + => EndsInDirectorySeparator(path.AsSpan()) ? path : path + DirectorySeparatorCharAsString; internal static string TrimEndingDirectorySeparator(string path) => - EndsInDirectorySeparator(path) && !IsRoot(path) ? + EndsInDirectorySeparator(path.AsSpan()) && !IsRoot(path.AsSpan()) ? path.Substring(0, path.Length - 1) : path; @@ -97,8 +97,8 @@ namespace System.IO /// </summary> internal static bool AreRootsEqual(string first, string second, StringComparison comparisonType) { - int firstRootLength = GetRootLength(first); - int secondRootLength = GetRootLength(second); + int firstRootLength = GetRootLength(first.AsSpan()); + int secondRootLength = GetRootLength(second.AsSpan()); return firstRootLength == secondRootLength && string.Compare( diff --git a/src/System.Private.CoreLib/shared/System/Text/ValueStringBuilder.cs b/src/System.Private.CoreLib/shared/System/Text/ValueStringBuilder.cs index 045a40b65..21cc3dc01 100644 --- a/src/System.Private.CoreLib/shared/System/Text/ValueStringBuilder.cs +++ b/src/System.Private.CoreLib/shared/System/Text/ValueStringBuilder.cs @@ -73,7 +73,7 @@ namespace System.Text public override string ToString() { - var s = new string(_chars.Slice(0, _pos)); + var s = _chars.Slice(0, _pos).ToString(); Dispose(); return s; } |