Skip to content

Commit 04a770f

Browse files
committed
Use native Test-Path in validation scripts which can handle relative paths, add Resolve-Path to main process block
1 parent 1e5e9f0 commit 04a770f

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/PSAppDeployToolkit.Tools/Public/Convert-ADTDeployment.ps1

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,15 @@ function Convert-ADTDeployment
7777
{
7878
$PSCmdlet.ThrowTerminatingError((New-ADTValidateScriptErrorRecord -ParameterName Path -ProvidedValue $_ -ExceptionMessage 'The specified path does not exist.'))
7979
}
80-
elseif ([System.IO.File]::Exists($_) -and [System.IO.Path]::GetExtension($_) -ne '.ps1')
80+
elseif ((Test-Path -LiteralPath $_ -PathType Leaf) -and [System.IO.Path]::GetExtension($_) -ne '.ps1')
8181
{
8282
$PSCmdlet.ThrowTerminatingError((New-ADTValidateScriptErrorRecord -ParameterName Path -ProvidedValue $_ -ExceptionMessage 'The specified file is not a PowerShell script.'))
8383
}
84-
elseif ([System.IO.Directory]::Exists($_) -and -not [System.IO.File]::Exists([System.IO.Path]::Combine($_, 'Deploy-Application.ps1')))
84+
elseif ((Test-Path -LiteralPath $_ -PathType Container) -and -not (Test-Path -LiteralPath (Join-Path -Path $_ -ChildPath 'Deploy-Application.ps1') -PathType Leaf))
8585
{
8686
$PSCmdlet.ThrowTerminatingError((New-ADTValidateScriptErrorRecord -ParameterName Path -ProvidedValue $_ -ExceptionMessage 'Deploy-Application.ps1 not found in the specified path.'))
8787
}
88-
elseif ([System.IO.Directory]::Exists($_) -and -not [System.IO.Directory]::Exists([System.IO.Path]::Combine($_, 'AppDeployToolkit')))
88+
elseif ((Test-Path -LiteralPath $_ -PathType Container) -and -not (Test-Path -LiteralPath (Join-Path -Path $_ -ChildPath 'AppDeployToolkit') -PathType Container))
8989
{
9090
$PSCmdlet.ThrowTerminatingError((New-ADTValidateScriptErrorRecord -ParameterName Path -ProvidedValue $_ -ExceptionMessage 'AppDeployToolkit folder not found in the specified path.'))
9191
}
@@ -139,6 +139,7 @@ function Convert-ADTDeployment
139139
{
140140
try
141141
{
142+
$Path = (Resolve-Path -LiteralPath $Path).Path
142143
$tempFolderName = "Convert-ADTDeployment_$([System.IO.Path]::GetRandomFileName().Replace('.', ''))"
143144
$tempFolderPath = [System.IO.Path]::Combine([System.IO.Path]::GetTempPath(), $tempFolderName)
144145

src/PSAppDeployToolkit.Tools/Public/Test-ADTCompatibility.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function Test-ADTCompatibility
6565
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
6666
[Alias('FullName')]
6767
[ValidateScript({
68-
if (![System.IO.File]::Exists($_))
68+
if (!(Test-Path -LiteralPath $_ -PathType Leaf))
6969
{
7070
$PSCmdlet.ThrowTerminatingError((New-ADTValidateScriptErrorRecord -ParameterName FilePath -ProvidedValue $_ -ExceptionMessage 'The specified file does not exist.'))
7171
}
@@ -92,6 +92,8 @@ function Test-ADTCompatibility
9292
{
9393
try
9494
{
95+
$FilePath = (Resolve-Path -LiteralPath $FilePath).Path
96+
9597
if ($FilePath -notmatch '(Deploy-Application\.ps1|Invoke-AppDeployToolkit\.ps1)$')
9698
{
9799
Write-Warning -Message "This function is designed to test PSAppDeployToolkit deployment scripts such as Deploy-Application.ps1 or Invoke-AppDeployToolkit.ps1."

0 commit comments

Comments
 (0)