Skip to content

Commit 0405698

Browse files
committed
Avoid persisting environment variables on systems that don't support it (like nanoserver)
1 parent 43ee288 commit 0405698

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

PhpManager/private/Add-PhpFolderToPath.ps1

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,18 @@ Function Add-PhpFolderToPath
3535
$targets += $Script:ENVTARGET_PROCESS
3636
}
3737
If ($null -ne $Persist) {
38-
If ($Persist -eq 'User') {
39-
$targets += $Script:ENVTARGET_USER
40-
} ElseIf ($Persist -eq 'System') {
41-
$targets += $Script:ENVTARGET_MACHINE
38+
If ([System.Environment]::GetEnvironmentVariable[0].OverloadDefinitions.Count -lt 2) {
39+
If ($CurrentProcess) {
40+
Write-Warning "The current PowerShell version does not support persisting environment variables: we'll set the Path only for the current process"
41+
} Else {
42+
Write-Warning "The current PowerShell version does not support persisting environment variables"
43+
}
44+
} Else {
45+
If ($Persist -eq 'User') {
46+
$targets += $Script:ENVTARGET_USER
47+
} ElseIf ($Persist -eq 'System') {
48+
$targets += $Script:ENVTARGET_MACHINE
49+
}
4250
}
4351
}
4452
ForEach ($target in $targets) {

PhpManager/public/Install-Php.ps1

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,7 @@ function Install-Php() {
152152
Set-PhpIniKey -Key 'extension_dir' -Value $([System.IO.Path]::Combine($Path, 'ext')) -Path $iniPath
153153
}
154154
If ($null -ne $AddToPath -and $AddToPath -ne '') {
155-
If ([System.Environment]::GetEnvironmentVariable[0].OverloadDefinitions.Count -lt 2) {
156-
Write-Warning "The current PowerShell version does not support saving environment variables to ${AddToPath}: we'll set the Path only for the current process"
157-
Add-PhpFolderToPath -Path $Path -CurrentProcess
158-
} Else {
159-
Add-PhpFolderToPath -Path $Path -Persist $AddToPath -CurrentProcess
160-
}
155+
Add-PhpFolderToPath -Path $Path -Persist $AddToPath -CurrentProcess
161156
}
162157
}
163158
End {

0 commit comments

Comments
 (0)