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:
+6
-12
@@ -41,26 +41,20 @@ function Start-UninstallTranscript {
|
|||||||
function Stop-UninstallTranscript { try { Stop-Transcript | Out-Null } catch {} }
|
function Stop-UninstallTranscript { try { Stop-Transcript | Out-Null } catch {} }
|
||||||
|
|
||||||
function Uninstall-Elysium {
|
function Uninstall-Elysium {
|
||||||
$ElysiumPath = Get-Location
|
$ElysiumPath = $PSScriptRoot
|
||||||
|
|
||||||
Write-Host "Uninstalling Elysium tool from $ElysiumPath..."
|
Write-Host "Uninstalling Elysium tool from $ElysiumPath..."
|
||||||
|
|
||||||
# Check if the Elysium directory exists
|
# Check if the Elysium directory exists
|
||||||
if (Test-Path $ElysiumPath) {
|
if (Test-Path $ElysiumPath) {
|
||||||
# Schedule the script file for deletion
|
# PowerShell reads the whole script into memory before execution begins, so it holds no
|
||||||
$scriptPath = $MyInvocation.MyCommand.Path
|
# open file handle on this script - deleting the install directory (including this file)
|
||||||
$deleteScript = { param($path) Remove-Item -Path $path -Force }
|
# while still running is safe and needs no deferred external delete process.
|
||||||
Start-Sleep -Seconds 3 # Delay to ensure the script finishes
|
Remove-Item -Path $ElysiumPath -Recurse -Force
|
||||||
Start-Process -FilePath "powershell.exe" -ArgumentList "-Command", $deleteScript, "-ArgumentList", $scriptPath -WindowStyle Hidden
|
Write-Host "Elysium tool and all related files have been removed."
|
||||||
|
|
||||||
# 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."
|
|
||||||
} else {
|
} else {
|
||||||
Write-Host "Elysium directory not found. It might have been removed already, or the path is incorrect."
|
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
|
Start-UninstallTranscript
|
||||||
|
|||||||
Reference in New Issue
Block a user