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.
This commit is contained in:
Ian Douglas Scott 2023-07-03 14:33:25 -07:00 committed by GitHub
parent b5a5e01de4
commit 456b2ddcd5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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<notify::Event, notify::Error>| {
// 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) {