Skip to content

The agent that grows with you

fix(pm): clear read-only bits when removing a replaced tool entry

blennerhassett_btyebe431788dd81
diff --git a/pm/install.py b/pm/install.py
index 48f91d747b0..f1b8869da03 100644
--- a/pm/install.py
+++ b/pm/install.py
@@ -225,13 +225,19 @@ def _remove_entry(store: Store, entry_name: str, *, attempts: int = 5) -> None:
"""
import time
+ from hermes_cli.fs_utils import rmtree_force
+
entry = store.entry(entry_name)
for attempt in range(attempts):
try:
if entry.is_symlink() or not entry.is_dir():
entry.unlink(missing_ok=True)
else:
- shutil.rmtree(entry)
+ # PortableGit ships etc/hosts read-only, and Windows refuses to unlink
+ # a read-only file, so a bare rmtree raised WinError 5 and aborted the
+ # whole update ("install failed: [WinError 5] Access is denied"). The
+ # retry loop cannot help: the read-only bit is not a transient hold.
+ rmtree_force(entry)
return
except FileNotFoundError:
return