Skip to content

Commit

Permalink
(MODULES-7580) Fix PowerShell task for puppet version on 32bit
Browse files Browse the repository at this point in the history
Previously the powershell based version task was failing on 32bit windows
operating systems due to passing in a null path to Test-Path.  This commit
modifies the detection to be far more tolerant of errors and instead detects if
the registry entries are null instead of using Test-Path.

This commit also cleans up the code as per PS Script Analyzer rules;
* Remove use of aliases
* Prefer `$null -eq ...` instead of `... -eq $null`
  • Loading branch information
glennsarti authored and donoghuc committed Aug 7, 2018
1 parent 32de120 commit 984dadd
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions tasks/version_powershell.ps1
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
if (Test-Path 'HKLM:\SOFTWARE\Puppet Labs\Puppet') {
$reg = $(Get-ItemProperty -Path 'HKLM:\SOFTWARE\Puppet Labs\Puppet')
if (Test-Path $reg.RememberedInstallDir64) {
$rootPath = 'HKLM:\SOFTWARE\Puppet Labs\Puppet'

$reg = Get-ItemProperty -Path $rootPath -ErrorAction SilentlyContinue
if ($null -ne $reg) {
if ($null -ne $reg.RememberedInstallDir64) {
$loc = $reg.RememberedInstallDir64+'VERSION'
} elseif (Test-Path $reg.RememberedInstallDir) {
} elseif ($null -ne $reg.RememberedInstallDir) {
$loc = $reg.RememberedInstallDir+'VERSION'
}
}

if ($loc -ne $null) {
Write-Output "{`"version`":`"$(type $loc)`",`"source`":`"$($loc.replace('\', '/'))`"}"
if ( ($null -ne $loc) -and (Test-Path -Path $loc) ) {
Write-Output "{`"version`":`"$(Get-Content -Path $loc -ErrorAction Stop)`",`"source`":`"$($loc.replace('\', '/'))`"}"
} else {
Write-Output '{"version":null,"source":null}'
}

0 comments on commit 984dadd

Please sign in to comment.