New Imfs event type

This commit is contained in:
Lucien Greathouse 2019-10-01 11:29:09 -07:00
parent 1737da9c1f
commit 694b6101ca
3 changed files with 49 additions and 25 deletions

View file

@ -9,9 +9,9 @@ use std::{
time::Duration,
};
use crossbeam_channel::{unbounded, Receiver};
use crossbeam_channel::{unbounded, Receiver, Sender};
use jod_thread::JoinHandle;
use notify::{RecommendedWatcher, RecursiveMode, Watcher};
use notify::{DebouncedEvent, RecommendedWatcher, RecursiveMode, Watcher};
use super::{
event::ImfsEvent,
@ -58,9 +58,7 @@ impl RealFetcher {
let handle = jod_thread::Builder::new()
.name("notify message converter".to_owned())
.spawn(move || {
notify_receiver
.into_iter()
.for_each(|event| sender.send(event).unwrap());
converter_thread(notify_receiver, sender);
})
.expect("Could not start message converter thread");
@ -84,6 +82,41 @@ impl RealFetcher {
}
}
fn converter_thread(notify_receiver: mpsc::Receiver<DebouncedEvent>, sender: Sender<ImfsEvent>) {
notify_receiver.into_iter().for_each(|event| {
use DebouncedEvent::*;
match event {
Create(path) => sender.send(ImfsEvent::Created(path)).unwrap(),
Write(path) => sender.send(ImfsEvent::Modified(path)).unwrap(),
Remove(path) => sender.send(ImfsEvent::Removed(path)).unwrap(),
Rename(from_path, to_path) => {
sender.send(ImfsEvent::Created(from_path)).unwrap();
sender.send(ImfsEvent::Removed(to_path)).unwrap();
}
Rescan => {
log::warn!("Unhandled filesystem rescan event.");
log::warn!(
"Please file an issue! Rojo may need to handle this case, but does not yet."
);
}
Error(err, maybe_path) => {
log::warn!("Unhandled filesystem error: {}", err);
match maybe_path {
Some(path) => log::warn!("On path {}", path.display()),
None => log::warn!("No path was associated with this error."),
}
log::warn!(
"Rojo may need to handle this. If this happens again, please file an issue!"
);
}
NoticeWrite(_) | NoticeRemove(_) | Chmod(_) => {}
}
});
}
impl ImfsFetcher for RealFetcher {
fn file_type(&mut self, path: &Path) -> io::Result<FileType> {
let metadata = fs::metadata(path)?;