You've already forked linux-packaging-mono
Imported Upstream version 5.0.0.42
Former-commit-id: fd56571888259555122d8a0f58c68838229cea2b
This commit is contained in:
parent
1190d13a04
commit
6bdd276d05
@ -284,7 +284,7 @@ namespace System.IO {
|
||||
|
||||
SecurityManager.EnsureElevatedPermissions (); // this is a no-op outside moonlight
|
||||
|
||||
#if !MOBILE
|
||||
#if MONO_FEATURE_CAS
|
||||
if (SecurityManager.SecurityEnabled) {
|
||||
new FileIOPermission (FileIOPermissionAccess.PathDiscovery, fullpath).Demand ();
|
||||
}
|
||||
@ -297,7 +297,7 @@ namespace System.IO {
|
||||
return InsecureGetFullPath (path);
|
||||
}
|
||||
|
||||
#if !MOBILE
|
||||
#if WIN_PLATFORM
|
||||
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa364963%28v=vs.85%29.aspx
|
||||
[DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
|
||||
private static extern int GetFullPathName(string path, int numBufferChars, StringBuilder buffer, ref IntPtr lpFilePartOrNull);
|
||||
@ -318,11 +318,13 @@ namespace System.IO {
|
||||
buffer = new StringBuilder(length);
|
||||
GetFullPathName(path, length, buffer, ref ptr);
|
||||
}
|
||||
|
||||
return buffer.ToString();
|
||||
}
|
||||
|
||||
internal static string WindowsDriveAdjustment (string path)
|
||||
{
|
||||
|
||||
// three special cases to consider when a drive is specified
|
||||
if (path.Length < 2) {
|
||||
if (path.Length == 1 && (path[0] == '\\' || path[0] == '/'))
|
||||
@ -365,7 +367,7 @@ namespace System.IO {
|
||||
string msg = Locale.GetText ("The specified path is not of a legal form (empty).");
|
||||
throw new ArgumentException (msg);
|
||||
}
|
||||
#if !MOBILE
|
||||
#if WIN_PLATFORM
|
||||
// adjust for drives, i.e. a special case for windows
|
||||
if (Environment.IsRunningOnWindows)
|
||||
path = WindowsDriveAdjustment (path);
|
||||
@ -732,6 +734,7 @@ namespace System.IO {
|
||||
else {
|
||||
string ret = String.Join (DirectorySeparatorStr, dirs, 0, target);
|
||||
if (Environment.IsRunningOnWindows) {
|
||||
#if WIN_PLATFORM
|
||||
// append leading '\' of the UNC path that was lost in STEP 3.
|
||||
if (isUnc)
|
||||
ret = Path.DirectorySeparatorStr + ret;
|
||||
@ -757,6 +760,7 @@ namespace System.IO {
|
||||
else
|
||||
return current + ret;
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
if (root != "" && ret.Length > 0 && ret [0] != '/')
|
||||
ret = root + ret;
|
||||
@ -876,11 +880,13 @@ namespace System.IO {
|
||||
throw new ArgumentException (Locale.GetText ("Path is empty"));
|
||||
if (path.IndexOfAny (Path.InvalidPathChars) != -1)
|
||||
throw new ArgumentException (Locale.GetText ("Path contains invalid chars"));
|
||||
#if WIN_PLATFORM
|
||||
if (Environment.IsRunningOnWindows) {
|
||||
int idx = path.IndexOf (':');
|
||||
if (idx >= 0 && idx != 1)
|
||||
throw new ArgumentException (parameterName);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
internal static string DirectorySeparatorCharAsString {
|
||||
@ -890,5 +896,61 @@ namespace System.IO {
|
||||
}
|
||||
|
||||
internal const int MAX_PATH = 260; // From WinDef.h
|
||||
|
||||
#region Copied from referencesource
|
||||
// this was copied from corefx since it's not available in referencesource
|
||||
internal static readonly char[] trimEndCharsWindows = { (char)0x9, (char)0xA, (char)0xB, (char)0xC, (char)0xD, (char)0x20, (char)0x85, (char)0xA0 };
|
||||
internal static readonly char[] trimEndCharsUnix = { };
|
||||
|
||||
internal static char[] TrimEndChars => Environment.IsRunningOnWindows ? trimEndCharsWindows : trimEndCharsUnix;
|
||||
|
||||
// ".." can only be used if it is specified as a part of a valid File/Directory name. We disallow
|
||||
// the user being able to use it to move up directories. Here are some examples eg
|
||||
// Valid: a..b abc..d
|
||||
// Invalid: ..ab ab.. .. abc..d\abc..
|
||||
//
|
||||
internal static void CheckSearchPattern(String searchPattern)
|
||||
{
|
||||
int index;
|
||||
while ((index = searchPattern.IndexOf("..", StringComparison.Ordinal)) != -1) {
|
||||
|
||||
if (index + 2 == searchPattern.Length) // Terminal ".." . Files names cannot end in ".."
|
||||
throw new ArgumentException(Environment.GetResourceString("Arg_InvalidSearchPattern"));
|
||||
|
||||
if ((searchPattern[index+2] == DirectorySeparatorChar)
|
||||
|| (searchPattern[index+2] == AltDirectorySeparatorChar))
|
||||
throw new ArgumentException(Environment.GetResourceString("Arg_InvalidSearchPattern"));
|
||||
|
||||
searchPattern = searchPattern.Substring(index + 2);
|
||||
}
|
||||
}
|
||||
|
||||
internal static void CheckInvalidPathChars(string path, bool checkAdditional = false)
|
||||
{
|
||||
if (path == null)
|
||||
throw new ArgumentNullException("path");
|
||||
|
||||
if (PathInternal.HasIllegalCharacters(path, checkAdditional))
|
||||
throw new ArgumentException(Environment.GetResourceString("Argument_InvalidPathChars"));
|
||||
}
|
||||
|
||||
internal static String InternalCombine(String path1, String path2) {
|
||||
if (path1==null || path2==null)
|
||||
throw new ArgumentNullException((path1==null) ? "path1" : "path2");
|
||||
CheckInvalidPathChars(path1);
|
||||
CheckInvalidPathChars(path2);
|
||||
|
||||
if (path2.Length == 0)
|
||||
throw new ArgumentException(Environment.GetResourceString("Argument_PathEmpty"), "path2");
|
||||
if (IsPathRooted(path2))
|
||||
throw new ArgumentException(Environment.GetResourceString("Arg_Path2IsRooted"), "path2");
|
||||
int i = path1.Length;
|
||||
if (i == 0) return path2;
|
||||
char ch = path1[i - 1];
|
||||
if (ch != DirectorySeparatorChar && ch != AltDirectorySeparatorChar && ch != VolumeSeparatorChar)
|
||||
return path1 + DirectorySeparatorCharAsString + path2;
|
||||
return path1 + path2;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user