mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-25 14:20:22 -07:00
support missing drive letters in PS path
type (#29884)
* fixes #26623 * Test-Path (and thus `-type path` in Get-AnsibleParam) fail on a nonexistent drive letter, since it can't be mapped to a PSProvider. * added support and basic smoke tests for
This commit is contained in:
parent
8515db8588
commit
1e2ce4c8ab
4 changed files with 45 additions and 1 deletions
|
@ -207,7 +207,17 @@ Function Get-AnsibleParam($obj, $name, $default = $null, $resultobj = @{}, $fail
|
|||
$value = Expand-Environment($value)
|
||||
# Test if a valid path is provided
|
||||
if (-not (Test-Path -IsValid $value)) {
|
||||
Fail-Json -obj $resultobj -message "Get-AnsibleParam: Parameter '$name' has an invalid path '$value' specified."
|
||||
$path_invalid = $true
|
||||
# could still be a valid-shaped path with a nonexistent drive letter
|
||||
if ($value -match "^\w:") {
|
||||
# rewrite path with a valid drive letter and recheck the shape- this might still fail, eg, a nonexistent non-filesystem PS path
|
||||
if (Test-Path -IsValid $(@(Get-PSDrive -PSProvider Filesystem)[0].Name + $value.Substring(1))) {
|
||||
$path_invalid = $false
|
||||
}
|
||||
}
|
||||
if ($path_invalid) {
|
||||
Fail-Json -obj $resultobj -message "Get-AnsibleParam: Parameter '$name' has an invalid path '$value' specified."
|
||||
}
|
||||
}
|
||||
} elseif ($type -eq "str") {
|
||||
# Convert str types to real Powershell strings
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue