Skip to content

Commit

Permalink
(chocolatey#3501) Remove old install migration code
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vexx32 committed Oct 8, 2024
1 parent 8fc766e commit 2bdb4e9
Showing 1 changed file with 1 addition and 93 deletions.
94 changes: 1 addition & 93 deletions nuspec/chocolatey/chocolatey/tools/chocolateysetup.psm1
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
$thisScriptFolder = (Split-Path -Parent $MyInvocation.MyCommand.Definition)
$chocoInstallVariableName = "ChocolateyInstall"
$sysDrive = $env:SystemDrive
$tempDir = $env:TEMP
$defaultChocolateyPathOld = "$sysDrive\Chocolatey"

$originalForegroundColor = $host.ui.RawUI.ForegroundColor

Expand Down Expand Up @@ -142,7 +140,7 @@ function Initialize-Chocolatey {

# if we have an already environment variable path, use it.
$alreadyInitializedNugetPath = Get-ChocolateyInstallFolder
if ($alreadyInitializedNugetPath -and $alreadyInitializedNugetPath -ne $chocolateyPath -and ($allowInsecureRootInstall -or $alreadyInitializedNugetPath -ne $defaultChocolateyPathOld)) {
if ($alreadyInitializedNugetPath -and $alreadyInitializedNugetPath -ne $chocolateyPath -and $allowInsecureRootInstall) {
$chocolateyPath = $alreadyInitializedNugetPath
}
else {
Expand Down Expand Up @@ -194,11 +192,6 @@ Creating Chocolatey CLI folders if they do not already exist.
$realModule = Join-Path $chocolateyPath "helpers\chocolateyInstaller.psm1"
Import-Module "$realModule" -Force

if (-not $allowInsecureRootInstall -and (Test-Path($defaultChocolateyPathOld))) {
Upgrade-OldChocolateyInstall $defaultChocolateyPathOld $chocolateyPath
Install-ChocolateyBinFiles $chocolateyPath $chocolateyExePath
}

Add-ChocolateyProfile
Invoke-Chocolatey-Initial
if ($env:ChocolateyExitCode -eq $null -or $env:ChocolateyExitCode -eq '') {
Expand All @@ -220,10 +213,6 @@ You may need to shut down and restart powershell and/or consoles
"@ | Write-Output
}

if (-not $allowInsecureRootInstall) {
Remove-OldChocolateyInstall $defaultChocolateyPathOld
}

Remove-UnsupportedShimFiles -Paths $chocolateyExePath
}

Expand Down Expand Up @@ -368,87 +357,6 @@ function Ensure-Permissions {
$ErrorActionPreference = $currentEA
}

function Upgrade-OldChocolateyInstall {
param(
[string]$chocolateyPathOld = "$sysDrive\Chocolatey",
[string]$chocolateyPath = "$($env:ALLUSERSPROFILE)\chocolatey"
)

Write-Debug "Upgrade-OldChocolateyInstall"

if (Test-Path $chocolateyPathOld) {
Write-Output "Attempting to upgrade `'$chocolateyPathOld`' to `'$chocolateyPath`'."
Write-ChocolateyWarning "Copying the contents of `'$chocolateyPathOld`' to `'$chocolateyPath`'. `n This step may fail if you have anything in this folder running or locked."
Write-Output 'If it fails, just manually copy the rest of the items out and then delete the folder.'
Write-ChocolateyWarning "!!!! ATTN: YOU WILL NEED TO CLOSE AND REOPEN YOUR SHELL !!!!"
#-ForegroundColor Magenta -BackgroundColor Black

$chocolateyExePathOld = Join-Path $chocolateyPathOld 'bin'
'Machine', 'User' |
ForEach-Object {
$path = Get-EnvironmentVariable -Name 'PATH' -Scope $_
$updatedPath = [System.Text.RegularExpressions.Regex]::Replace($path, [System.Text.RegularExpressions.Regex]::Escape($chocolateyExePathOld) + '(?>;)?', '', [System.Text.RegularExpressions.RegexOptions]::IgnoreCase)
if ($updatedPath -ne $path) {
Write-Output "Updating `'$_`' PATH to reflect removal of '$chocolateyPathOld'."
try {
Set-EnvironmentVariable -Name 'Path' -Value $updatedPath -Scope $_ -ErrorAction Stop
}
catch {
Write-ChocolateyWarning "Was not able to remove the old environment variable from PATH. You will need to do this manually"
}
}
}

Copy-Item "$chocolateyPathOld\lib\*" "$chocolateyPath\lib" -Force -Recurse

$from = "$chocolateyPathOld\bin"
$to = "$chocolateyPath\bin"
# TODO: This exclusion list needs to be updated once shims are removed
$exclude = @("choco.exe", "RefreshEnv.cmd")
Get-ChildItem -Path $from -Recurse -Exclude $exclude |
ForEach-Object {
Write-Debug "Copying $_ `n to $to"
if ($_.PSIsContainer) {
Copy-Item $_ -Destination (Join-Path $to $_.Parent.FullName.Substring($from.length)) -Force -ErrorAction SilentlyContinue
}
else {
$fileToMove = (Join-Path $to $_.FullName.Substring($from.length))
try {
Copy-Item $_ -Destination $fileToMove -Exclude $exclude -Force -ErrorAction Stop
}
catch {
Write-ChocolateyWarning "Was not able to move `'$fileToMove`'. You may need to reinstall the shim"
}
}
}
}
}

function Remove-OldChocolateyInstall {
param(
[string]$chocolateyPathOld = "$sysDrive\Chocolatey"
)
Write-Debug "Remove-OldChocolateyInstall"

if (Test-Path $chocolateyPathOld) {
Write-ChocolateyWarning "This action will result in Log Errors, you can safely ignore those. `n You may need to finish removing '$chocolateyPathOld' manually."
try {
Get-ChildItem -Path "$chocolateyPathOld" | ForEach-Object {
if (Test-Path $_.FullName) {
Write-Debug "Removing $_ unless matches .log"
Remove-Item $_.FullName -Exclude *.log -Recurse -Force -ErrorAction SilentlyContinue
}
}

Write-Output "Attempting to remove `'$chocolateyPathOld`'. This may fail if something in the folder is being used or locked."
Remove-Item "$($chocolateyPathOld)" -Force -Recurse -ErrorAction Stop
}
catch {
Write-ChocolateyWarning "Was not able to remove `'$chocolateyPathOld`'. You will need to manually remove it."
}
}
}

function Install-ChocolateyFiles {
param(
[string]$chocolateyPath
Expand Down

0 comments on commit 2bdb4e9

Please sign in to comment.