enable using filesystem from a UNC location (#4998)

* enable using filesystem from a UNC location

* [feature]
address PR feedback

* [feature]
removed changed in NavigationProviderBase and made change in FileSystemProvider where it should belong

* added variations of tests for set-location and push-location
no need to run [feature] anymore since it passed previously and the test case added is CI

* [feature]
move code to reproduce UNC path to GetParentPath()
This commit is contained in:
Steve Lee 2017-10-09 14:05:16 -07:00 committed by Aditya Patwardhan
parent 9d5823baeb
commit 90165fc17c
2 changed files with 28 additions and 0 deletions

View file

@ -4817,6 +4817,13 @@ namespace Microsoft.PowerShell.Commands
{
parentPath = EnsureDriveIsRooted(parentPath);
}
#if !UNIX
else if (parentPath.Equals(StringLiterals.DefaultPathSeparatorString, StringComparison.Ordinal))
{
// make sure we return two backslashes so it still results in a UNC path
parentPath = "\\\\";
}
#endif
return parentPath;
} // GetParentPath

View file

@ -1368,3 +1368,24 @@ Describe "Extended FileSystem Path/Location Cmdlet Provider Tests" -Tags "Featur
}
}
}
Describe "UNC paths" -Tags 'CI' {
It "Can Get-ChildItems from a UNC location using <cmdlet>" -Skip:(!$IsWindows) -TestCases @(
@{cmdlet="Push-Location"},
@{cmdlet="Set-Location"}
) {
param($cmdlet)
$originalLocation = Get-Location
try {
$systemDrive = ($env:SystemDrive).Replace(":","$")
$testPath = Join-Path "\\localhost" $systemDrive
& $cmdlet $testPath
Get-Location | Should BeExactly "Microsoft.PowerShell.Core\FileSystem::$testPath"
$children = { Get-ChildItem -ErrorAction Stop } | Should Not Throw
$children.Count | Should BeGreaterThan 0
}
finally {
Set-Location $originalLocation
}
}
}