Skip to content

Commit e185f89

Browse files
SteveL-MSFTAndrew
authored andcommitted
Handle exception if enumerating files fails when rebuilding path to have correct casing (#11014)
1 parent 1c817c6 commit e185f89

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

src/System.Management.Automation/namespaces/FileSystemProvider.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,22 @@ private static string GetCorrectCasedPath(string path)
161161
else
162162
{
163163
// Use GetFileSystemEntries to get the correct casing of this element
164-
var entries = Directory.GetFileSystemEntries(exactPath, item);
165-
if (entries.Length > 0)
164+
try
166165
{
167-
exactPath = entries.First();
166+
var entries = Directory.GetFileSystemEntries(exactPath, item);
167+
if (entries.Length > 0)
168+
{
169+
exactPath = entries.First();
170+
}
171+
else
172+
{
173+
// If previous call didn't return anything, something failed so we just return the path we were given
174+
return path;
175+
}
168176
}
169-
else
177+
catch
170178
{
171-
// If previous call didn't return anything, something failed so we just return the path we were given
179+
// If we can't enumerate, we stop and just return the original path
172180
return path;
173181
}
174182
}

test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,23 @@ Describe "Basic FileSystem Provider Tests" -Tags "CI" {
279279
}
280280
}
281281

282+
Context "Appx path" {
283+
BeforeAll {
284+
$skipTest = $true
285+
if ($IsWindows -and (Get-Command -Name Get-AppxPackage) -and (Get-AppxPackage Microsoft.WindowsCalculator)) {
286+
$skipTest = $false
287+
}
288+
}
289+
290+
It "Can get an appx package item" -Skip:$skipTest {
291+
$pkgDir = (Get-AppxPackage)[0].InstallLocation
292+
293+
Get-Item $pkgDir\Calculator.exe -ErrorAction Stop | Should -BeOfType [System.IO.FileInfo]
294+
Get-Item -Path $pkgDir -ErrorAction Stop | Should -BeOfType [System.IO.DirectoryInfo]
295+
Get-ChildItem -Path $pkgDir -ErrorAction Stop | Should -Not -BeNullOrEmpty
296+
}
297+
}
298+
282299
Context "Validate basic host navigation functionality" {
283300
BeforeAll {
284301
#build semi-complex directory structure to test navigation within

0 commit comments

Comments
 (0)