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

Ensure Install-ChocolateyPath adds a new entry to the PATH when part of it is already there #3318

Closed
5 tasks done
knappmk opened this issue Sep 8, 2023 · 1 comment · Fixed by #3440
Closed
5 tasks done
Assignees
Milestone

Comments

@knappmk
Copy link

knappmk commented Sep 8, 2023

Checklist

  • I have verified this is the correct repository for opening this issue.
  • I have verified no other issues exist related to my problem.
  • I have verified this is not an issue for a specific package.
  • I have verified this issue is not security related.
  • I confirm I am using official, and not unofficial, or modified, Chocolatey products.

What You Are Seeing?

I create my own internal Chocolatey packages. In the install script I have to use the command Install-ChocolateyPath. Thereby I want to have multiple folders of a program added to the PATH environment variable (here: "C:\tools\msys2\usr\bin" and "C:\tools\msys2"). But if "C:\tools\msys2\usr\bin" is already present in the PATH variable and "C:\tools\msys2" is not present (e.g. during an upgrade), then Install-ChocolateyPath does not add the path anymore.
It is not an environment update problem, because no change has taken place in the registry and the output of the command confirms this (see log). The cause of the error is in the condition that checks whether the path already exists in the PATH variable or not.

if (!$envPath.ToLower().Contains($pathToInstall.ToLower())) {

What is Expected?

The path should be taken over into the PATH variable, even if a subpath of this path already exists in the variable. For this, it should be checked exactly whether the path is already included in the variable or not.

How Did You Get This To Happen?

  1. Pick a path (e.g. "C:\tools\msys2") and a subpath (e.g. "C:\tools\msys2\usr\bin").
  2. Make sure that a subpath of the path to be added already exists in the PATH variable (e.g. 'C:\tools\msys2\usr\bin')
  3. Call the command Install-ChocolateyPath "C:\tools\msys64\" -pathType "Machine".
  4. Check the PATH environment variable: the path should not have been added

System Details

  • Operating System: Windows 10.0.17763.0
  • Windows PowerShell version: 5.1.17763.4720
  • Chocolatey CLI Version: 1.3.0
  • Chocolatey Licensed Extension version: None
  • Chocolatey License type: Free
  • Terminal/Emulator: Windows PowerShell

Installed Packages

N/A

Output Log

Sorry no Chocolatey log here, as I have already narrowed down the problem and don't want to post any internal issues. Running the command does not show any output - normally it should say "PATH environment variable does not have C:\tools\msys64 in it. Adding..."

14:53 C:\Users\Administrator.VH12052\Desktop> $env:PATH
C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\ProgramData\chocolatey\bin;C:\tools\msys64\usr\bin;C:\Progra
m Files\Git\cmd;C:\Program Files\IcedTeaWeb\WebStart\bin;C:\Program Files\OpenJDK\jdk-13\bin;
14:53 C:\Users\Administrator.VH12052\Desktop> Install-ChocolateyPath "C:\tools\msys64" -pathType Machine
14:53 C:\Users\Administrator.VH12052\Desktop> $env:PATH
C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\ProgramData\chocolatey\bin;C:\tools\msys64\usr\bin;C:\Progra
m Files\Git\cmd;C:\Program Files\IcedTeaWeb\WebStart\bin;C:\Program Files\OpenJDK\jdk-13\bin;

Additional Context

I add a pull request that should fix the problem by matching the exact path to be added.

@knappmk knappmk added the Bug label Sep 8, 2023
@gep13 gep13 added this to the 2.3.0 milestone May 23, 2024
@vexx32 vexx32 self-assigned this May 23, 2024
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
@pauby pauby changed the title Install-ChocolateyPath does not add path if subpath already exists Ensure Install-ChocolateyPath adds a new entry to the PATH when part of it is already there May 28, 2024
@choco-bot
Copy link

🎉 This issue has been resolved in version 2.3.0 🎉

The release is available on:

Your GitReleaseManager bot 📦 🚀

vexx32 added a commit to vexx32/choco that referenced this issue Oct 25, 2024
Some cmdlets should support ShouldProcess, this change ensures that they
do correctly support it, along with adding checks to the underlying
methods to make it work as users will expect.

As Chocolatey CLI already supports --dry-run itself, this is primarily
going to be useful for effectively unit testing the commands.
vexx32 added a commit to vexx32/choco that referenced this issue Oct 25, 2024
Update-SessionEnvironment, Set-EnvironmentVariable, and
(Un)Install-ChocolateyPath implement ShouldProcess, so we can use
-WhatIf to verify their behaviour with unit tests.
vexx32 added a commit to vexx32/choco that referenced this issue Nov 1, 2024
Some cmdlets should support ShouldProcess, this change ensures that they
do correctly support it, along with adding checks to the underlying
methods to make it work as users will expect.

As Chocolatey CLI already supports --dry-run itself, this is primarily
going to be useful for effectively unit testing the commands.
vexx32 added a commit to vexx32/choco that referenced this issue Nov 1, 2024
Update-SessionEnvironment, Set-EnvironmentVariable, and
(Un)Install-ChocolateyPath implement ShouldProcess, so we can use
-WhatIf to verify their behaviour with unit tests.
corbob pushed a commit to vexx32/choco that referenced this issue Nov 4, 2024
Some cmdlets should support ShouldProcess, this change ensures that they
do correctly support it, along with adding checks to the underlying
methods to make it work as users will expect.

As Chocolatey CLI already supports --dry-run itself, this is primarily
going to be useful for effectively unit testing the commands.
corbob pushed a commit to vexx32/choco that referenced this issue Nov 4, 2024
Update-SessionEnvironment, Set-EnvironmentVariable, and
(Un)Install-ChocolateyPath implement ShouldProcess, so we can use
-WhatIf to verify their behaviour with unit tests.
corbob added a commit that referenced this issue Nov 4, 2024
(#3318) Add ShouldProcess support to rewritten helper cmdlets
vexx32 added a commit to vexx32/choco that referenced this issue Nov 7, 2024
A couple of small errors in the -WhatIf tests showed up on teamcity, so
this should hopefully fix those.
@vexx32 vexx32 mentioned this issue Nov 7, 2024
10 tasks
vexx32 added a commit to vexx32/choco that referenced this issue Nov 7, 2024
A couple of small errors in the -WhatIf tests showed up on teamcity, so
this should hopefully fix those.
vexx32 added a commit to vexx32/choco that referenced this issue Nov 7, 2024
A couple of small errors in the -WhatIf tests showed up on teamcity, so
this should hopefully fix those.
vexx32 added a commit to vexx32/choco that referenced this issue Nov 7, 2024
A couple of small errors in the -WhatIf tests showed up on teamcity, so
this should hopefully fix those.
corbob added a commit that referenced this issue Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants