Fix a small bug with the filtering
This commit is contained in:
parent
5945a9515b
commit
4bb424ba78
|
@ -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();
|
||||||
|
|
Loading…
Reference in New Issue