Remove unncessary check for Paths.count > 0 as there is code later to use the current (#5596)

Remove unnecessary check for Paths.count > 0 as there is code later to use the current working directory since -Path is not a mandatory parameter.
Updated ShouldProcess to output the internal action on adding paths rather than the user action (which is the cmdlet name).

Updated tests to not specify -Path

Fix #5594
This commit is contained in:
Steve Lee 2017-12-01 10:57:00 -08:00 committed by Travis Plunk
parent baa0a28a21
commit b69ff717ab
2 changed files with 14 additions and 12 deletions

View File

@ -95,7 +95,7 @@ namespace Microsoft.PowerShell.Commands
{
foreach (PathInfo tempPath in SessionState.Path.GetResolvedPSPathFromPSPath(p))
{
if (ShouldProcess(tempPath.ProviderPath))
if (ShouldProcess("Including path " + tempPath.ProviderPath, "", ""))
{
paths.Add(tempPath.ProviderPath);
}
@ -103,17 +103,16 @@ namespace Microsoft.PowerShell.Commands
}
}
// We add 'paths.Count > 0' to support 'ShouldProcess()'
if (paths.Count > 0 )
string drive = null;
// resolve catalog destination Path
if (!SessionState.Path.IsPSAbsolute(catalogFilePath, out drive) && !System.IO.Path.IsPathRooted(catalogFilePath))
{
string drive = null;
// resolve catalog destination Path
if (!SessionState.Path.IsPSAbsolute(catalogFilePath, out drive) && !System.IO.Path.IsPathRooted(catalogFilePath))
{
catalogFilePath = SessionState.Path.GetUnresolvedProviderPathFromPSPath(catalogFilePath);
}
catalogFilePath = SessionState.Path.GetUnresolvedProviderPathFromPSPath(catalogFilePath);
}
if (ShouldProcess(catalogFilePath))
{
PerformAction(paths, catalogFilePath);
}
}

View File

@ -233,11 +233,14 @@ Describe "Test suite for NewFileCatalogAndTestFileCatalogCmdlets" -Tags "CI" {
try
{
copy-item "$testDataPath\UserConfigProv" $env:temp -Recurse -ErrorAction SilentlyContinue
$null = New-FileCatalog -Path $env:temp\UserConfigProv\ -CatalogFilePath $catalogPath -CatalogVersion 1.0
$result = Test-FileCatalog -Path $env:temp\UserConfigProv\ -CatalogFilePath $catalogPath
Push-Location "$env:TEMP\UserConfigProv"
# When -Path is not specified, it should use current directory
$null = New-FileCatalog -CatalogFilePath $catalogPath -CatalogVersion 1.0
$result = Test-FileCatalog -CatalogFilePath $catalogPath
}
finally
{
Pop-Location
Remove-Item "$catalogPath" -Force -ErrorAction SilentlyContinue
Remove-Item "$env:temp\UserConfigProv\" -Force -ErrorAction SilentlyContinue -Recurse
}