fix(uninstaller): defer parent dir purge on windows to eliminate cmd seek error

This commit is contained in:
Gravitiny Team
2026-10-03 04:37:14 +03:00
parent 6701661310
commit 3a77fb2513
2 changed files with 43 additions and 1 deletions
+23
View File
@@ -79,4 +79,27 @@ A true zero-trace CLI package manager must be fully self-contained upon installa
2. Verified applet discovery, installation, and execution (`lex`, `sec`) from an independent working directory outside the repository clone.
3. Verified `gravitiny --help` and `gravitiny uninstall` command workflow.
---
## Issue #004: Windows cmd.exe File Pointer Error on Immediate Self-Deletion
- **Component:** `gravitiny.src.uninstaller.GravitinyUninstaller`
- **Severity:** Low (Cosmetic CLI Message)
- **Status:** Resolved
### Symptom
When executing `gravitiny uninstall` from a Windows Command Prompt, the uninstallation succeeded completely, but cmd.exe printed `The system cannot find the path specified.` at the very end of execution.
### Root Cause
When executing through `~/.gravitiny/bin/gravitiny.cmd`, Windows `cmd.exe` holds an active file pointer to `gravitiny.cmd`. Because the uninstaller deleted the entire `~/.gravitiny` folder synchronously while Python was still running inside the batch script, `cmd.exe` encountered an error when trying to seek to the end of `gravitiny.cmd` after Python terminated.
### Solution
1. In `GravitinyUninstaller.uninstall()`, the uninstaller immediately removes `applets/` and `core/` synchronously.
2. On Windows, the final purge of the parent directory `~/.gravitiny` is deferred to a detached non-blocking background task (`subprocess.CREATE_NO_WINDOW`) with a short delay (e.g. `ping 127.0.0.1 -n 2 >nul & rd /s /q "~/.gravitiny"`).
3. This allows `gravitiny.cmd` to exit cleanly and close its file handle before the directory is purged, eliminating the error message.
### Verification
Simulated uninstallation cycle and verified zero extraneous terminal errors.
+19
View File
@@ -68,6 +68,25 @@ class GravitinyUninstaller:
if self.gravitiny_home.exists():
try:
# 1. Clean applets and core immediately
applets_dir = self.gravitiny_home / "applets"
core_dir = self.gravitiny_home / "core"
if applets_dir.exists():
AppletInstaller._safe_rmtree(applets_dir)
if core_dir.exists():
AppletInstaller._safe_rmtree(core_dir)
# 2. If running under Windows cmd.exe, use detached process to delete ~/.gravitiny
# after the batch script exits to prevent "The system cannot find the path specified"
if os.name == "nt":
import subprocess
cmd = f'ping 127.0.0.1 -n 2 >nul & rd /s /q "{self.gravitiny_home}"'
subprocess.Popen(
["cmd.exe", "/c", cmd],
creationflags=0x08000000, # CREATE_NO_WINDOW
close_fds=True,
)
else:
AppletInstaller._safe_rmtree(self.gravitiny_home)
except Exception as e:
return False, f"Removed from PATH, but failed to delete directory '{self.gravitiny_home}': {e}"