From 62f509c0e3d3ef8731269f6fa3f2c222de5e2a00 Mon Sep 17 00:00:00 2001 From: Daniel Collin Date: Fri, 10 Mar 2023 16:45:38 +0100 Subject: [PATCH] Updated to new notify/debouncer --- Cargo.toml | 2 +- src/lib.rs | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 08ee70b..6eb9210 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,6 +19,6 @@ no-timestamps = [] no-unload = [] [dependencies] -notify = "4.0.*" +notify-debouncer-mini = "0.2.0" libloading = "0.7.*" tempfile = "3" diff --git a/src/lib.rs b/src/lib.rs index 465785a..a23f180 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -19,7 +19,7 @@ //! use libloading::Library; -use notify::{RecommendedWatcher, Watcher}; +use notify_debouncer_mini::{notify::*,new_debouncer,DebounceEventResult, Debouncer}; use std::{ env, fs, path::{Path, PathBuf}, @@ -53,10 +53,10 @@ pub struct Lib { /// Contains information about loaded libraries and also tracks search paths and reloading events. pub struct DynamicReload { libs: Vec>, - watcher: Option, + watcher: Option>, shadow_dir: Option, search_paths: Vec, - watch_recv: Receiver, + watch_recv: Receiver, } /// Searching for a shared library can be done in current directory, but can also be allowed to @@ -195,7 +195,7 @@ impl<'a> DynamicReload { parent.to_path_buf() }; - let _ = w.watch(parent_buf, notify::RecursiveMode::NonRecursive); + let _ = w.watcher().watch(&parent_buf, RecursiveMode::NonRecursive); } } // Bump the ref here as we keep one around to keep track of files that needs to be reloaded @@ -248,10 +248,11 @@ impl<'a> DynamicReload { F: Fn(&mut T, UpdateState, Option<&Arc>), { while let Ok(evt) = self.watch_recv.try_recv() { - use notify::DebouncedEvent::*; match evt { - NoticeWrite(ref path) | Write(ref path) | Create(ref path) => { - Self::reload_libs(self, path, update_call, data); + Ok(events) => { + for event in events { + Self::reload_libs(self, &event.path, update_call, data); + } } _ => (), } @@ -452,10 +453,10 @@ impl<'a> DynamicReload { } fn get_watcher( - tx: Sender, + tx: Sender, debounce_duration: Duration, - ) -> Option { - match notify::watcher(tx, debounce_duration) { + ) -> Option> { + match new_debouncer(debounce_duration, None, tx) { Ok(watcher) => Some(watcher), Err(e) => { println!(