Update code to use single method to check if path is UNC (#8680)

update all checks if path is unc to one method
This commit is contained in:
Steve Lee 2019-01-23 09:37:45 -08:00 committed by Aditya Patwardhan
parent 0c2a8911d6
commit f7c25e8f7c

View file

@ -1052,7 +1052,7 @@ namespace Microsoft.PowerShell.Commands
#endif
// Make sure the path is either drive rooted or UNC Path
if (!IsAbsolutePath(path) && !IsUNCPath(path))
if (!IsAbsolutePath(path) && !Utils.PathIsUnc(path))
{
return false;
}
@ -4676,7 +4676,7 @@ namespace Microsoft.PowerShell.Commands
protected override string GetParentPath(string path, string root)
{
string parentPath = base.GetParentPath(path, root);
if (!IsUNCPath(path))
if (!Utils.PathIsUnc(path))
{
parentPath = EnsureDriveIsRooted(parentPath);
}
@ -4712,11 +4712,6 @@ namespace Microsoft.PowerShell.Commands
return result;
}
private static bool IsUNCPath(string path)
{
return path.StartsWith("\\\\", StringComparison.Ordinal);
}
/// <summary>
/// Determines if the specified path is a root of a UNC share
/// by counting the path separators "\" following "\\". If only
@ -4735,7 +4730,7 @@ namespace Microsoft.PowerShell.Commands
if (!string.IsNullOrEmpty(path))
{
if (IsUNCPath(path))
if (Utils.PathIsUnc(path))
{
int lastIndex = path.Length - 1;
@ -4863,8 +4858,7 @@ namespace Microsoft.PowerShell.Commands
if (originalPathComparison.StartsWith(basePathComparison, StringComparison.OrdinalIgnoreCase))
{
bool isUNCPath = IsUNCPath(result);
if (!isUNCPath)
if (!Utils.PathIsUnc(result))
{
// Add the base path back on so that it can be used for
// processing
@ -6934,17 +6928,6 @@ namespace Microsoft.PowerShell.Commands
[DllImport("api-ms-win-core-shlwapi-legacy-l1-1-0.dll", CharSet = CharSet.Unicode)]
internal static extern int PathGetDriveNumber(string path);
/// <summary>
/// Determines if a path string is a valid Universal Naming Convention (UNC) path, as opposed to a path based on a drive letter.
/// </summary>
/// <param name="path">
/// Path of the file being executed
/// </param>
/// <returns>Returns TRUE if the string is a valid UNC path; otherwise, FALSE.</returns>
[DllImport("api-ms-win-core-shlwapi-legacy-l1-1-0.dll", CharSet = CharSet.Unicode)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool PathIsUNC(string path);
/// <summary>
/// The API 'PathIsNetworkPath' is not available in CoreSystem.
/// This implementation is based on the 'PathIsNetworkPath' API.
@ -6958,7 +6941,7 @@ namespace Microsoft.PowerShell.Commands
return false;
}
if (PathIsUNC(path))
if (Utils.PathIsUnc(path))
{
return true;
}