From 5a2251390b0dc89f6383a054f6f596a416c91e3e Mon Sep 17 00:00:00 2001 From: metamuffin Date: Thu, 10 Apr 2025 21:07:13 +0200 Subject: fixup: config watches --- src/config.rs | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/config.rs b/src/config.rs index 020e1e2..7b46944 100644 --- a/src/config.rs +++ b/src/config.rs @@ -8,7 +8,7 @@ use crate::{ State, }; use anyhow::Context; -use inotify::{EventMask, Inotify, WatchMask}; +use inotify::{Inotify, WatchMask}; use log::{error, info}; use rand::random; use serde::{ @@ -218,7 +218,7 @@ pub fn setup_file_watch(config_path: PathBuf, state: Arc) { .watches() .add( config_path.parent().unwrap(), - WatchMask::MODIFY | WatchMask::CREATE | WatchMask::DELETE, + WatchMask::MODIFY | WatchMask::CREATE | WatchMask::DELETE | WatchMask::MOVED_TO, ) .unwrap(); let mut buffer = [0u8; 4096]; @@ -228,18 +228,16 @@ pub fn setup_file_watch(config_path: PathBuf, state: Arc) { .expect("Failed to read inotify events"); for event in events { - if event.mask.contains(EventMask::MODIFY) { - if event.name == config_path.file_name() { - if config_path.metadata().map(|m| m.len()).unwrap_or_default() == 0 { - continue; - } - match Config::load(&config_path) { - Ok(conf) => { - let mut r = state.config.blocking_write(); - *r = Arc::new(conf) - } - Err(e) => error!("config has errors: {e:?}"), + if event.name == config_path.file_name() { + if config_path.metadata().map(|m| m.len()).unwrap_or_default() == 0 { + continue; + } + match Config::load(&config_path) { + Ok(conf) => { + let mut r = state.config.blocking_write(); + *r = Arc::new(conf) } + Err(e) => error!("config has errors: {e:?}"), } } } -- cgit v1.2.3-70-g09d2