From 3ab04dcb3250ed1b9ffe3b2c17083e8f0ee8139a Mon Sep 17 00:00:00 2001 From: Reid 'arrdem' McKenzie Date: Wed, 27 Jul 2022 23:04:25 -0600 Subject: [PATCH] Be better at removing dead links --- projects/cram/src/python/cram/__main__.py | 4 +++- projects/vfs/src/python/vfs/impl.py | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/projects/cram/src/python/cram/__main__.py b/projects/cram/src/python/cram/__main__.py index 91cb320..a4afd39 100644 --- a/projects/cram/src/python/cram/__main__.py +++ b/projects/cram/src/python/cram/__main__.py @@ -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) diff --git a/projects/vfs/src/python/vfs/impl.py b/projects/vfs/src/python/vfs/impl.py index 6fd84c1..2ac3fe7 100644 --- a/projects/vfs/src/python/vfs/impl.py +++ b/projects/vfs/src/python/vfs/impl.py @@ -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)