Skip to content

Commit

Permalink
Master (ansible#62626)
Browse files Browse the repository at this point in the history
* Update win_package.ps1

Update Test-Path to use -LiteralPath instead of -Path to fix issue where powershell will not detect path with special characters such as '=' and '[]'.

* Update win_package.ps1

modified other instances of -Path and changed to -LiteralPath.  All except line L243 since it is a different function.

* added literal path to get-itemproperty
  • Loading branch information
richardsonky authored and jborean93 committed Sep 20, 2019
1 parent 2a206f0 commit 153a322
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions lib/ansible/modules/windows/win_package.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ Function Test-RegistryProperty($path, $name) {
# will validate if the registry key contains the property, returns true
# if the property exists and false if the property does not
try {
$value = (Get-Item -Path $path).GetValue($name)
$value = (Get-Item -LiteralPath $path).GetValue($name)
# need to do it this way return ($null -eq $value) does not work
if ($null -eq $value) {
return $false
Expand Down Expand Up @@ -193,13 +193,13 @@ Function Get-ProgramMetadata($state, $path, $product_id, [PSCredential]$credenti
$test_path = $path
}

$valid_path = Test-Path -Path $test_path -PathType Leaf
$valid_path = Test-Path -LiteralPath $test_path -PathType Leaf
if ($valid_path -ne $true) {
$metadata.path_error = "the file at the UNC path $path cannot be reached, ensure the user_name account has access to this path or use an auth transport with credential delegation"
}
} else {
$metadata.location_type = [LocationType]::Local
$valid_path = Test-Path -Path $path -PathType Leaf
$valid_path = Test-Path -LiteralPath $path -PathType Leaf
if ($valid_path -ne $true) {
$metadata.path_error = "the file at the local path $path cannot be reached"
}
Expand Down Expand Up @@ -230,17 +230,17 @@ Function Get-ProgramMetadata($state, $path, $product_id, [PSCredential]$credenti
if ($null -ne $metadata.product_id) {
$uninstall_key = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$($metadata.product_id)"
$uninstall_key_wow64 = "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\$($metadata.product_id)"
if (Test-Path -Path $uninstall_key) {
if (Test-Path -LiteralPath $uninstall_key) {
$metadata.installed = $true
} elseif (Test-Path -Path $uninstall_key_wow64) {
} elseif (Test-Path -LiteralPath $uninstall_key_wow64) {
$metadata.installed = $true
$uninstall_key = $uninstall_key_wow64
}

# if the reg key exists, try and get the uninstall string and check if it is an MSI
if ($metadata.installed -eq $true -and $metadata.location_type -eq [LocationType]::Empty) {
if (Test-RegistryProperty -path $uninstall_key -name "UninstallString") {
$metadata.uninstall_string = (Get-ItemProperty -Path $uninstall_key -Name "UninstallString").UninstallString
$metadata.uninstall_string = (Get-ItemProperty -LiteralPath $uninstall_key -Name "UninstallString").UninstallString
if ($metadata.uninstall_string.StartsWith("MsiExec")) {
$metadata.msi = $true
}
Expand All @@ -250,11 +250,11 @@ Function Get-ProgramMetadata($state, $path, $product_id, [PSCredential]$credenti

# use the creates_* to determine if the program is installed
if ($null -ne $creates_path) {
$path_exists = Test-Path -Path $creates_path
$path_exists = Test-Path -LiteralPath $creates_path
$metadata.installed = $path_exists

if ($null -ne $creates_version -and $path_exists -eq $true) {
if (Test-Path -Path $creates_path -PathType Leaf) {
if (Test-Path -LiteralPath $creates_path -PathType Leaf) {
$existing_version = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($creates_path).FileVersion
$version_matched = $creates_version -eq $existing_version
$metadata.installed = $version_matched
Expand Down Expand Up @@ -363,7 +363,7 @@ if ($state -eq "absent") {
Fail-Json -obj $result -message "failed to run uninstall process ($($command_args['command'])): $($_.Exception.Message)"
}

if (($null -ne $log_path) -and (Test-Path -Path $log_path)) {
if (($null -ne $log_path) -and (Test-Path -LiteralPath $log_path)) {
$log_content = Get-Content -Path $log_path | Out-String
} else {
$log_content = $null
Expand All @@ -388,7 +388,7 @@ if ($state -eq "absent") {
} finally {
# make sure we cleanup any remaining artifacts
foreach ($cleanup_artifact in $cleanup_artifacts) {
if (Test-Path -Path $cleanup_artifact) {
if (Test-Path -LiteralPath $cleanup_artifact) {
Remove-Item -Path $cleanup_artifact -Recurse -Force -WhatIf:$check_mode
}
}
Expand Down Expand Up @@ -451,7 +451,7 @@ if ($state -eq "absent") {
Fail-Json -obj $result -message "failed to run install process ($($command_args['command'])): $($_.Exception.Message)"
}

if (($null -ne $log_path) -and (Test-Path -Path $log_path)) {
if (($null -ne $log_path) -and (Test-Path -LiteralPath $log_path)) {
$log_content = Get-Content -Path $log_path | Out-String
} else {
$log_content = $null
Expand All @@ -476,7 +476,7 @@ if ($state -eq "absent") {
} finally {
# make sure we cleanup any remaining artifacts
foreach ($cleanup_artifact in $cleanup_artifacts) {
if (Test-Path -Path $cleanup_artifact) {
if (Test-Path -LiteralPath $cleanup_artifact) {
Remove-Item -Path $cleanup_artifact -Recurse -Force -WhatIf:$check_mode
}
}
Expand Down

0 comments on commit 153a322

Please sign in to comment.