fix(Uninstall): use script location, fix broken self-delete

Two bugs in Uninstall-Elysium:
- $ElysiumPath came from Get-Location (the caller's current working
  directory) instead of $PSScriptRoot. Running the script from any
  CWD other than the install folder recursively force-deleted the
  wrong directory.
- The self-delete workaround was also broken: Remove-Item -Exclude
  matches leaf names via wildcard, not the full path it was given, so
  the exclusion never matched; and the deferred
  "powershell.exe -Command <scriptblock> -ArgumentList <path>" command
  line is not valid syntax for binding $path in the child process.

PowerShell reads a script fully into memory before running it, so it
holds no open handle on the file - deleting the install directory
(including this script) while it's still executing is safe. Dropped
the exclude/deferred-process workaround entirely.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-29 11:49:47 +02:00
parent ac3f30db1e
commit 855be8de9c
+6 -12
View File
@@ -41,26 +41,20 @@ function Start-UninstallTranscript {
function Stop-UninstallTranscript { try { Stop-Transcript | Out-Null } catch {} }
function Uninstall-Elysium {
$ElysiumPath = Get-Location
$ElysiumPath = $PSScriptRoot
Write-Host "Uninstalling Elysium tool from $ElysiumPath..."
# Check if the Elysium directory exists
if (Test-Path $ElysiumPath) {
# Schedule the script file for deletion
$scriptPath = $MyInvocation.MyCommand.Path
$deleteScript = { param($path) Remove-Item -Path $path -Force }
Start-Sleep -Seconds 3 # Delay to ensure the script finishes
Start-Process -FilePath "powershell.exe" -ArgumentList "-Command", $deleteScript, "-ArgumentList", $scriptPath -WindowStyle Hidden
# Remove the Elysium directory and all its contents
Remove-Item -Path $ElysiumPath -Recurse -Force -Exclude $scriptPath
Write-Host "Elysium tool and all related files have been removed, excluding this script. This script will be deleted shortly."
# PowerShell reads the whole script into memory before execution begins, so it holds no
# open file handle on this script - deleting the install directory (including this file)
# while still running is safe and needs no deferred external delete process.
Remove-Item -Path $ElysiumPath -Recurse -Force
Write-Host "Elysium tool and all related files have been removed."
} else {
Write-Host "Elysium directory not found. It might have been removed already, or the path is incorrect."
}
# Additional cleanup actions can be added here if needed
}
Start-UninstallTranscript