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.
This commit is contained in:
Daniel Fichtinger 2025-07-13 03:13:58 -04:00
parent 8d17572d12
commit e5fa7e85fc
2 changed files with 8 additions and 1 deletions

View file

@ -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...")

View file

@ -4,6 +4,7 @@ import signal
import sys
import tempfile
import threading
import time
from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer
from pathlib import Path
from types import FrameType