From 456b2ddcd569782748e0f42533f247512a6425fe Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Mon, 3 Jul 2023 14:33:25 -0700 Subject: [PATCH] config: Ignore some filesystem events (#125) APIs like inotify can provide notification for some events that don't change the contents of a file. It makes sense to ignore those here, even if the expected way to write is through the config API. This reduces the number of events on the directory received by a single `:w` in vim from 12 to 8. And reduces a `touch` from 2 events to 1. Atomic writes through the config API only result in 1 event per-setting, before and after this change. --- cosmic-config/src/lib.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/cosmic-config/src/lib.rs b/cosmic-config/src/lib.rs index a7b2be63..20e03a55 100644 --- a/cosmic-config/src/lib.rs +++ b/cosmic-config/src/lib.rs @@ -2,7 +2,10 @@ use iced_futures::futures::channel::mpsc; #[cfg(feature = "subscription")] use iced_futures::subscription; -use notify::{RecommendedWatcher, Watcher}; +use notify::{ + event::{EventKind, ModifyKind}, + RecommendedWatcher, Watcher, +}; use serde::{de::DeserializeOwned, Serialize}; use std::{ borrow::Cow, @@ -137,8 +140,16 @@ impl Config { let mut watcher = notify::recommended_watcher(move |event_res: Result| { // println!("{:#?}", event_res); - match event_res { + match &event_res { Ok(event) => { + match &event.kind { + EventKind::Access(_) | EventKind::Modify(ModifyKind::Metadata(_)) => { + // Data not mutated + return; + } + _ => {} + } + let mut keys = Vec::new(); for path in event.paths.iter() { match path.strip_prefix(&watch_config.user_path) {