From 90165fc17cb28eb1a8d9845cdec17417e89bd26d Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Mon, 9 Oct 2017 14:05:16 -0700 Subject: [PATCH] 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() --- .../namespaces/FileSystemProvider.cs | 7 +++++++ .../FileSystem.Tests.ps1 | 21 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/System.Management.Automation/namespaces/FileSystemProvider.cs b/src/System.Management.Automation/namespaces/FileSystemProvider.cs index eca208ec5a..172e884957 100644 --- a/src/System.Management.Automation/namespaces/FileSystemProvider.cs +++ b/src/System.Management.Automation/namespaces/FileSystemProvider.cs @@ -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 diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1 index c50c655805..29b6659922 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1 @@ -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 " -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 + } + } +}