Be better at removing dead links

This commit is contained in:
Reid 'arrdem' McKenzie 2022-07-27 23:04:25 -06:00
parent 3a8677c630
commit 1df60b873b
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:
"""Load a persisted VFS state from disk. Sort of."""
oldfs = Vfs()
oldfs = Vfs([])
if statefile.exists():
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()
dest = destdir.resolve()
log.info(f"Installing requirements {require}")
if not root.is_dir():
log.fatal(f"{confdir} does not exist!")
_exit(1)

View file

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