From 230f708ecbb64cb7aa1e4569ffff630b3e77a959 Mon Sep 17 00:00:00 2001 From: Mityno Date: Sat, 21 Nov 2026 12:07:49 +0100 Subject: [PATCH 1/5] fix: Fix WSL auto-rebuild by switching Watcher depending on the fs --- objdiff-cli/src/cmd/diff.rs | 4 +- objdiff-core/src/build/watcher.rs | 154 +++++++++++++++++++++++------- objdiff-gui/src/app.rs | 4 +- 3 files changed, 121 insertions(+), 41 deletions(-) diff --git a/objdiff-cli/src/cmd/diff.rs b/objdiff-cli/src/cmd/diff.rs index 7cf4edc8..6dcec1c3 100644 --- a/objdiff-cli/src/cmd/diff.rs +++ b/objdiff-cli/src/cmd/diff.rs @@ -24,7 +24,7 @@ use objdiff_core::{ bindings::diff::DiffResult, build::{ BuildConfig, BuildStatus, - watcher::{Watcher, create_watcher}, + watcher::{AnyDebouncer, create_watcher}, }, config::{ ProjectConfig, ProjectObject, ProjectObjectMetadata, ProjectOptions, apply_project_options, @@ -271,7 +271,7 @@ pub struct AppState { pub prev_obj: Option<(Object, ObjectDiff)>, pub reload_time: Option, pub time_format: Vec>, - pub watcher: Option, + pub watcher: Option, pub modified: Arc, pub diff_obj_config: DiffObjConfig, pub mapping_config: MappingConfig, diff --git a/objdiff-core/src/build/watcher.rs b/objdiff-core/src/build/watcher.rs index f9f8cf9f..db560464 100644 --- a/objdiff-core/src/build/watcher.rs +++ b/objdiff-core/src/build/watcher.rs @@ -1,6 +1,6 @@ use std::{ fs, - path::{Path, PathBuf}, + path::{Component, Path, PathBuf, Prefix}, sync::{ Arc, atomic::{AtomicBool, Ordering}, @@ -13,10 +13,33 @@ use globset::GlobSet; use notify::RecursiveMode; use notify_debouncer_full::{DebounceEventResult, new_debouncer_opt}; -pub type Watcher = notify_debouncer_full::Debouncer< - notify::RecommendedWatcher, - notify_debouncer_full::RecommendedCache, ->; +pub enum AnyDebouncer { + NativeDebouncer( + notify_debouncer_full::Debouncer< + notify::RecommendedWatcher, + notify_debouncer_full::RecommendedCache, + >, + ), + NetworkFSDebouncer( + notify_debouncer_full::Debouncer, + ), +} + +impl AnyDebouncer { + pub fn watch(&mut self, path: impl AsRef, mode: RecursiveMode) -> notify::Result<()> { + match self { + Self::NativeDebouncer(d) => d.watch(path, mode), + Self::NetworkFSDebouncer(d) => d.watch(path, mode), + } + } + + pub fn unwatch(&mut self, path: impl AsRef) -> notify::Result<()> { + match self { + Self::NativeDebouncer(d) => d.unwatch(path), + Self::NetworkFSDebouncer(d) => d.unwatch(path), + } + } +} pub struct WatcherState { pub config_path: Option, @@ -25,52 +48,109 @@ pub struct WatcherState { pub patterns: GlobSet, } +pub fn is_win_networkfs_path(path: &Path) -> bool { + let mut components = path.components(); + let first_component = components.next().expect("Path should not be empty"); + match first_component { + Component::Prefix(prefix) => match prefix.kind() { + Prefix::VerbatimUNC(_, _) => true, + _ => false, + }, + _ => panic!("Path should have a prefix (use canonicalize)"), + } +} + pub fn create_watcher( modified: Arc, project_dir: &Path, patterns: GlobSet, ignore_patterns: GlobSet, waker: Waker, -) -> notify::Result { +) -> notify::Result { let base_dir = fs::canonicalize(project_dir)?; let base_dir_clone = base_dir.clone(); let timeout = Duration::from_millis(200); let config = notify::Config::default().with_poll_interval(Duration::from_secs(2)); - let mut debouncer = new_debouncer_opt( - timeout, - None, - move |result: DebounceEventResult| match result { - Ok(events) => { - let mut any_match = false; - for event in events.iter() { - if !matches!( - event.kind, - notify::EventKind::Modify(..) - | notify::EventKind::Create(..) - | notify::EventKind::Remove(..) - ) { + let handler = move |result: DebounceEventResult| match result { + Ok(events) => { + let mut any_match = false; + for event in events.iter() { + if !matches!( + event.kind, + notify::EventKind::Modify(..) + | notify::EventKind::Create(..) + | notify::EventKind::Remove(..) + ) { + continue; + } + for path in &event.paths { + let Ok(path) = path.strip_prefix(&base_dir_clone) else { continue; + }; + if patterns.is_match(path) && !ignore_patterns.is_match(path) { + log::debug!("File modified: {}", path.display()); + any_match = true; } - for path in &event.paths { - let Ok(path) = path.strip_prefix(&base_dir_clone) else { - continue; - }; - if patterns.is_match(path) && !ignore_patterns.is_match(path) { - log::debug!("File modified: {}", path.display()); - any_match = true; - } - } - } - if any_match { - modified.store(true, Ordering::Relaxed); - waker.wake_by_ref(); } } - Err(errors) => errors.iter().for_each(|e| log::error!("Watch error: {e:?}")), - }, - notify_debouncer_full::RecommendedCache::new(), - config, - )?; + if any_match { + modified.store(true, Ordering::Relaxed); + waker.wake_by_ref(); + } + } + Err(errors) => errors.iter().for_each(|e| { + let path_is_ignored = e.paths.iter().all(|absolute_path| { + let Ok(path) = absolute_path.strip_prefix(&base_dir_clone) else { + return false; + }; + ignore_patterns.is_match(path) + }); + // Don't directly report watch errors for path that are ignored + if path_is_ignored { + log::debug!("Watch error (ignored path) : {e:?}"); + return; + } + log::error!("Watch error: {e:?}"); + }), + }; + + let mut debouncer; + // On Windows (only), check if base_dir is inside a network fs, if so switch to polling watcher + #[cfg(windows)] + { + if is_win_networkfs_path(base_dir.as_path()) { + // Use more frequent polling to compensate the slow polls + let poll_config = config.with_poll_interval(Duration::from_secs(1)); + log::debug!("Using NetworkFS debouncer"); + debouncer = AnyDebouncer::NetworkFSDebouncer(new_debouncer_opt( + timeout, + None, + handler, + notify_debouncer_full::NoCache::new(), + poll_config, + )?); + } else { + log::debug!("Using Native debouncer"); + debouncer = AnyDebouncer::NativeDebouncer(new_debouncer_opt( + timeout, + None, + handler, + notify_debouncer_full::RecommendedCache::new(), + config, + )?); + } + } + #[cfg(not(windows))] + { + debouncer = AnyDebouncer::NativeDebouncer(new_debouncer_opt( + timeout, + None, + handler, + notify_debouncer_full::RecommendedCache::new(), + config, + )?); + } + debouncer.watch(base_dir, RecursiveMode::Recursive)?; Ok(debouncer) } diff --git a/objdiff-gui/src/app.rs b/objdiff-gui/src/app.rs index 0c2e061d..9f94ffa7 100644 --- a/objdiff-gui/src/app.rs +++ b/objdiff-gui/src/app.rs @@ -15,7 +15,7 @@ use egui::text::LayoutJob; use filetime::FileTime; use globset::Glob; use objdiff_core::{ - build::watcher::{Watcher, create_watcher}, + build::watcher::{AnyDebouncer, create_watcher}, config::{ ProjectConfig, ProjectConfigInfo, ProjectObject, ScratchConfig, apply_project_options, build_globset, default_ignore_patterns, default_watch_patterns, @@ -461,7 +461,7 @@ pub struct App { view_state: ViewState, state: AppStateRef, modified: Arc, - watcher: Option, + watcher: Option, app_path: Option, relaunch_path: Rc>>, should_relaunch: bool, From 32f59941ba40c46deacc4f9f391c53f62875de7d Mon Sep 17 00:00:00 2001 From: Mityno Date: Sat, 21 Nov 2026 12:22:16 +0100 Subject: [PATCH 2/5] fix: Remove unused function --- objdiff-core/src/build/watcher.rs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/objdiff-core/src/build/watcher.rs b/objdiff-core/src/build/watcher.rs index db560464..2a43dd4b 100644 --- a/objdiff-core/src/build/watcher.rs +++ b/objdiff-core/src/build/watcher.rs @@ -32,13 +32,6 @@ impl AnyDebouncer { Self::NetworkFSDebouncer(d) => d.watch(path, mode), } } - - pub fn unwatch(&mut self, path: impl AsRef) -> notify::Result<()> { - match self { - Self::NativeDebouncer(d) => d.unwatch(path), - Self::NetworkFSDebouncer(d) => d.unwatch(path), - } - } } pub struct WatcherState { From 8ba0def709fe833b98ef2c9ffb3aac839ae2b5f0 Mon Sep 17 00:00:00 2001 From: Mityno Date: Sat, 21 Nov 2026 12:37:20 +0100 Subject: [PATCH 3/5] fix: Use matches as suggested by clippy --- objdiff-core/src/build/watcher.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/objdiff-core/src/build/watcher.rs b/objdiff-core/src/build/watcher.rs index 2a43dd4b..2f4db585 100644 --- a/objdiff-core/src/build/watcher.rs +++ b/objdiff-core/src/build/watcher.rs @@ -45,10 +45,7 @@ pub fn is_win_networkfs_path(path: &Path) -> bool { let mut components = path.components(); let first_component = components.next().expect("Path should not be empty"); match first_component { - Component::Prefix(prefix) => match prefix.kind() { - Prefix::VerbatimUNC(_, _) => true, - _ => false, - }, + Component::Prefix(prefix) => matches!(prefix.kind(), Prefix::VerbatimUNC(_, _)), _ => panic!("Path should have a prefix (use canonicalize)"), } } From 0562bf78ca0bd8f25d7676eddd98bfeff67d71c0 Mon Sep 17 00:00:00 2001 From: Mityno Date: Sat, 21 Nov 2026 13:06:22 +0100 Subject: [PATCH 4/5] feat: Improve is_win_networkfs_path to return a Result instead of raw bool --- objdiff-core/src/build/watcher.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/objdiff-core/src/build/watcher.rs b/objdiff-core/src/build/watcher.rs index 2f4db585..5e560c42 100644 --- a/objdiff-core/src/build/watcher.rs +++ b/objdiff-core/src/build/watcher.rs @@ -1,4 +1,5 @@ use std::{ + error::Error, fs, path::{Component, Path, PathBuf, Prefix}, sync::{ @@ -41,12 +42,17 @@ pub struct WatcherState { pub patterns: GlobSet, } -pub fn is_win_networkfs_path(path: &Path) -> bool { +pub fn is_win_networkfs_path(path: &Path) -> Result> { let mut components = path.components(); - let first_component = components.next().expect("Path should not be empty"); + let Some(first_component) = components.next() else { + return Err("Path should not be empty")?; + }; match first_component { - Component::Prefix(prefix) => matches!(prefix.kind(), Prefix::VerbatimUNC(_, _)), - _ => panic!("Path should have a prefix (use canonicalize)"), + Component::Prefix(prefix) => Ok(matches!(prefix.kind(), Prefix::VerbatimUNC(..))), + _ => { + log::error!("Path should have a prefix (use canonicalize)"); + Err("Path should have a prefix (use canonicalize)")? + } } } @@ -108,7 +114,8 @@ pub fn create_watcher( // On Windows (only), check if base_dir is inside a network fs, if so switch to polling watcher #[cfg(windows)] { - if is_win_networkfs_path(base_dir.as_path()) { + let use_polling = is_win_networkfs_path(base_dir.as_path()).unwrap_or_default(); + if use_polling { // Use more frequent polling to compensate the slow polls let poll_config = config.with_poll_interval(Duration::from_secs(1)); log::debug!("Using NetworkFS debouncer"); From 172f707fc86bdd5fd18c1e7293627d0434d737f9 Mon Sep 17 00:00:00 2001 From: Mityno Date: Sat, 21 Nov 2026 13:11:48 +0100 Subject: [PATCH 5/5] fix: Remove extraneous log --- objdiff-core/src/build/watcher.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/objdiff-core/src/build/watcher.rs b/objdiff-core/src/build/watcher.rs index 5e560c42..8cb1c928 100644 --- a/objdiff-core/src/build/watcher.rs +++ b/objdiff-core/src/build/watcher.rs @@ -49,10 +49,7 @@ pub fn is_win_networkfs_path(path: &Path) -> Result> { }; match first_component { Component::Prefix(prefix) => Ok(matches!(prefix.kind(), Prefix::VerbatimUNC(..))), - _ => { - log::error!("Path should have a prefix (use canonicalize)"); - Err("Path should have a prefix (use canonicalize)")? - } + _ => Err("Path should have a prefix (use canonicalize)")?, } }