From bcc135761db881fd937767788a0d0480bb1b1f31 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Mon, 20 Nov 2023 11:25:50 +0100 Subject: fix file watch path --- src/config.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src/config.rs') diff --git a/src/config.rs b/src/config.rs index be41420..9e7f720 100644 --- a/src/config.rs +++ b/src/config.rs @@ -12,12 +12,14 @@ use std::{ fs::read_to_string, marker::PhantomData, net::SocketAddr, - path::PathBuf, + path::{Path, PathBuf}, sync::Arc, }; #[derive(Debug, Serialize, Deserialize)] pub struct Config { + #[serde(default = "true_default")] + pub watch_config: bool, pub http: Option, pub https: Option, #[serde(default)] @@ -26,6 +28,10 @@ pub struct Config { pub hosts: HashMap, } +fn true_default() -> bool { + true +} + #[derive(Debug, Serialize, Deserialize)] #[serde(default)] pub struct Limits { @@ -157,7 +163,8 @@ where } impl Config { - pub fn load(path: &str) -> anyhow::Result { + pub fn load(path: &Path) -> anyhow::Result { + info!("loading config from {path:?}"); let raw = read_to_string(path).context("reading config file")?; let config: Config = serde_yaml::from_str(&raw).context("parsing config")?; Ok(config) @@ -173,13 +180,13 @@ impl Default for Limits { } } -pub fn setup_file_watch(config_path: String, state: Arc) { +pub fn setup_file_watch(config_path: PathBuf, state: Arc) { std::thread::spawn(move || { let mut inotify = Inotify::init().unwrap(); inotify .watches() .add( - ".", + config_path.parent().unwrap(), WatchMask::MODIFY | WatchMask::CREATE | WatchMask::DELETE, ) .unwrap(); @@ -191,7 +198,6 @@ pub fn setup_file_watch(config_path: String, state: Arc) { for event in events { if event.mask.contains(EventMask::MODIFY) { - info!("reloading config"); match Config::load(&config_path) { Ok(conf) => { let mut r = state.config.blocking_write(); -- cgit v1.2.3-70-g09d2