Fix a small bug with the filtering

This commit is contained in:
Pi Lanningham 2023-11-10 23:20:12 -05:00 committed by KtorZ
parent 5945a9515b
commit 4bb424ba78
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
1 changed files with 8 additions and 3 deletions

View File

@ -3,6 +3,7 @@ use notify::{Event, RecursiveMode, Watcher};
use std::{ use std::{
collections::VecDeque, collections::VecDeque,
env, env,
ffi::OsStr,
path::PathBuf, path::PathBuf,
sync::{Arc, Mutex}, sync::{Arc, Mutex},
}; };
@ -15,12 +16,13 @@ pub fn default_filter(evt: &Event) -> bool {
let source_file = evt let source_file = evt
.paths .paths
.iter() .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 let build_dir = evt
.paths .paths
.iter() .iter()
.all(|p| p.ancestors().any(|a| a.ends_with("build"))); .all(|p| p.ancestors().any(|a| a.ends_with("build")));
match evt.kind { match evt.kind {
notify::EventKind::Any => true,
notify::EventKind::Create(_) notify::EventKind::Create(_)
| notify::EventKind::Modify(_) | notify::EventKind::Modify(_)
| notify::EventKind::Remove(_) => source_file && !build_dir, | 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 // Set up a queue for events, primarily so we can debounce on related events
let queue = Arc::new(Mutex::new(VecDeque::new())); let queue = Arc::new(Mutex::new(VecDeque::new()));
// pre-seed that queue with a single event, so it builds once at the start // Run the action once, to start
queue.lock().unwrap().push_back(Event::default()); queue
.lock()
.expect("lock queue")
.push_back(Event::default());
// Spawn a file-watcher that will put each change event on the queue // Spawn a file-watcher that will put each change event on the queue
let queue_write = queue.clone(); let queue_write = queue.clone();