From 41c1439192d8526d9a288908d98fd91c05f0bcdb Mon Sep 17 00:00:00 2001 From: Ross Andrews Date: Tue, 25 Nov 2025 12:51:55 -0600 Subject: [PATCH] building now clears build dir --- src/fleen_app.rs | 16 +++++++++++++++- src/main.rs | 2 +- src/server.rs | 2 +- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/fleen_app.rs b/src/fleen_app.rs index bd467ea..8cfc3ce 100644 --- a/src/fleen_app.rs +++ b/src/fleen_app.rs @@ -241,7 +241,7 @@ impl FleenApp { for entry in root.join(dir).read_dir().unwrap() { let file = PathBuf::from(entry.unwrap().file_name()); sources.push(renderer::file_render(dir.join(&file), root)?); - if root.join(&dir).join(&file).is_dir() { + if root.join(dir).join(&file).is_dir() { // root + dir + file is a child directory, so we want to recurse... // into dir + file. visit_dir(&dir.join(&file), root, sources)? @@ -254,12 +254,26 @@ impl FleenApp { } pub fn build_site(&self, target: &Path) -> Result<(), FleenError> { + // Ensure neither the target nor src dirs are ancestors of the other if self.root.ancestors().any(|a| a == target) || target.ancestors().any(|a| a == self.root) { return Err(TargetDir) } + // Clear the target directory first: + for entry in fs::read_dir(target)? { + let entry = entry?; + if entry.file_type()?.is_dir() { + fs::remove_dir_all(entry.path())? + } else { + fs::remove_file(entry.path())? + } + } + + // Decide which actions we need to do to build the site let actions = self.compile()?; + + // And then do them! for action in actions.into_iter() { action.file_operation(&self.root, target)?; } diff --git a/src/main.rs b/src/main.rs index fa96056..4c06def 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,7 @@ mod ui_ext; use std::path::{Path, PathBuf}; use std::time::{Duration, Instant}; -use eframe::egui::{Button, Context, Direction, Id, Layout, RichText}; +use eframe::egui::{Button, Context, Id, RichText}; use eframe::{egui, Frame}; use egui_ltreeview::Action; use tokio::task::JoinHandle; diff --git a/src/server.rs b/src/server.rs index c9e579e..9d6cbb3 100644 --- a/src/server.rs +++ b/src/server.rs @@ -39,7 +39,7 @@ fn serve_path(path: String, root: PathBuf) -> impl IntoResponse { // We were pointed at the raw contents of a file: Response::builder() .status(200) - .body(Body::from(fs::read(root.join(file)).unwrap_or(vec![]))).unwrap() + .body(Body::from(fs::read(root.join(file)).unwrap_or_default())).unwrap() } Ok(RenderOutput::NoOutput) | Ok(RenderOutput::Dir(_)) => {