diff options
author | 2022-02-21 14:31:21 +0800 | |
---|---|---|
committer | 2022-02-21 14:31:21 +0800 | |
commit | a492ea4f14c5e3104e0d90d1a411074d1d2b10a0 (patch) | |
tree | fefc2c921fabda84668006941a91f9100a363d3f | |
parent | 55aedfc29a47dc4ddeb9434b699fff199e2ca239 (diff) | |
download | rathole-a492ea4f14c5e3104e0d90d1a411074d1d2b10a0.tar.gz rathole-a492ea4f14c5e3104e0d90d1a411074d1d2b10a0.tar.zst rathole-a492ea4f14c5e3104e0d90d1a411074d1d2b10a0.zip |
fix(config_watcher): allow backupcopy for vim (#122)
by watching the parent dir of config file, we can receive events regardless of the inode of the config file.
-rw-r--r-- | src/config_watcher.rs | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/config_watcher.rs b/src/config_watcher.rs index 5899f15..00594c7 100644 --- a/src/config_watcher.rs +++ b/src/config_watcher.rs @@ -11,7 +11,7 @@ use tokio::sync::{broadcast, mpsc}; use tracing::{error, info, instrument}; #[cfg(feature = "notify")] -use notify::{event::ModifyKind, EventKind, RecursiveMode, Watcher}; +use notify::{EventKind, RecursiveMode, Watcher}; #[derive(Debug, PartialEq)] pub enum ConfigChange { @@ -139,18 +139,24 @@ async fn config_watcher( mut old: Config, ) -> Result<()> { let (fevent_tx, mut fevent_rx) = mpsc::unbounded_channel(); - + let parent_path = path.parent().expect("config file should have a parent dir"); + let path_clone = path.clone(); let mut watcher = notify::recommended_watcher(move |res: Result<notify::Event, _>| match res { Ok(e) => { - if let EventKind::Modify(ModifyKind::Data(_)) = e.kind { + if matches!(e.kind, EventKind::Modify(_)) + && e.paths + .iter() + .map(|x| x.file_name()) + .any(|x| x == path_clone.file_name()) + { let _ = fevent_tx.send(true); } } Err(e) => error!("watch error: {:#}", e), })?; - watcher.watch(&path, RecursiveMode::NonRecursive)?; + watcher.watch(parent_path, RecursiveMode::NonRecursive)?; info!("Start watching the config"); loop { |