From b124c36eca78852b47c2cd58b86cce4016280fd5 Mon Sep 17 00:00:00 2001 From: Daniel Faust Date: Sat, 19 Nov 2016 17:04:03 +0100 Subject: [PATCH] Fix another panic in debounce module related to move events Fixes #100 --- CHANGELOG.md | 3 ++- src/debounce/mod.rs | 13 +++++++++++-- tests/debounce.rs | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a49b470..2eacfb4e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,10 @@ ## 3.0.1 -- FIX: \[macOS\] Fix panic in debounce module related to move events. [#99] +- FIX: \[macOS\] Fix two panics in debounce module related to move events. [#99], [#100] [#99]: https://github.com/passcod/notify/issues/99 +[#100]: https://github.com/passcod/notify/issues/100 ## 3.0.0 diff --git a/src/debounce/mod.rs b/src/debounce/mod.rs index 4e5ff7b6..871b689f 100644 --- a/src/debounce/mod.rs +++ b/src/debounce/mod.rs @@ -114,7 +114,8 @@ impl Debounce { restart_timer(timer_id, path, &mut self.timer); } _ => { - // this code can only be reached with fsevents because it may repeat a rename event for a file that has been renamed before + // this code can only be reached with fsevents because it may + // repeat a rename event for a file that has been renamed before // (https://github.com/passcod/notify/issues/99) } } @@ -146,7 +147,15 @@ impl Debounce { *operation = Some(op::REMOVE); restart_timer(timer_id, path, &mut self.timer); } - // renaming a deleted file is impossible + Some(op::REMOVE) => { + + // file has been renamed and then removed / keep write event + // this code can only be reached with fsevents because it may + // repeat a rename event for a file that has been renamed before + // (https://github.com/passcod/notify/issues/100) + restart_timer(timer_id, path, &mut self.timer); + } + // CLOSE_WRITE and RESCAN aren't tracked by operations_buffer _ => { unreachable!(); } diff --git a/tests/debounce.rs b/tests/debounce.rs index b6c0cbd7..84c702b2 100644 --- a/tests/debounce.rs +++ b/tests/debounce.rs @@ -356,6 +356,42 @@ fn create_rename_write_create() { // fsevents ]); } +// https://github.com/passcod/notify/issues/100 +#[test] +fn create_rename_remove_create() { // fsevents + let tdir = TempDir::new("temp_dir").expect("failed to create temporary directory"); + + sleep_macos(10); + + let (tx, rx) = mpsc::channel(); + let mut watcher: RecommendedWatcher = Watcher::new(tx, Duration::from_secs(DELAY_S)).expect("failed to create debounced watcher"); + watcher.watch(tdir.mkpath("."), RecursiveMode::Recursive).expect("failed to watch directory"); + + tdir.create("file1"); + + sleep_macos(35_000); + + tdir.rename("file1", "file2"); + tdir.remove("file2"); + sleep_macos(10); + tdir.create("file3"); + + if cfg!(target_os="macos") { + assert_eq!(recv_events_debounced(&rx), vec![ + DebouncedEvent::Create(tdir.mkpath("file1")), + DebouncedEvent::NoticeRemove(tdir.mkpath("file1")), + DebouncedEvent::NoticeRemove(tdir.mkpath("file2")), + // DebouncedEvent::Remove(tdir.mkpath("file1")), BUG: There should be a remove event for file1 + DebouncedEvent::Remove(tdir.mkpath("file2")), + DebouncedEvent::Create(tdir.mkpath("file3")), + ]); + } else { + assert_eq!(recv_events_debounced(&rx), vec![ + DebouncedEvent::Create(tdir.mkpath("file3")), + ]); + } +} + #[test] fn write_rename_file() { let tdir = TempDir::new("temp_dir").expect("failed to create temporary directory");