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 all commits
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
24 changes: 14 additions & 10 deletions nuget/tools/chocolateysetup.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@ $sysDrive = $env:SystemDrive
$defaultChocolateyPathOld = "$sysDrive\NuGet"

function Set-ChocolateyInstallFolder($folder){
#if(test-path $folder){
$procVar = [Environment]::GetEnvironmentVariable($chocInstallVariableName, [System.EnvironmentVariableTarget]::Process)
$userVar = [Environment]::GetEnvironmentVariable($chocInstallVariableName, [System.EnvironmentVariableTarget]::User)

# only set an env var if the value came from a process based env or the default value
# the default value can be assumed if both proc and user scoped vars are null
# Otherwise it came from a sys or existing user var which means we don't have to set it
if ( ($procVar -eq $folder) -or ($procVar -eq $null -and $userVar -eq $null)) {
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]"
#}
}
}

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 +143,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