From 8102e4af388cad65e8b0e8c3fcc7f4c7cbf20e26 Mon Sep 17 00:00:00 2001 From: mxdamien Date: Mon, 17 Jan 2022 22:39:57 +0100 Subject: [PATCH] Match file extensions against blacklist to avoid multiple rebuilds triggered by temporary files --- src/main.rs | 54 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/src/main.rs b/src/main.rs index 6cdaa6fbbe..28fa50bbe5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,6 +9,8 @@ mod mesh; mod model; mod window; +use std::collections::HashSet; +use std::ffi::OsStr; use std::{collections::HashMap, sync::mpsc, time::Instant}; use futures::executor::block_on; @@ -139,27 +141,37 @@ fn main() -> anyhow::Result<()> { notify::event::DataChange::Content, )) = event.kind { - let shape = match model.load(¶meters) { - Ok(shape) => shape, - Err(model::Error::Compile) => { - // It would be better to display an error in the UI, - // where the user can actually see it. Issue: - // https://github.com/hannobraun/fornjot/issues/30 - println!("Error compiling model"); - return; - } - Err(err) => { - panic!("Error reloading model: {:?}", err); - } - }; - - // This will panic, if the other end is disconnected, which is - // probably the result of a panic on that thread, or the - // application is being shut down. - // - // Either way, not much we can do about it here, except maybe to - // provide a better error message in the future. - watcher_tx.send(shape).unwrap(); + let file_ext = event + .paths + .get(0) + .expect("File path missing in watch event") + .extension(); + + let black_list = HashSet::from([ + OsStr::new("swp"), + OsStr::new("tmp"), + OsStr::new("swx"), + ]); + + if (file_ext.is_some() + && black_list.get(file_ext.unwrap()).is_none()) + | file_ext.is_none() + { + let shape = match model.load(¶meters) { + Ok(shape) => shape, + Err(model::Error::Compile) => { + // It would be better to display an error in the UI, + // where the user can actually see it. Issue: + // https://github.com/hannobraun/fornjot/issues/30 + println!("Error compiling model"); + return; + } + Err(err) => { + panic!("Error reloading model: {:?}", err); + } + }; + watcher_tx.send(shape).unwrap(); + } } }, )?;