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

Add Uninstall-ChocolateyPath function to manage removing entries from PATH #310

Closed
mrdima opened this issue Jun 5, 2015 · 28 comments · Fixed by #3440
Closed

Add Uninstall-ChocolateyPath function to manage removing entries from PATH #310

mrdima opened this issue Jun 5, 2015 · 28 comments · Fixed by #3440
Assignees
Milestone

Comments

@mrdima
Copy link

mrdima commented Jun 5, 2015

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.

@ferventcoder ferventcoder added this to the 0.9.10.x milestone Jun 5, 2015
@ferventcoder
Copy link
Member

Yep, we had something logged somewhere for these.

@tirolo
Copy link
Contributor

tirolo commented Nov 25, 2015

Wanna open it up for grab?

@ferventcoder
Copy link
Member

@tirolo done.

@mrdima
Copy link
Author

mrdima commented Nov 25, 2015

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

@ferventcoder
Copy link
Member

ferventcoder commented Nov 25, 2015

Sounds nice - keep in mind it should only remove the added values and not
restore the previous version (that would be bad).

@tirolo
Copy link
Contributor

tirolo commented Nov 26, 2015

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)

@tirolo
Copy link
Contributor

tirolo commented Nov 26, 2015

@ferventcoder Should I target master?

@ferventcoder
Copy link
Member

@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.

@sindux
Copy link

sindux commented Jan 1, 2016

There was a PR for this in the old chocolatey repo chocolatey-archive/chocolatey#542

@ferventcoder
Copy link
Member

Moving discussion back over to here, @DarwinJS See - #303

@DarwinJS
Copy link
Contributor

DarwinJS commented Jan 8, 2016

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

@ferventcoder
Copy link
Member

This is related to #303

@DarwinJS
Copy link
Contributor

I'll take this one.

@DarwinJS
Copy link
Contributor

I am wondering a few things about this code:
*) Does it make sense to remove the requested string from both user and computer path? On one hand if I was requesting a removal I would just want it gone no matter what paths it appeared on if the software was just removed. On the other hand it may make uninstalls reach to things that weren't instended.

Hmmm - what if it could take params "user", "machine" and "all" ? Should it default to "All" if unspecified or just always require the param?

@DarwinJS
Copy link
Contributor

PR: #1019

@gep13 gep13 modified the milestones: Future, 2.3.0 May 23, 2024
vexx32 added a commit to vexx32/choco that referenced this issue May 23, 2024
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.
vexx32 added a commit to vexx32/choco that referenced this issue May 23, 2024
vexx32 added a commit to vexx32/choco that referenced this issue May 23, 2024
- 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.
gep13 pushed a commit to vexx32/choco that referenced this issue May 24, 2024
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.
gep13 pushed a commit to vexx32/choco that referenced this issue May 24, 2024
gep13 pushed a commit to vexx32/choco that referenced this issue May 24, 2024
- 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.
gep13 added a commit that referenced this issue May 24, 2024
(#310, #3318) Add Uninstall-ChocolateyPath cmdlet & rewrite associated functions as cmdlets
@gep13 gep13 added 4 - Done and removed 3 - Review labels May 24, 2024
vexx32 added a commit to vexx32/choco that referenced this issue May 24, 2024
- 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.
gep13 added a commit that referenced this issue May 27, 2024
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.
gep13 added a commit that referenced this issue May 27, 2024
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.
@pauby pauby changed the title Add PowerShell helper function to manage removing paths from $PATH Add Uninstall-ChocolateyPath function to manage removing entries from PATH May 28, 2024
vexx32 added a commit to gep13/choco that referenced this issue May 30, 2024
Previous changes for this issue had issues loading in powershell v2,
this fixes those to the extent it's possible to do so.
vexx32 added a commit to gep13/choco that referenced this issue May 30, 2024
Fix up Set-EnvironmentVariable and Update-SessionEnvironment tests.
vexx32 added a commit to gep13/choco that referenced this issue May 30, 2024
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.
gep13 pushed a commit to gep13/choco that referenced this issue May 30, 2024
Previous changes for this issue had issues loading in powershell v2,
this fixes those to the extent it's possible to do so.
gep13 pushed a commit to gep13/choco that referenced this issue May 30, 2024
Fix up Set-EnvironmentVariable and Update-SessionEnvironment tests.
gep13 pushed a commit to gep13/choco that referenced this issue May 30, 2024
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.
gep13 added a commit that referenced this issue Jun 5, 2024
* 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
  ...
gep13 added a commit that referenced this issue Jun 5, 2024
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/
@choco-bot
Copy link

🎉 This issue has been resolved in version 2.3.0 🎉

The release is available on:

Your GitReleaseManager bot 📦 🚀

gep13 added a commit that referenced this issue Jun 5, 2024
* 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
  ...
josh-cooley added a commit to josh-cooley/choco that referenced this issue Jul 8, 2024
…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
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment