Skip to content
This repository was archived by the owner on Feb 19, 2019. It is now read-only.

Allowing ChocolateyInstall from System & Proc Env #135

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion chocolateyInstall/InstallChocolatey.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ $chocInstallPS1 = Join-Path $toolsFolder "chocolateyInstall.ps1"

write-host 'Ensuring chocolatey commands are on the path'
$chocInstallVariableName = "ChocolateyInstall"
$nuGetPath = [Environment]::GetEnvironmentVariable($chocInstallVariableName, [System.EnvironmentVariableTarget]::User)
$nuGetPath = [Environment]::GetEnvironmentVariable($chocInstallVariableName)
$nugetExePath = 'C:\NuGet\bin'
if ($nuGetPath -ne $null) {
$nugetExePath = Join-Path $nuGetPath 'bin'
Expand Down
30 changes: 18 additions & 12 deletions nuget/tools/chocolateysetup.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,23 @@ $sysDrive = $env:SystemDrive
$defaultChocolateyPathOld = "$sysDrive\NuGet"

function Set-ChocolateyInstallFolder($folder){
#if(test-path $folder){
write-host "Creating $chocInstallVariableName as a User Environment variable and setting it to `'$folder`'"
[Environment]::SetEnvironmentVariable($chocInstallVariableName, $folder, [System.EnvironmentVariableTarget]::User)
#}
#else{
# throw "Cannot set the chocolatey install folder. Folder not found [$folder]"
#}
$procVar = [Environment]::GetEnvironmentVariable($chocInstallVariableName, [System.EnvironmentVariableTarget]::Process)
$userVar = [Environment]::GetEnvironmentVariable($chocInstallVariableName, [System.EnvironmentVariableTarget]::User)

# Only the set the user variable if it came from proc doesn't match the current user var
# This allows a system var to be used, but a user var to override
#
if ( $procVar -ne $null ) {
if ($userVar -ne $folder) {
write-host "Creating $chocInstallVariableName as a User Environment variable and setting it to `'$folder`'"
[Environment]::SetEnvironmentVariable($chocInstallVariableName, $folder, [System.EnvironmentVariableTarget]::User)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

So when you are a regular user who has never installed before, how do you get the environment variable set? Am I misunderstanding that process environment variable will aways be set?

}
}

function Get-ChocolateyInstallFolder(){
[Environment]::GetEnvironmentVariable($chocInstallVariableName, [System.EnvironmentVariableTarget]::User)
function Get-ChocolateyInstallFolder {
# Use the chocInstallVar from any environment: sys, usr, proc
[Environment]::GetEnvironmentVariable($chocInstallVariableName)
}

function Create-DirectoryIfNotExists($folderName){
Expand Down Expand Up @@ -139,9 +145,9 @@ param(
if($alreadyInitializedNugetPath -and $alreadyInitializedNugetPath -ne $chocolateyPath -and $alreadyInitializedNugetPath -ne $defaultChocolateyPathOld){
$chocolateyPath = $alreadyInitializedNugetPath
}
else {
Set-ChocolateyInstallFolder $chocolateyPath
}

# Always set the path in case its coming from process
Set-ChocolateyInstallFolder $chocolateyPath

if(!(test-path $chocolateyPath)){
mkdir $chocolateyPath | out-null
Expand Down