Skip to content

Commit a36cab5

Browse files
committed
(#3501) Remove old install migration code
This migration path hasnt been supported or used since pre-1.0 versions of Chocolatey and is dead code. Removing this now to simplify the install process somewhat and get the old code out of the way as it's not used at all.
1 parent 8fc766e commit a36cab5

File tree

1 file changed

+7
-97
lines changed

1 file changed

+7
-97
lines changed

nuspec/chocolatey/chocolatey/tools/chocolateysetup.psm1

Lines changed: 7 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
$thisScriptFolder = (Split-Path -Parent $MyInvocation.MyCommand.Definition)
22
$chocoInstallVariableName = "ChocolateyInstall"
3-
$sysDrive = $env:SystemDrive
43
$tempDir = $env:TEMP
5-
$defaultChocolateyPathOld = "$sysDrive\Chocolatey"
4+
$insecureRootInstallPath = "$env:SystemDrive\Chocolatey"
65

76
$originalForegroundColor = $host.ui.RawUI.ForegroundColor
87

@@ -135,14 +134,15 @@ function Initialize-Chocolatey {
135134
}
136135

137136
# variable to allow insecure directory:
138-
$allowInsecureRootInstall = $false
139-
if ($env:ChocolateyAllowInsecureRootDirectory -eq 'true') {
140-
$allowInsecureRootInstall = $true
141-
}
137+
$allowInsecureRootInstall = $env:ChocolateyAllowInsecureRootDirectory -eq 'true'
142138

143139
# if we have an already environment variable path, use it.
144140
$alreadyInitializedNugetPath = Get-ChocolateyInstallFolder
145-
if ($alreadyInitializedNugetPath -and $alreadyInitializedNugetPath -ne $chocolateyPath -and ($allowInsecureRootInstall -or $alreadyInitializedNugetPath -ne $defaultChocolateyPathOld)) {
141+
142+
$useCustomInstallPath = $alreadyInitializedNugetPath -and
143+
$alreadyInitializedNugetPath -ne $chocolateyPath -and
144+
($allowInsecureRootInstall -or $alreadyInitializedNugetPath -ne $insecureRootInstallPath)
145+
if ($useCustomInstallPath) {
146146
$chocolateyPath = $alreadyInitializedNugetPath
147147
}
148148
else {
@@ -194,11 +194,6 @@ Creating Chocolatey CLI folders if they do not already exist.
194194
$realModule = Join-Path $chocolateyPath "helpers\chocolateyInstaller.psm1"
195195
Import-Module "$realModule" -Force
196196

197-
if (-not $allowInsecureRootInstall -and (Test-Path($defaultChocolateyPathOld))) {
198-
Upgrade-OldChocolateyInstall $defaultChocolateyPathOld $chocolateyPath
199-
Install-ChocolateyBinFiles $chocolateyPath $chocolateyExePath
200-
}
201-
202197
Add-ChocolateyProfile
203198
Invoke-Chocolatey-Initial
204199
if ($env:ChocolateyExitCode -eq $null -or $env:ChocolateyExitCode -eq '') {
@@ -220,10 +215,6 @@ You may need to shut down and restart powershell and/or consoles
220215
"@ | Write-Output
221216
}
222217

223-
if (-not $allowInsecureRootInstall) {
224-
Remove-OldChocolateyInstall $defaultChocolateyPathOld
225-
}
226-
227218
Remove-UnsupportedShimFiles -Paths $chocolateyExePath
228219
}
229220

@@ -368,87 +359,6 @@ function Ensure-Permissions {
368359
$ErrorActionPreference = $currentEA
369360
}
370361

371-
function Upgrade-OldChocolateyInstall {
372-
param(
373-
[string]$chocolateyPathOld = "$sysDrive\Chocolatey",
374-
[string]$chocolateyPath = "$($env:ALLUSERSPROFILE)\chocolatey"
375-
)
376-
377-
Write-Debug "Upgrade-OldChocolateyInstall"
378-
379-
if (Test-Path $chocolateyPathOld) {
380-
Write-Output "Attempting to upgrade `'$chocolateyPathOld`' to `'$chocolateyPath`'."
381-
Write-ChocolateyWarning "Copying the contents of `'$chocolateyPathOld`' to `'$chocolateyPath`'. `n This step may fail if you have anything in this folder running or locked."
382-
Write-Output 'If it fails, just manually copy the rest of the items out and then delete the folder.'
383-
Write-ChocolateyWarning "!!!! ATTN: YOU WILL NEED TO CLOSE AND REOPEN YOUR SHELL !!!!"
384-
#-ForegroundColor Magenta -BackgroundColor Black
385-
386-
$chocolateyExePathOld = Join-Path $chocolateyPathOld 'bin'
387-
'Machine', 'User' |
388-
ForEach-Object {
389-
$path = Get-EnvironmentVariable -Name 'PATH' -Scope $_
390-
$updatedPath = [System.Text.RegularExpressions.Regex]::Replace($path, [System.Text.RegularExpressions.Regex]::Escape($chocolateyExePathOld) + '(?>;)?', '', [System.Text.RegularExpressions.RegexOptions]::IgnoreCase)
391-
if ($updatedPath -ne $path) {
392-
Write-Output "Updating `'$_`' PATH to reflect removal of '$chocolateyPathOld'."
393-
try {
394-
Set-EnvironmentVariable -Name 'Path' -Value $updatedPath -Scope $_ -ErrorAction Stop
395-
}
396-
catch {
397-
Write-ChocolateyWarning "Was not able to remove the old environment variable from PATH. You will need to do this manually"
398-
}
399-
}
400-
}
401-
402-
Copy-Item "$chocolateyPathOld\lib\*" "$chocolateyPath\lib" -Force -Recurse
403-
404-
$from = "$chocolateyPathOld\bin"
405-
$to = "$chocolateyPath\bin"
406-
# TODO: This exclusion list needs to be updated once shims are removed
407-
$exclude = @("choco.exe", "RefreshEnv.cmd")
408-
Get-ChildItem -Path $from -Recurse -Exclude $exclude |
409-
ForEach-Object {
410-
Write-Debug "Copying $_ `n to $to"
411-
if ($_.PSIsContainer) {
412-
Copy-Item $_ -Destination (Join-Path $to $_.Parent.FullName.Substring($from.length)) -Force -ErrorAction SilentlyContinue
413-
}
414-
else {
415-
$fileToMove = (Join-Path $to $_.FullName.Substring($from.length))
416-
try {
417-
Copy-Item $_ -Destination $fileToMove -Exclude $exclude -Force -ErrorAction Stop
418-
}
419-
catch {
420-
Write-ChocolateyWarning "Was not able to move `'$fileToMove`'. You may need to reinstall the shim"
421-
}
422-
}
423-
}
424-
}
425-
}
426-
427-
function Remove-OldChocolateyInstall {
428-
param(
429-
[string]$chocolateyPathOld = "$sysDrive\Chocolatey"
430-
)
431-
Write-Debug "Remove-OldChocolateyInstall"
432-
433-
if (Test-Path $chocolateyPathOld) {
434-
Write-ChocolateyWarning "This action will result in Log Errors, you can safely ignore those. `n You may need to finish removing '$chocolateyPathOld' manually."
435-
try {
436-
Get-ChildItem -Path "$chocolateyPathOld" | ForEach-Object {
437-
if (Test-Path $_.FullName) {
438-
Write-Debug "Removing $_ unless matches .log"
439-
Remove-Item $_.FullName -Exclude *.log -Recurse -Force -ErrorAction SilentlyContinue
440-
}
441-
}
442-
443-
Write-Output "Attempting to remove `'$chocolateyPathOld`'. This may fail if something in the folder is being used or locked."
444-
Remove-Item "$($chocolateyPathOld)" -Force -Recurse -ErrorAction Stop
445-
}
446-
catch {
447-
Write-ChocolateyWarning "Was not able to remove `'$chocolateyPathOld`'. You will need to manually remove it."
448-
}
449-
}
450-
}
451-
452362
function Install-ChocolateyFiles {
453363
param(
454364
[string]$chocolateyPath

0 commit comments

Comments
 (0)