Skip to content

Commit

Permalink
Fix another panic in debounce module related to move events
Browse files Browse the repository at this point in the history
  • Loading branch information
dfaust committed Nov 19, 2016
1 parent 6f58cce commit b124c36
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 11 additions & 2 deletions src/debounce/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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!();
}
Expand Down
36 changes: 36 additions & 0 deletions tests/debounce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit b124c36

Please sign in to comment.