From edf9a4f29d0862fd7b378cdac01fef64db9f82a3 Mon Sep 17 00:00:00 2001 From: Tony <68118705+Legend-Master@users.noreply.github.com> Date: Wed, 24 Apr 2024 16:50:12 +0800 Subject: [PATCH] fix(fs): missing debouncer rename cache (#1245) * Fix missing debouncer rename cache * Add change file * Format --- .changes/watcher-debouncer-rename.md | 5 +++++ plugins/fs/src/watcher.rs | 7 ++++--- 2 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 .changes/watcher-debouncer-rename.md diff --git a/.changes/watcher-debouncer-rename.md b/.changes/watcher-debouncer-rename.md new file mode 100644 index 00000000..a03bda6d --- /dev/null +++ b/.changes/watcher-debouncer-rename.md @@ -0,0 +1,5 @@ +--- +"fs": patch +--- + +Fixes `RenameMode::From` and `RenameMode::To` never getting converted to `RenameMode::Both` when using `watch` with a debounce on Windows diff --git a/plugins/fs/src/watcher.rs b/plugins/fs/src/watcher.rs index 920b86e0..986aebff 100644 --- a/plugins/fs/src/watcher.rs +++ b/plugins/fs/src/watcher.rs @@ -100,7 +100,7 @@ pub async fn watch( )?); } - let mode = if options.recursive { + let recursive_mode = if options.recursive { RecursiveMode::Recursive } else { RecursiveMode::NonRecursive @@ -110,7 +110,8 @@ pub async fn watch( let (tx, rx) = channel(); let mut debouncer = new_debouncer(Duration::from_millis(delay), None, tx)?; for path in &resolved_paths { - debouncer.watcher().watch(path.as_ref(), mode)?; + debouncer.watcher().watch(path.as_ref(), recursive_mode)?; + debouncer.cache().add_root(path, recursive_mode); } watch_debounced(on_event, rx); WatcherKind::Debouncer(debouncer) @@ -118,7 +119,7 @@ pub async fn watch( let (tx, rx) = channel(); let mut watcher = RecommendedWatcher::new(tx, Config::default())?; for path in &resolved_paths { - watcher.watch(path.as_ref(), mode)?; + watcher.watch(path.as_ref(), recursive_mode)?; } watch_raw(on_event, rx); WatcherKind::Watcher(watcher)