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

FIX: Install-ChocolateyPath won't add a path that is a substring of a… #1275

Closed
wants to merge 2 commits into from
Closed

FIX: Install-ChocolateyPath won't add a path that is a substring of a… #1275

wants to merge 2 commits into from

Conversation

glachancecmaisonneuve
Copy link

@glachancecmaisonneuve glachancecmaisonneuve commented Apr 29, 2017

FIX: Install-ChocolateyPath won't add a path that is a substring of an existing path
FIX: Install-ChocolateyPath adds duplicate paths if the added path ends in a folder separator and the one already in the path does not.
New Feature: Check if path exists on disk before adding it. Default behavior is to ignore the install if the path doesnt exist. A Force parameter was added for weird cases where that would be desirable.
New Feature: Install-ChocolateyPath now understands cmd-type variables.

A complete pester test file is available. I didn't add it to the commit as I haven't seen any for powershell methods in the project.

…n existing path

New Feature: Check if path exists on disk before adding it.  Default behavior is to ignore the install if the path doesnt exist.  A Force parameter was added for weird cases where that would be desirable.

New Feature: Install-ChocolateyPath now understands cmd-type variables.

A complete pester test file is available.  I didnt add it to the commit as I haven't seen any for powershell methogs in the project.
@glachancecmaisonneuve
Copy link
Author

Test file is available here: aba1d04#diff-94c826cb9ab70d9c220a3d018358890f

@ferventcoder
Copy link
Member

I see the Pester file.

# Copyright © 2011 - 2015 RealDimensions Software, LLC & original authors/contributors from https://github.com/chocolatey/chocolatey
# Copyright 2017 Chocolatey Software, Inc.
# Copyright 2015 - 2017 RealDimensions Software, LLC
# Copyright 2011 - 2015 RealDimensions Software, LLC & original authors/contributors from https://github.com/chocolatey/chocolatey
Copy link
Member

Choose a reason for hiding this comment

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

It looks like you possibly changed line endings on this file. That will break it for authenticode signing.

Choose a reason for hiding this comment

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

Will fix. Thanks

[parameter(ValueFromRemainingArguments = $true)][Object[]] $ignoredArguments
)
Write-Debug "Running 'Install-ChocolateyPath' with pathToInstall:`'$pathToInstall`'";
$originalPathToInstall = $pathToInstall
Set-StrictMode -Version 2
Copy link
Member

Choose a reason for hiding this comment

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

This won't work. On PowerShell 4/5 systems, you have to install the v2 engine so that you can do this. This breaks those systems.

Choose a reason for hiding this comment

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

Will remove. Thanks

Choose a reason for hiding this comment

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

@ferventcoder In what circumstances exactly did you encounter problems with that? I run scripts containing

#Requires -Version 2
Set-StrictMode -Version 2

on Windows 10 1511 and 1607 systems and on Server 2012 R2 with both .NET 2.0 and PowerShell 2.0 removed and no issues occur. The docs for Set-StrictMode and #Requires imply that the number is interpreted as a minimum, not an exact version.

Copy link
Member

Choose a reason for hiding this comment

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

@jberezanski remove the PowerShell v2 engine feature and #Requires -Version 2 fails. I've seen it before. Would love for the minimum to be true, but have not seen it implemented in that way.

Choose a reason for hiding this comment

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

(The line of code in question was Set-StrictMode, not #Requires, but the behavior should be the same for both constructs.)
On what systems exactly have you seen that? I'm asking because, as I wrote before, this works as expected on all machines I have access to.
Besides, two widespread Chocolatey extensions (chocolatey-windowsupdate.extension and chocolatey-visualstudio.extension) use it and there has not been a single issue reported.

Or perhaps you were thinking about executing powershell.exe -version 2? This is asking specifically for the 2.0 engine, so naturally it fails if that engine is not available.

Copy link
Member

@ferventcoder ferventcoder left a comment

Choose a reason for hiding this comment

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

I highly appreciate these changes. Perhaps you can review some of the notes I've left here and provide fixes. Have you had an opportunity to review our CONTRIBUTING documentation? It's pretty helpful and can save you lots of review fixes - https://github.com/chocolatey/choco/blob/master/CONTRIBUTING.md

@@ -0,0 +1,126 @@
. $PSScriptRoot\Install-ChocolateyPath.ps1
Copy link
Member

Choose a reason for hiding this comment

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

This file is in a non-good location. If we are going to introduce Pester tests again (or I should say when we do, as they are in the original chocolatey/chocolatey), they need to be in a test project directory.

Choose a reason for hiding this comment

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

Where do you suggest I create/put the pester file?

$newPath = $pathToInstall + [System.IO.Path]::PathSeparator + (Get-EnvironmentVariable -Name 'Path' -Scope $pathType)

Set-EnvironmentVariable -Name 'PATH' -Value $newPath -Scope $pathType
Update-SessionEnvironment
Copy link
Member

Choose a reason for hiding this comment

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

This is already a PR up for this particular file and this appears to be repeating some of what is being handled there. You may wish to review some of their changes as well in this area.

Choose a reason for hiding this comment

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

The PR in waiting (327) should be closed. ctaggart said he is unable to continue the PR (#327 (comment))

Copy link
Member

Choose a reason for hiding this comment

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

I don't believe that was the one I was talking about.

@glachancecmaisonneuve
Copy link
Author

glachancecmaisonneuve commented May 4, 2017

It may look like come of the code is a "styling-rewrite" but the changes were made so the module could be pester-able. This means no more direct access to environment variables to allow mocking those calls. Also, the logic was hard to implement making minimal changes to the existing code... hence the rewrite.

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.

3 participants