Imported Upstream version 4.0.0~alpha1

Former-commit-id: 806294f5ded97629b74c85c09952f2a74fe182d9
This commit is contained in:
Jo Shields
2015-04-07 09:35:12 +01:00
parent 283343f570
commit 3c1f479b9d
22469 changed files with 2931443 additions and 869343 deletions

View File

@ -362,8 +362,8 @@ namespace System.IO {
var canonicalize = true;
if (path.Length >= 2 &&
IsDsc (path [0]) &&
IsDsc (path [1])) {
IsDirectorySeparator (path [0]) &&
IsDirectorySeparator (path [1])) {
if (path.Length == 2 || path.IndexOf (path [0], 2) < 0)
throw new ArgumentException ("UNC paths should be of the form \\\\server\\share.");
@ -390,8 +390,8 @@ namespace System.IO {
path = cwd + DirectorySeparatorChar + path;
} else if (DirectorySeparatorChar == '\\' &&
path.Length >= 2 &&
IsDsc (path [0]) &&
!IsDsc (path [1])) { // like `\abc\def'
IsDirectorySeparator (path [0]) &&
!IsDirectorySeparator (path [1])) { // like `\abc\def'
string current = Directory.InsecureGetCurrentDirectory();
if (current [1] == VolumeSeparatorChar)
path = current.Substring (0, 2) + path;
@ -404,16 +404,16 @@ namespace System.IO {
path = CanonicalizePath (path);
// if the original ended with a [Alt]DirectorySeparatorChar then ensure the full path also ends with one
if (IsDsc (end) && (path [path.Length - 1] != DirectorySeparatorChar))
if (IsDirectorySeparator (end) && (path [path.Length - 1] != DirectorySeparatorChar))
path += DirectorySeparatorChar;
return path;
}
static bool IsDsc (char c) {
internal static bool IsDirectorySeparator (char c) {
return c == DirectorySeparatorChar || c == AltDirectorySeparatorChar;
}
public static string GetPathRoot (string path)
{
if (path == null)
@ -427,36 +427,36 @@ namespace System.IO {
if (DirectorySeparatorChar == '/') {
// UNIX
return IsDsc (path [0]) ? DirectorySeparatorStr : String.Empty;
return IsDirectorySeparator (path [0]) ? DirectorySeparatorStr : String.Empty;
} else {
// Windows
int len = 2;
if (path.Length == 1 && IsDsc (path [0]))
if (path.Length == 1 && IsDirectorySeparator (path [0]))
return DirectorySeparatorStr;
else if (path.Length < 2)
return String.Empty;
if (IsDsc (path [0]) && IsDsc (path[1])) {
if (IsDirectorySeparator (path [0]) && IsDirectorySeparator (path[1])) {
// UNC: \\server or \\server\share
// Get server
while (len < path.Length && !IsDsc (path [len])) len++;
while (len < path.Length && !IsDirectorySeparator (path [len])) len++;
// Get share
if (len < path.Length) {
len++;
while (len < path.Length && !IsDsc (path [len])) len++;
while (len < path.Length && !IsDirectorySeparator (path [len])) len++;
}
return DirectorySeparatorStr +
DirectorySeparatorStr +
path.Substring (2, len - 2).Replace (AltDirectorySeparatorChar, DirectorySeparatorChar);
} else if (IsDsc (path [0])) {
} else if (IsDirectorySeparator (path [0])) {
// path starts with '\' or '/'
return DirectorySeparatorStr;
} else if (path[1] == VolumeSeparatorChar) {
// C:\folder
if (path.Length >= 3 && (IsDsc (path [2]))) len++;
if (path.Length >= 3 && (IsDirectorySeparator (path [2]))) len++;
} else
return Directory.GetCurrentDirectory ().Substring (0, 2);// + path.Substring (0, len);
return path.Substring (0, len);
@ -628,11 +628,11 @@ namespace System.IO {
static string GetServerAndShare (string path)
{
int len = 2;
while (len < path.Length && !IsDsc (path [len])) len++;
while (len < path.Length && !IsDirectorySeparator (path [len])) len++;
if (len < path.Length) {
len++;
while (len < path.Length && !IsDsc (path [len])) len++;
while (len < path.Length && !IsDirectorySeparator (path [len])) len++;
}
return path.Substring (2, len - 2).Replace (AltDirectorySeparatorChar, DirectorySeparatorChar);
@ -646,8 +646,8 @@ namespace System.IO {
return false;
// UNC handling
if (IsDsc (root[0]) && IsDsc (root[1])) {
if (!(IsDsc (path[0]) && IsDsc (path[1])))
if (IsDirectorySeparator (root[0]) && IsDirectorySeparator (root[1])) {
if (!(IsDirectorySeparator (path[0]) && IsDirectorySeparator (path[1])))
return false;
string rootShare = GetServerAndShare (root);
@ -664,7 +664,7 @@ namespace System.IO {
return false;
if ((root.Length > 2) && (path.Length > 2)) {
// but don't directory compare the directory separator
return (IsDsc (root[2]) && IsDsc (path[2]));
return (IsDirectorySeparator (root[2]) && IsDirectorySeparator (path[2]));
}
return true;
}
@ -692,7 +692,7 @@ namespace System.IO {
int target = 0;
bool isUnc = Environment.IsRunningOnWindows &&
root.Length > 2 && IsDsc (root[0]) && IsDsc (root[1]);
root.Length > 2 && IsDirectorySeparator (root[0]) && IsDirectorySeparator (root[1]);
// Set an overwrite limit for UNC paths since '\' + server + share
// must not be eliminated by the '..' elimination algorithm.
@ -728,7 +728,7 @@ namespace System.IO {
if (isUnc) {
return ret;
} else if (!IsDsc (path[0]) && SameRoot (root, path)) {
} else if (!IsDirectorySeparator (path[0]) && SameRoot (root, path)) {
if (ret.Length <= 2 && !ret.EndsWith (DirectorySeparatorStr)) // '\' after "c:"
ret += Path.DirectorySeparatorChar;
return ret;
@ -736,10 +736,10 @@ namespace System.IO {
string current = Directory.GetCurrentDirectory ();
if (current.Length > 1 && current[1] == Path.VolumeSeparatorChar) {
// DOS local file path
if (ret.Length == 0 || IsDsc (ret[0]))
if (ret.Length == 0 || IsDirectorySeparator (ret[0]))
ret += '\\';
return current.Substring (0, 2) + ret;
} else if (IsDsc (current[current.Length - 1]) && IsDsc (ret[0]))
} else if (IsDirectorySeparator (current[current.Length - 1]) && IsDirectorySeparator (ret[0]))
return current + ret.Substring (1);
else
return current + ret;
@ -776,11 +776,7 @@ namespace System.IO {
return String.Compare (subset, slast, path, slast, subset.Length - slast) == 0;
}
#if NET_4_0
public
#else
internal
#endif
static string Combine (params string [] paths)
{
if (paths == null)
@ -821,11 +817,7 @@ namespace System.IO {
return ret.ToString ();
}
#if NET_4_0
public
#else
internal
#endif
static string Combine (string path1, string path2, string path3)
{
if (path1 == null)
@ -840,11 +832,7 @@ namespace System.IO {
return Combine (new string [] { path1, path2, path3 });
}
#if NET_4_0
public
#else
internal
#endif
static string Combine (string path1, string path2, string path3, string path4)
{
if (path1 == null)