From f6de40251b75e7506163bbb8b9ac18f3349221b0 Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Sat, 20 Feb 2021 19:13:10 -0600 Subject: [PATCH] Fix the watch mask --- imap/src/client/inner.rs | 23 +++++++++++++---------- src/config.rs | 16 +++++++++------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/imap/src/client/inner.rs b/imap/src/client/inner.rs index c712123..a44b3fa 100644 --- a/imap/src/client/inner.rs +++ b/imap/src/client/inner.rs @@ -19,6 +19,7 @@ use crate::command::Command; use crate::response::Response; pub type BoxedFunc = Box; +pub const TAG_PREFIX: &str = "panorama"; /// The private Client struct, that is shared by all of the exported structs in the state machine. pub struct Client { @@ -28,7 +29,6 @@ pub struct Client { id: usize, results: ResultMap, - /// Cached capabilities that shouldn't change between caps: Vec, handle: JoinHandle>, } @@ -63,7 +63,7 @@ where handlers.insert(id, (None, None)); } - let cmd_str = format!("pano{} {}\n", id, cmd); + let cmd_str = format!("{}{} {}\r\n", TAG_PREFIX, id, cmd); debug!("[{}] writing to socket: {:?}", id, cmd_str); self.conn.write_all(cmd_str.as_bytes()).await?; debug!("[{}] written.", id); @@ -92,7 +92,7 @@ impl<'a, C> Future for ExecHandle<'a, C> { type Output = (); fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll { let mut handlers = self.0.results.write(); - let mut state = handlers.get_mut(&self.1); + let state = handlers.get_mut(&self.1); // TODO: handle the None case here debug!("f[{}] {:?}", self.1, state); @@ -117,18 +117,21 @@ async fn listen(conn: impl AsyncRead + Unpin, results: ResultMap) -> Result<()> loop { let mut next_line = String::new(); reader.read_line(&mut next_line).await?; + let next_line = next_line.trim_end_matches('\r'); // debug!("line: {:?}", next_line); - let parts = next_line.split(" ").collect::>(); - let tag = parts[0]; + let mut parts = next_line.split(" "); + let tag = parts.next().unwrap(); + let rest = parts.collect::>().join(" "); + if tag == "*" { - debug!("UNTAGGED {:?}", next_line); - } else if tag.starts_with("pano") { - let id = tag.trim_start_matches("pano").parse::()?; - debug!("set {} to {:?}", id, next_line); + debug!("UNTAGGED {:?}", rest); + } else if tag.starts_with(TAG_PREFIX) { + let id = tag.trim_start_matches(TAG_PREFIX).parse::()?; + debug!("set {} to {:?}", id, rest); let mut results = results.write(); if let Some((c, w)) = results.get_mut(&id) { - *c = Some(next_line); + *c = Some(rest.to_string()); let w = w.take().unwrap(); w.wake(); } diff --git a/src/config.rs b/src/config.rs index e294fd8..88fafe7 100644 --- a/src/config.rs +++ b/src/config.rs @@ -96,8 +96,10 @@ async fn start_inotify_stream( config_tx.send(config)?; } + debug!("listening for inotify events"); while let Some(v) = event_stream.next().await { let event = v.context("event")?; + debug!("inotify event: {:?}", event); if let Some(name) = event.name { let path = PathBuf::from(name); @@ -139,15 +141,15 @@ pub fn spawn_config_watcher_system() -> Result<(JoinHandle<()>, ConfigWatcher)> fs::create_dir_all(&config_home)?; } inotify - .add_watch(&config_home, WatchMask::all()) + .add_watch(&config_home, WatchMask::CLOSE_WRITE) .context("adding watch for config home")?; - let config_file_path = config_home.join("panorama.toml"); - if config_file_path.exists() { - inotify - .add_watch(config_file_path, WatchMask::CLOSE) - .context("adding watch for config file")?; - } + // let config_file_path = config_home.join("panorama.toml"); + // if config_file_path.exists() { + // inotify + // .add_watch(config_file_path, WatchMask::ALL_EVENTS) + // .context("adding watch for config file")?; + // } debug!("watching {:?}", config_home); let (config_tx, config_update) = watch::channel(Config::default());