Be better at removing dead links

This commit is contained in:
Reid 'arrdem' McKenzie 2022-07-27 23:04:25 -06:00
parent 6d5713d021
commit 3ab04dcb32
2 changed files with 8 additions and 2 deletions

View file

@ -110,7 +110,7 @@ def build_fs(root: Path, dest: Path, prelude: List[str]) -> Vfs:
def load_state(statefile: Path) -> Vfs: def load_state(statefile: Path) -> Vfs:
"""Load a persisted VFS state from disk. Sort of.""" """Load a persisted VFS state from disk. Sort of."""
oldfs = Vfs() oldfs = Vfs([])
if statefile.exists(): if statefile.exists():
log.debug("Loading statefile %s", statefile) log.debug("Loading statefile %s", statefile)
@ -207,6 +207,8 @@ def do_apply(confdir, destdir, state_file, execute, optimize, require, exec_idem
root = confdir.resolve() root = confdir.resolve()
dest = destdir.resolve() dest = destdir.resolve()
log.info(f"Installing requirements {require}")
if not root.is_dir(): if not root.is_dir():
log.fatal(f"{confdir} does not exist!") log.fatal(f"{confdir} does not exist!")
_exit(1) _exit(1)

View file

@ -51,10 +51,14 @@ class Vfs(object):
elif e[0] == "unlink": elif e[0] == "unlink":
_, dest = e _, dest = e
if dest.is_dir(): if dest.is_symlink():
dest.unlink()
elif dest.is_dir():
rmtree(dest) rmtree(dest)
elif dest.is_file(): elif dest.is_file():
dest.unlink() dest.unlink()
else:
raise Exception(f"Couldn't unlink {dest}")
def _append(self, msg): def _append(self, msg):
self._log.append(msg) self._log.append(msg)