From 69d8d741218141d41172e51646053e8411c3e0c6 Mon Sep 17 00:00:00 2001 From: Daniel Faust Date: Fri, 25 Nov 2016 16:31:35 +0100 Subject: [PATCH] Skip over event sequences that should be impossible but aren't with fsevents Fixes #101 --- CHANGELOG.md | 3 ++- src/debounce/mod.rs | 37 ++++++++++++++++++++++++++----------- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2eacfb4e..bb6e2093 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,10 +2,11 @@ ## 3.0.1 -- FIX: \[macOS\] Fix two panics in debounce module related to move events. [#99], [#100] +- FIX: \[macOS\] Fix multiple panics in debounce module related to move events. [#99], [#100], [#101] [#99]: https://github.com/passcod/notify/issues/99 [#100]: https://github.com/passcod/notify/issues/100 +[#101]: https://github.com/passcod/notify/issues/101 ## 3.0.0 diff --git a/src/debounce/mod.rs b/src/debounce/mod.rs index 4e2fcbe5..334ed43e 100644 --- a/src/debounce/mod.rs +++ b/src/debounce/mod.rs @@ -101,7 +101,7 @@ impl Debounce { if let Some(&mut (ref mut operation, ref mut from_path, ref mut timer_id)) = op_buf.get_mut(self.rename_path.as_ref().unwrap()) { if op != op::RENAME || self.rename_cookie.is_none() || - self.rename_cookie != cookie { + self.rename_cookie != cookie { if self.rename_path.as_ref().unwrap().exists() { match *operation { Some(op::RENAME) if from_path.is_none() => { @@ -207,8 +207,9 @@ impl Debounce { Some(op::CHMOD) | // file can't be renamed to before being created - // (repetitions are removed anyway) - Some(op::RENAME) => { unreachable!(); } + // (repetitions are removed anyway), + // but with fsevents everything is possible + Some(op::RENAME) => {} // file has been removed and is now being re-created; // convert this to a write event @@ -254,7 +255,10 @@ impl Debounce { restart_timer(timer_id, path.clone(), &mut self.timer); } - // writing to a deleted file is impossible + // writing to a deleted file is impossible, + // but with fsevents everything is possible + Some(op::REMOVE) => {} + _ => { unreachable!(); } } } @@ -281,21 +285,25 @@ impl Debounce { restart_timer(timer_id, path.clone(), &mut self.timer); } - // changing a deleted file is impossible + // changing a deleted file is impossible, + // but with fsevents everything is possible + Some(op::REMOVE) => {} + _ => { unreachable!(); } } } if op.contains(op::RENAME) { + // unwrap is safe because rename_path is Some if self.rename_path.is_some() && self.rename_cookie.is_some() && - self.rename_cookie == cookie { + self.rename_cookie == cookie && + op_buf.contains_key(self.rename_path.as_ref().unwrap()) { // This is the second part of a rename operation, the old path is stored in the // rename_path variable. - // Unwrapping is safe because rename_path is Some. + // unwrap is safe because rename_path is Some and op_buf contains rename_path let (from_operation, from_from_path, from_timer_id) = - op_buf.remove(self.rename_path.as_ref().unwrap()) - .expect("rename_path is set but not present in operations_buffer"); + op_buf.remove(self.rename_path.as_ref().unwrap()).unwrap(); // ignore running timer of removed operations_buffer entry if let Some(from_timer_id) = from_timer_id { @@ -332,7 +340,10 @@ impl Debounce { restart_timer(timer_id, path.clone(), &mut self.timer); } - // file can't be renamed after beeing removed + // file can't be renamed after beeing removed, + // but with fsevents everything is possible + Some(op::REMOVE) => {} + _ => { unreachable!(); } } @@ -374,7 +385,11 @@ impl Debounce { restart_timer(timer_id, path.clone(), &mut self.timer); } - // renaming a deleted file is impossible + // renaming a deleted file should be impossible, + // but with fsevents everything is possible + // (https://github.com/passcod/notify/issues/101) + Some(op::REMOVE) => {} + _ => { unreachable!(); } } }