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

@@ -1,2 +1,8 @@
// TODO: Use our own event type instead of notify's.
pub type ImfsEvent = notify::DebouncedEvent;
use std::path::PathBuf;
#[derive(Debug)]
pub enum ImfsEvent {
Modified(PathBuf),
Created(PathBuf),
Removed(PathBuf),
}

View File

@@ -48,32 +48,17 @@ impl<F: ImfsFetcher> Imfs<F> {
}
pub fn commit_change(&mut self, event: &ImfsEvent) -> FsResult<()> {
use notify::DebouncedEvent::*;
use ImfsEvent::*;
log::trace!("Committing Imfs change {:?}", event);
match event {
Create(path) => {
Created(path) | Modified(path) => {
self.raise_file_changed(path)?;
}
Write(path) => {
self.raise_file_changed(path)?;
}
Remove(path) => {
Removed(path) => {
self.raise_file_removed(path)?;
}
Rename(from_path, to_path) => {
self.raise_file_removed(from_path)?;
self.raise_file_changed(to_path)?;
}
Error(err, path) => {
log::warn!("Filesystem error detected: {:?} on path {:?}", err, path);
}
Rescan => {
// FIXME: Implement rescanning
log::warn!("Unhandled filesystem rescan event");
}
NoticeWrite(_) | NoticeRemove(_) | Chmod(_) => {}
}
Ok(())

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)?;