Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(MODULES-7580) Fix PowerShell task for puppet version on 32bit #309

Merged
merged 1 commit into from
Aug 7, 2018

Conversation

glennsarti
Copy link
Contributor

@glennsarti glennsarti commented Aug 3, 2018

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

@glennsarti glennsarti force-pushed the modules-7580-powershell branch from c6708e4 to 65cf3f5 Compare August 3, 2018 02:57
@glennsarti
Copy link
Contributor Author

Tested manually on Windows 10 32bit, 64bit and 2008R2 64bit.

@puppetcla
Copy link

CLA signed by all contributors.

if ($loc -ne $null) {
Write-Output "{`"version`":`"$(type $loc)`",`"source`":`"$($loc.replace('\', '/'))`"}"
if ($null -ne $loc) {
Write-Output "{`"version`":`"$(Get-Content -Path $loc -ErrorAction SilentlyContinue)`",`"source`":`"$($loc.replace('\', '/'))`"}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-ErrorAction SilentlyContinue will result in an empty version if reading the file fails for some reason (permissions?). I'm not sure that's what we want... if the file is present but we can't read it, we may want to fail the task.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. Can just read it first before write-Output


$reg = Get-ItemProperty -Path $rootPath -ErrorAction SilentlyContinue
if ($null -ne $reg) {
if ($null -ne $reg.RememberedInstallDir64) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we only want to set $loc if the path exists, can we also Test-Path? If the registry entry is there but the file isn't, I interpret that as the package is not installed (but registry cleanup didn't succeed for some reason).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could add that in Line 12

if ( ($null -ne $loc) -and (Test-Path -Path $loc) ) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you going to follow up on these changes, or would you like me to take over the PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to take over. Just busy with other tasks first.

@donoghuc donoghuc force-pushed the modules-7580-powershell branch from 65cf3f5 to 1504c52 Compare August 7, 2018 15:53
@puppetcla
Copy link

CLA signed by all contributors.

@MikaelSmith
Copy link
Contributor

Ready for a rebase.

@donoghuc donoghuc force-pushed the modules-7580-powershell branch from 1504c52 to 693f85a Compare August 7, 2018 17:53
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`
@donoghuc donoghuc force-pushed the modules-7580-powershell branch from 693f85a to 984dadd Compare August 7, 2018 17:58
@MikaelSmith MikaelSmith merged commit 41eeccb into puppetlabs:master Aug 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants