From ed865d903994befeff45c9126be8439942b3a0ca Mon Sep 17 00:00:00 2001 From: Matt Green Date: Fri, 28 Oct 2016 08:58:15 -0400 Subject: [PATCH] Linux: fix logspam from inotify's notification volume --- src/main.rs | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 99e216b..07e951a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,6 +29,7 @@ mod notification_filter; mod process; mod watcher; +use std::collections::HashMap; use std::env; use std::sync::mpsc::{channel, Receiver}; use std::time::Duration; @@ -161,6 +162,7 @@ fn wait(rx: &Receiver, filter: &NotificationFilter) -> Option> { let mut paths = vec![]; + let mut cache = HashMap::new(); loop { select! { @@ -169,8 +171,17 @@ fn wait(rx: &Receiver, let e = ev.expect("error when reading event"); if let Some(ref path) = e.path { - if !filter.is_excluded(path) { - paths.push(path.to_owned()); + if cache.contains_key(path) { + continue; + } + + let excluded = filter.is_excluded(path); + + let p = path.to_owned(); + cache.insert(p.clone(), excluded); + + if !excluded { + paths.push(p); break; } } @@ -187,7 +198,18 @@ fn wait(rx: &Receiver, } if let Some(ref path) = e.path { - paths.push(path.to_owned()); + if cache.contains_key(path) { + continue; + } + + let excluded = filter.is_excluded(path); + + let p = path.to_owned(); + cache.insert(p.clone(), excluded); + + if !excluded { + paths.push(p); + } } }