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

(#1015) Path exists check retains path scope specified by user, adds semi-colon to end of path #1017

Closed
wants to merge 1 commit into from

Conversation

DarwinJS
Copy link
Contributor

@DarwinJS DarwinJS commented Oct 15, 2016

(GH 1015) Path exists check retains path scope specified by user, adds semi-colon to end of path

Also path exists check finds path whether or not trailing slash matches requested path, added alias 'path' for 'pathtoinstall' to align with powershell parameter naming, used chocolatey method Update-SessionEnvironment instead of simple path concetanation.

#1015

@DarwinJS
Copy link
Contributor Author

DarwinJS commented Oct 15, 2016

Looking for feedback on the following possible additional changes:

  • Thinking I should also change "write-host" to best practice "write-output" - however, I'm not sure if that has implications due to the fact chocolatey hosts powershell by default?
  • New scope option 'All' for adding path to both User and Machine
  • Check if path is in other scope and log that fact
  • Give a warning that paths added to User scope will ONLY be available to that user and not the System, services nor other users - especially since scope defaults to 'User'

Also path exists check finds path whether or not trailing slash matches requested path, added alias 'path' for 'pathtoinstall' to align with powershell parameter naming, used chocolatey method Update-SessionEnvironment instead of simple path concetanation.
Implements a couple aliases.
#array drops blanks (one of which is always created by final semi-colon)
$actualPathArray = (Get-EnvironmentVariable -Name 'Path' -Scope $pathType -PreserveVariables).split(';',[System.StringSplitOptions]::RemoveEmptyEntries)
#checks for match with and without trailing slash
if (($actualpathArray -inotcontains $pathToInstall.ToLower()) -AND ($actualpathArray -inotcontains "$(($pathToInstall + '\').ToLower())"))
Copy link

Choose a reason for hiding this comment

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

$actualpathArray is compared with lower case version of $pathToInstall. Where $actualpathArray is converted to lower case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The "i" in "-inotcontains" causes the entire comparison operation to be "case Insensitive". Technically this make "ToLower()" redundant.

Copy link

Choose a reason for hiding this comment

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

Oh, it makes sense. I am not very good at PS and was deceived by ToLower().

@dragon788
Copy link
Contributor

@DarwinJS I think from talking with @ferventcoder about this on Gitter Write-Host is best because it avoids major pitfalls of Write-Output's behavior, if you have Write-Output inside a function it automatically forces itself into the return value. There is a new Write-Information, but that is a PS5 only function iirc.

@DarwinJS
Copy link
Contributor Author

Trying to understand why this isn't getting merged?

@ferventcoder
Copy link
Member

Apologies @DarwinJS - this change wasn't under vNext, so it didn't get in for 0.10.4 - 0.10.5 was a bug fix release for a gating issue in 0.10.4. 0.10.6 is fixing an issue that came in from a change to how xml files are saved.

It will make it in, and I did take a look and notice it may change the current behavior of looking at the entire path (breaking change), even if that is technically the right thing to do, and realized this changes a lot of code so it requires more scrutiny. Since it wasn't technically scheduled for the next release, it did not get merged. If we can agree that this is more of an annoyance than a critical fix - it may add an item to path twice, but it won't necessarily stop choco from working. HTH

@DarwinJS
Copy link
Contributor Author

@ferventcoder - no need to apologize - I am just trying to understand.
Is the same true of #1019 ?

@jedfrechette
Copy link

Has there been any progress on getting this merged?

I just ran in to the issue described in #1015, where the Machine PATH was silently not getting updated because the path I was trying to add already existed on the User PATH. I never would have guessed what the problem was without finding that bug.

@CLAassistant
Copy link

CLAassistant commented Jun 8, 2020

CLA assistant check
All committers have signed the CLA.

@gep13 gep13 changed the title (GH 1015) Path exists check retains path scope specified by user, adds semi-colon to end of path (#1015) Path exists check retains path scope specified by user, adds semi-colon to end of path Oct 15, 2021
@gep13 gep13 linked an issue Oct 15, 2021 that may be closed by this pull request
@vexx32
Copy link
Member

vexx32 commented Sep 18, 2024

Thanks for the contribution here, and apologies that this was not reviewed for a long while.

This has been resolved during the rewrite of this command to C# which shipped in 2.3.0 and the issue this seeks to resolve is no longer present; see here: #1015 (comment)

As such, I'll be closing this PR, but thank you for the contribution nonetheless! 💜

@vexx32 vexx32 closed this Sep 18, 2024
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.

Possible bug in Install-ChocolateyPath.ps1
7 participants