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

Uninstall template fails when encountering "bad" registry keys #739

Closed
dtgm opened this issue May 18, 2016 · 17 comments
Closed

Uninstall template fails when encountering "bad" registry keys #739

dtgm opened this issue May 18, 2016 · 17 comments

Comments

@dtgm
Copy link
Contributor

dtgm commented May 18, 2016

[array]$key = Get-ItemProperty -Path @($machine_key6432,$machine_key, $local_key) `
-ErrorAction SilentlyContinue `
| ? { $_.DisplayName -like ""$softwareName"" }

[array]$key = Get-ItemProperty -Path @($machine_key6432,$machine_key, $local_key) `
                        -ErrorAction SilentlyContinue `
         | ? { $_.DisplayName -like ""$softwareName"" }

This code will fail if a registry key exists that was written with binary data and incorrectly typed. [array]$key does not resolve issue as Get-ItemProperty will fail before set to variable.

For more details, see dtgm/chocolatey-packages#92 (comment)

@ferventcoder
Copy link
Member

What is the proposed solution to this issue? I do think making the template more bulletproof would be helpful.

@ferventcoder ferventcoder added this to the 0.9.10 milestone May 18, 2016
@ferventcoder ferventcoder self-assigned this May 18, 2016
@dtgm
Copy link
Contributor Author

dtgm commented May 18, 2016

This is what I came up with chocolatey-community/chocolatey-packages@f7fe281#diff-1213b3569e3787f648fc1ae040fd00d4

I was thinking of distributing the fix as an extension to keep chocolateyUninstall.ps1 files less complicated as noted at chocolatey-community/chocolatey-packages#214

@dtgm
Copy link
Contributor Author

dtgm commented May 18, 2016

So these lines in the template would be replaced with

[array]$key = Get-UninstallRegistryKey -SoftwareName $softwareName

And the package would also have to include in the nuspec:

<dependencies>
  <dependency id="chocolatey-uninstall.extension" />
</dependencies>

dtgm added a commit to dtgm/choco that referenced this issue May 18, 2016
Templates are set to use the chocolatey-uninstall.extension helper by default.
The helper includes a catch for invalid registry keys. Using the catch is a
requirement as blindly enumerating will fail every time if even one invalid key
exists.
@dtgm
Copy link
Contributor Author

dtgm commented May 21, 2016

I am looking at adding <dependency id="chocolatey-uninstall.extension" /> to about 500 of my pkgs. And it should be applied to another 500 pkgs in the wild, if not more. Due to the scope of packages this applies to I am reconsidering my proposed solution of having to add the extension to each package. The other options are:

  1. Add the extension function as an internal helper. And it looks like some effort has went into this direction already Helper for retrieving installed applications list #396
  2. Adding the extension as a dependency to chocolatey package? This would allow not having to have >50% of packages having the same dependency. Also it eases managing the helpers by keeping development outside of chocolatey program.
  3. Keep as is, requiring each package using the helpers to include as a dep. Some downsides:
  • If many pkgs with this dep are installed, the dep would be checked repeatedly. This would slow choco down a bit until local indexes are developed.
  • It would require lots of maintainers to have to add that dependency code to their nuspec file; just one more thing to do. I don't consider this a problem for me as I already wrote the script to add the dep to my nuspecs.

Thoughts? Are there any clear guidelines or recommendations of when helpers should be extensions or internal helpers? Is the compromise of adding a dependency to the chocolatey package a horrible idea for a reason I overlooked?

dtgm added a commit to dtgm/choco that referenced this issue May 22, 2016
…ve registry key

Templates are set to use the chocolatey-uninstall.extension helper by default.
The helper includes a catch for invalid registry keys. Using the catch is a
requirement as blindly enumerating will fail every time if even one invalid key
exists.
@ferventcoder
Copy link
Member

2 Adding the extension as a dependency to chocolatey package?

Chocolatey has no dependencies, it would just include the helper as part of its framework.

@dtgm
Copy link
Contributor Author

dtgm commented May 23, 2016

Right, I was imagining if you ignore everything a "dependency" is for a sec :), it would allow distributing the extension without including it as an internal helper for management outside of chocolatey codebase. Which might be better(?)

When should a helper be external or internal?

@ferventcoder
Copy link
Member

@dtgm I tend to think of it as a both argument - you load up the extension and only make it live if the built-in function isn't there (or if it is a known broken version).

@ferventcoder
Copy link
Member

And we are starting to get into the reasons I have been hesitant to document the extensions feature.

It's super powerful, but also makes it extremely easy to cut yourself with.

@dtgm
Copy link
Contributor Author

dtgm commented May 23, 2016

I'm thinking more of the performance impact of including it in many packages as a dep and the many redundant checks for an updated version. How significant is that?

@ferventcoder
Copy link
Member

Included without a version dependency, there is no check IIRC. Please check for sure though.

It would just upgrade as part of cup all (or specific upgrade).

@ferventcoder
Copy link
Member

I could be totally wrong about versionless dependencies

@dtgm
Copy link
Contributor Author

dtgm commented May 23, 2016

As a basepoint, installing an empty package working from $pwd, if extension dep is included, it adds 0.2 - 0.3 ms to install when dep is already installed. Which is about 1.5x longer than no dependency. So scaling up for 200 pkgs installed using this dep would take cumulatively, 1 min longer.

Summary
measure-command {choco install test-pkg -s "$pwd" -y}
~350 ms -- no dep
~550 ms -- with dep, dep not installed
~850 ms -- with dep, dep already installed

@dtgm
Copy link
Contributor Author

dtgm commented May 23, 2016

test-pkg uninstalled between tests. Times didn't deviate much between tests.

@ferventcoder
Copy link
Member

Also subject to issues with chocolatey-community/chocolatey-packages#222

ferventcoder pushed a commit that referenced this issue Jun 12, 2016
Add Get-UninstallRegistryKey function to provide a means of getting
uninstaller registry keys that does not fail with incorrectly
encoded keys and values.

Update the code documentation to link update the function with other
similar functions and generate updated documentation

Add the function to the uninstall template and nuspec with
instructions to use the chocolatey-uninstall.extension package when
supporting 0.9.9.x and below as the new function will only be
available in 0.9.10 and above.

The helper includes a trycatch for invalid registry keys. Using the
catch is a requirement as blindly enumerating will fail every time
if even one invalid key exists.
ferventcoder added a commit that referenced this issue Jun 12, 2016
* pr743:
  (maint) Convert function to UTF-8
  (GH-739) Get-UninstallRegistryKey / update templates
ferventcoder added a commit that referenced this issue Jun 12, 2016
* stable:
  (maint) Convert function to UTF-8
  (GH-739) Get-UninstallRegistryKey / update templates
  (maint) update logo location for nuspecs
@ferventcoder
Copy link
Member

Merged into stable at 91db949

@ferventcoder
Copy link
Member

@ferventcoder
Copy link
Member

Needs a small fixup, but 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants