Skip to content

Commit

Permalink
[events] Add Flag::Rescan and improve Any/Other documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
passcod committed Apr 20, 2019
1 parent 1997721 commit a718eab
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/debounce/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl EventTx {
} => {
match (event.path, event.op, event.cookie) {
(None, Ok(op::Op::RESCAN), None) => {
tx.send(Event::new(EventKind::Other).set_info("rescan"))
tx.send(Event::new(EventKind::Other).set_flag(event::Flag::Rescan))
.ok();
}
(Some(path), Ok(op), cookie) => {
Expand All @@ -103,7 +103,7 @@ impl EventTx {
EventTx::DebouncedTx { ref tx } => {
match (event.path, event.op, event.cookie) {
(None, Ok(op::Op::RESCAN), None) => {
tx.send(Event::new(EventKind::Other).set_info("rescan"))
tx.send(Event::new(EventKind::Other).set_flag(event::Flag::Rescan))
.ok();
}
(Some(_path), Ok(_op), _cookie) => {
Expand Down Expand Up @@ -253,7 +253,7 @@ impl Debounce {
pub fn event(&mut self, path: PathBuf, mut op: op::Op, cookie: Option<u32>) {
if op.contains(op::Op::RESCAN) {
self.tx
.send(Event::new(EventKind::Other).set_info("rescan"))
.send(Event::new(EventKind::Other).set_flag(event::Flag::Rescan))
.ok();
}

Expand Down
24 changes: 22 additions & 2 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ pub enum EventKind {
/// This variant should be used as the "else" case when mapping native kernel bitmasks or
/// bitmaps, such that if the mask is ever extended with new event types the backend will not
/// gain bugs due to not matching new unknown event types.
///
/// This variant is also the default variant used when Notify is in "imprecise" mode.
Any,

/// An event describing non-mutating access operations on files.
Expand All @@ -213,7 +215,7 @@ pub enum EventKind {
/// other such event that is about accessing files, folders, or other structures rather than
/// mutating them.
///
/// Only backends with the `EmitOnAccess` capability will generate these.
/// Only some platforms are capable of generating these.
Access(AccessKind),

/// An event describing creation operations on files.
Expand All @@ -240,7 +242,8 @@ pub enum EventKind {

/// An event not fitting in any of the above four categories.
///
/// This may be used for meta-events about the watch itself, but generally should not be used.
/// This may be used for meta-events about the watch itself. In "imprecise" mode, it is, along
/// with `Any`, the only other event generated.
Other,
}

Expand Down Expand Up @@ -276,6 +279,14 @@ impl EventKind {
_ => false,
}
}

/// Indicates whether an event is an Other variant.
pub fn is_other(&self) -> bool {
match *self {
EventKind::Other => true,
_ => false
}
}
}

impl Default for EventKind {
Expand Down Expand Up @@ -390,6 +401,15 @@ pub enum Flag {
///
/// Ongoing event notices are a runtime option and are disabled by default.
Ongoing,

/// Rescan notices are emitted by some platforms (and may also be emitted by Notify itself).
/// They indicate either a lapse in the events or a change in the filesystem such that events
/// received so far can no longer be relied on to represent the state of the filesystem now.
///
/// An application that simply reacts to file changes may not care about this. An application
/// that keeps an in-memory representation of the filesystem will need to care, and will need
/// to refresh that representation directly from the filesystem.
Rescan,
}

/// Additional information on the event.
Expand Down

0 comments on commit a718eab

Please sign in to comment.