From 4bb424ba7801ae4b833bfc88e60752a850eed01e Mon Sep 17 00:00:00 2001 From: Pi Lanningham Date: Fri, 10 Nov 2023 23:20:12 -0500 Subject: [PATCH] Fix a small bug with the filtering --- crates/aiken-project/src/watch.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/crates/aiken-project/src/watch.rs b/crates/aiken-project/src/watch.rs index fc95c426..61dda460 100644 --- a/crates/aiken-project/src/watch.rs +++ b/crates/aiken-project/src/watch.rs @@ -3,6 +3,7 @@ use notify::{Event, RecursiveMode, Watcher}; use std::{ collections::VecDeque, env, + ffi::OsStr, path::PathBuf, sync::{Arc, Mutex}, }; @@ -15,12 +16,13 @@ pub fn default_filter(evt: &Event) -> bool { let source_file = evt .paths .iter() - .any(|p| p.ends_with(".ak") || p.ends_with("aiken.toml")); + .any(|p| p.extension() == Some(OsStr::new("ak")) || p.ends_with("aiken.toml")); let build_dir = evt .paths .iter() .all(|p| p.ancestors().any(|a| a.ends_with("build"))); match evt.kind { + notify::EventKind::Any => true, notify::EventKind::Create(_) | notify::EventKind::Modify(_) | notify::EventKind::Remove(_) => source_file && !build_dir, @@ -56,8 +58,11 @@ where // Set up a queue for events, primarily so we can debounce on related events let queue = Arc::new(Mutex::new(VecDeque::new())); - // pre-seed that queue with a single event, so it builds once at the start - queue.lock().unwrap().push_back(Event::default()); + // Run the action once, to start + queue + .lock() + .expect("lock queue") + .push_back(Event::default()); // Spawn a file-watcher that will put each change event on the queue let queue_write = queue.clone();