-
Notifications
You must be signed in to change notification settings - Fork 905
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
Add Uninstall-ChocolateyPath
function to manage removing entries from PATH
#310
Comments
Yep, we had something logged somewhere for these. |
Wanna open it up for grab? |
@tirolo done. |
Just for an idea, wouldn't it be nice if the auto-uninstaller would be able to take care of this as well? Either snapshot the environment before and after the install (or only PATH environment variable) or have Install-Chocolatey log something for the uninstall |
Sounds nice - keep in mind it should only remove the added values and not |
Will start working on this one as soon as I get my read around the docs I have to read before start contributing + learn some github 😄 (shouldn't take long) |
@ferventcoder Should I target master? |
@tirolo master is set for 0.9.11.x, and stable is set for 0.9.10.x. I'd target stable if you can. |
There was a PR for this in the old chocolatey repo chocolatey-archive/chocolatey#542 |
Not sure if it's still relevant, but here is a link to the code I put together for this today. The code I did also handles removing duplicates (if the path to remove is in more than once), handles the path whether or not there is a trailing slash versus what is specified on the removal string and it handles removing extra ";' that are found. The code is not generalized to handle both user and machine path. https://github.com/DarwinJS/ChocoPackages/blob/master/ec2clitools/tools/chocolateyuninstall.ps1 |
This is related to #303 |
I'll take this one. |
I am wondering a few things about this code: Hmmm - what if it could take params "user", "machine" and "all" ? Should it default to "All" if unspecified or just always require the param? |
PR: #1019 |
Finally added Uninstall-ChocolateyPath. However, given overall contribution rates to the powershell functions are quite low, the decision has been made to rewrite our helper functions into C# cmdlets. This serves as the initial set of cmdlets, a handful of useful example cases to prove out the viability of this approach, as well as ensuring that we have a better path forward for both OSS commands and any licensed commands we want to use in the future. It also opens up the possibility of more easily overriding the OSS cmdlets with a licensed command, and there are provisions in the `chocolateyInstaller.psm1` module script to ensure that can work seamlessly. Summary of changes: - Added Uninstall-ChocolateyPath helper cmdlet - Rewrote the following associated functions into C# cmdlets: - Get-EnvironmentVariable - Get-EnvironmentVariableNames - Install-ChocolateyPath - Set-EnvironmentVariable - Test-ProcessAdminRights - Update-SessionEnvironment - Tweaked the PowerShell command lookup behaviour when loading the `chocolateyInstaller.psm1` module to ensure that licensed cmdlets can be preferentially used instead of open-source cmdlets or functions, regardless of any name collisions that may occur. - Tweaked the assembly resolver to ensure that if we have the licensed extension depend on the new Chocolatey.PowerShell assembly, it will not cause any issues when trying to load the licensed extension outside the PowerShell module context.
- Added an `update-cmdlet-documentation.ps1` script which will use PlatyPS to read the cmdlet metadata and keep documentation up to date. - Provides a `-NewCommand` switch to allow easier additions of documentation pages for any new cmdlets (PlatyPS does not add newly added commands by default). - This script directly adds or updates documentation in a local copy of the chocolatey/docs repository, and compiles an XML help file from the resulting content.
Finally added Uninstall-ChocolateyPath. However, given overall contribution rates to the powershell functions are quite low, the decision has been made to rewrite our helper functions into C# cmdlets. This serves as the initial set of cmdlets, a handful of useful example cases to prove out the viability of this approach, as well as ensuring that we have a better path forward for both OSS commands and any licensed commands we want to use in the future. It also opens up the possibility of more easily overriding the OSS cmdlets with a licensed command, and there are provisions in the `chocolateyInstaller.psm1` module script to ensure that can work seamlessly. Summary of changes: - Added Uninstall-ChocolateyPath helper cmdlet - Rewrote the following associated functions into C# cmdlets: - Get-EnvironmentVariable - Get-EnvironmentVariableNames - Install-ChocolateyPath - Set-EnvironmentVariable - Test-ProcessAdminRights - Update-SessionEnvironment - Tweaked the PowerShell command lookup behaviour when loading the `chocolateyInstaller.psm1` module to ensure that licensed cmdlets can be preferentially used instead of open-source cmdlets or functions, regardless of any name collisions that may occur. - Tweaked the assembly resolver to ensure that if we have the licensed extension depend on the new Chocolatey.PowerShell assembly, it will not cause any issues when trying to load the licensed extension outside the PowerShell module context.
- Added an `update-cmdlet-documentation.ps1` script which will use PlatyPS to read the cmdlet metadata and keep documentation up to date. - Provides a `-NewCommand` switch to allow easier additions of documentation pages for any new cmdlets (PlatyPS does not add newly added commands by default). - This script directly adds or updates documentation in a local copy of the chocolatey/docs repository, and compiles an XML help file from the resulting content.
- Only return environment variable names that have an associated value from Get-EnvironmentVariableNames - When calling Update-SessionEnvironment, don't call SetVariable if the value at the queried scope is null.
During testing, it was found that the Location property of the Assembly was an entry string, therefore the cmdlets weren't being loaded. This commit attempts to address this by first checking the Location property, and if it is there, use it. Otherwise, fall back to the previous direct Import-Module against the $licensedAssembly. Will schedule a call with Rain to discuss this further once they are back from holiday.
During testing, it was found that the Chocolatey Profile was not being correctly loaded, with neither Update-SessionEnvironment nor refreshenv working as expected. This commit changes the profile loading to explicitly set the alas for refreshenv, and also to load Update-SessionEnvironment as a Cmdlet, rather than a Funcation. This is needed since it is now written in C# rather than PowerShell.
Uninstall-ChocolateyPath
function to manage removing entries from PATH
Previous changes for this issue had issues loading in powershell v2, this fixes those to the extent it's possible to do so.
Fix up Set-EnvironmentVariable and Update-SessionEnvironment tests.
We noticed over the last few days that the previous version of this code was *adding* blank values into the registry, which caused some issues with how environment variables are applied to new processes. Specifically, if a Machine-level variable is set, and a User-level variable by the same name is set to a blank value, new processes do not properly inherit the Machine-level value and it remains blank/unset. This change ensures that if someone sets an environment variable to a blank value, it will be properly *deleted* rather than set to a blank value. Additionally, a minor change has been made to Update-SessionEnvironment to ensure that if there are somehow blank values in the registry, it can sidestep those issues if it is called.
Previous changes for this issue had issues loading in powershell v2, this fixes those to the extent it's possible to do so.
Fix up Set-EnvironmentVariable and Update-SessionEnvironment tests.
We noticed over the last few days that the previous version of this code was *adding* blank values into the registry, which caused some issues with how environment variables are applied to new processes. Specifically, if a Machine-level variable is set, and a User-level variable by the same name is set to a blank value, new processes do not properly inherit the Machine-level value and it remains blank/unset. This change ensures that if someone sets an environment variable to a blank value, it will be properly *deleted* rather than set to a blank value. Additionally, a minor change has been made to Update-SessionEnvironment to ensure that if there are somehow blank values in the registry, it can sidestep those issues if it is called.
* release/2.3.0: (153 commits) (#23) Move call to SetRemotePackageNamesIfAllSpecified (#1901) Revert commit to display location (maint) Update Authenticode Signature (tests) Some minor tweaks for test consistency (#310) Set-EnvironmentVariable: delete values properly (tests) Remove v2 import tests (#310) Fix test issues (#310) Fixup v2 compatibility (tests) Working on tests during pairing session (#2050) Add Pester test for --ignore-pinned option (#3381) Add Pester tests for rule command (#1144) Add Pester test to cover hash validation (#72) Add Pester tests to cover new functionality (test) Update assertions for push commands (#1310) Add Pester test to validate output (#23) Add tests to handle install all (#2200) Add test for new enhanced exit code (#1764) Add test for new enhanced exit code (#1760) Add test for new enhanced exit code (#1759) Add test for new enhanced exit code ...
When progressing the release of 2.3.0, it was found that the chocolatey.lib nupkg didn't contain any files. This was due to a change in the folder structure which wasn't caught during testing. This commit fixes this folder structure, pointing directly to the chocolatey.lib folder, so that running nuget pack works as expected. There may be additional changes required to this portion of the build, to make sure that everything is being created in the same way, but that can be picked up post release/
🎉 This issue has been resolved in version 2.3.0 🎉 The release is available on: Your GitReleaseManager bot 📦 🚀 |
* master: (37 commits) (#310) Fix path to chocolatey.lib files (maint) Corrected casing of file (#23) Move call to SetRemotePackageNamesIfAllSpecified (#1901) Revert commit to display location (maint) Update Authenticode Signature (tests) Some minor tweaks for test consistency (#310) Set-EnvironmentVariable: delete values properly (tests) Remove v2 import tests (#310) Fix test issues (#310) Fixup v2 compatibility (tests) Working on tests during pairing session (#2050) Add Pester test for --ignore-pinned option (#3381) Add Pester tests for rule command (#1144) Add Pester test to cover hash validation (#72) Add Pester tests to cover new functionality (test) Update assertions for push commands (#1310) Add Pester test to validate output (#23) Add tests to handle install all (#2200) Add test for new enhanced exit code (#1764) Add test for new enhanced exit code ...
…evelop * 'develop' of https://github.com/josh-cooley/choco: (145 commits) (maint) Add CODEOWNERS files (build) Add templated notifications to all builds (build) Add verification of source scripts (doc) Further tweak docgen for Chocolatey.PowerShell (doc) Tweak docgen for Chocolatey.PowerShell (chocolatey#3446) Update GenerateDocs.ps1 (chocolatey#3307) Do not create Tools directory from MSI (maint) Do not create Chocolatey directory in MSI (chocolatey#310) Fix path to chocolatey.lib files (maint) Corrected casing of file (chocolatey#23) Move call to SetRemotePackageNamesIfAllSpecified (chocolatey#1901) Revert commit to display location (maint) Update Authenticode Signature (tests) Some minor tweaks for test consistency (chocolatey#310) Set-EnvironmentVariable: delete values properly (tests) Remove v2 import tests (chocolatey#310) Fix test issues (chocolatey#310) Fixup v2 compatibility (tests) Working on tests during pairing session (chocolatey#2050) Add Pester test for --ignore-pinned option ...
There is a useful helper Install-ChocolateyPath which I use to add directories to the PATH variable. I would like to see an Uninstall-ChocolateyPath as well to cleanup those directories from the PATH variable at uninstall time.
I guess this would apply to quite a few other helpers which only have an "Install" part.
The text was updated successfully, but these errors were encountered: