Once a file (only a single file is being watched) gets modified, the Modify event gets triggered. Any consecutive modifications of the watched file do not result in the Modify event getting triggered. Not sure whether this is an issue with my code or not – help will be appreciated. Here is the code:
let (tx, rx) = mpsc::channel::<notify::Result<notify::Event>>();
let mut watcher =
match notify::RecommendedWatcher::new(tx.clone(), notify::Config::default()) {
Ok(w) => w,
Err(e) => {
eprintln!("Failed to create watcher: {:?}", e);
return;
}
};
if let Err(e) = watcher.watch(
Path::new(&config_path.clone()),
notify::RecursiveMode::Recursive,
) {
eprintln!("Failed to watch config file: {:?}", e);
return;
}
// Block forever, printing out events as they come in
for res in rx {
if let Err(e) = res {
println!("watch error: {:?}", e);
continue;
}
let event = res.unwrap();
println!("event: {:?}", event);
match event.kind {
notify::EventKind::Modify(_) => {
// Refresh config
let config_file = get_file(&config_path);
let mut p = Parser::new(config_file);
let cfg = p.parse();
if let Ok(cfg) = cfg {
let mut config_guard = config.lock().unwrap();
*config_guard = cfg;
println!("Config updated: {:#?}", config_guard);
}
}
_ => {}
}
}
Once a file (only a single file is being watched) gets modified, the
Modifyevent gets triggered. Any consecutive modifications of the watched file do not result in theModifyevent getting triggered. Not sure whether this is an issue with my code or not – help will be appreciated. Here is the code: