From dacea2756af75d1151788cc0c1b2eefbead3c01f Mon Sep 17 00:00:00 2001 From: Daniel Fichtinger Date: Sun, 13 Jul 2025 03:13:58 -0400 Subject: [PATCH] fix: live preview rebuilds no longer crash the server When cleaning the previous build, we deleted the entire directory, which caused problems. Now, we only clean the output dir's children, but leave the dir itself intact. --- src/zona/builder.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/zona/builder.py b/src/zona/builder.py index de16bf5..12b5458 100644 --- a/src/zona/builder.py +++ b/src/zona/builder.py @@ -145,7 +145,13 @@ class ZonaBuilder: and self.layout.output.is_dir() ): logger.debug("Removing stale output...") - shutil.rmtree(self.layout.output) + # only remove output dir's children + # to avoid breaking live preview + for child in self.layout.output.iterdir(): + if child.is_file() or child.is_symlink(): + child.unlink() + elif child.is_dir(): + shutil.rmtree(child) logger.debug("Discovering...") self._discover() logger.debug("Building...")