Improve uninstaller to purge all ~/.gravitiny contents and subfolders completely
This commit is contained in:
@@ -68,26 +68,22 @@ class GravitinyUninstaller:
|
|||||||
|
|
||||||
if self.gravitiny_home.exists():
|
if self.gravitiny_home.exists():
|
||||||
try:
|
try:
|
||||||
# 1. Clean applets and core immediately
|
# 1. Clean all subdirectories and files in ~/.gravitiny
|
||||||
applets_dir = self.gravitiny_home / "applets"
|
for item in list(self.gravitiny_home.iterdir()):
|
||||||
core_dir = self.gravitiny_home / "core"
|
if item.is_dir():
|
||||||
if applets_dir.exists():
|
AppletInstaller._safe_rmtree(item)
|
||||||
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:
|
else:
|
||||||
|
try:
|
||||||
|
item.unlink(missing_ok=True)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# 2. Delete the root directory itself
|
||||||
|
try:
|
||||||
|
self.gravitiny_home.rmdir()
|
||||||
|
except Exception:
|
||||||
AppletInstaller._safe_rmtree(self.gravitiny_home)
|
AppletInstaller._safe_rmtree(self.gravitiny_home)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return False, f"Removed from PATH, but failed to delete directory '{self.gravitiny_home}': {e}"
|
return False, f"Removed from PATH, but failed to delete directory '{self.gravitiny_home}': {e}"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user