Skip to content

Commit

Permalink
preservev IO errors in PollWatcher
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelcolvin authored and 0xpr03 committed Sep 29, 2024
1 parent 2cd5aea commit 146b1bd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
15 changes: 12 additions & 3 deletions notify-types/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,10 @@ pub enum RemoveKind {
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))]
#[cfg_attr(all(feature = "serde", not(feature = "serialization-compat-6")), serde(tag = "type"))]
#[cfg_attr(
all(feature = "serde", not(feature = "serialization-compat-6")),
serde(tag = "type")
)]
pub enum EventKind {
/// The catch-all event kind, for unsupported/unknown events.
///
Expand Down Expand Up @@ -300,7 +303,10 @@ pub struct Event {
/// The `EventKind::Any` 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.
#[cfg_attr(all(feature = "serde", not(feature = "serialization-compat-6")), serde(flatten))]
#[cfg_attr(
all(feature = "serde", not(feature = "serialization-compat-6")),
serde(flatten)
)]
pub kind: EventKind,

/// Paths the event is about, if known.
Expand Down Expand Up @@ -478,7 +484,10 @@ impl EventAttributes {
/// particular ways.
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
#[cfg_attr(all(feature = "serde", not(feature = "serialization-compat-6")), serde(rename_all = "camelCase"))]
#[cfg_attr(
all(feature = "serde", not(feature = "serialization-compat-6")),
serde(rename_all = "camelCase")
)]
pub enum Flag {
/// 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
Expand Down
37 changes: 18 additions & 19 deletions notify/src/poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ mod data {
// FIXME: Can we always allow to watch a path, even file not
// found at this path?
if let Err(e) = fs::metadata(&root) {
data_builder.emitter.emit_io_err(e, &root);
data_builder.emitter.emit_io_err(e, Some(&root));
return None;
}

Expand Down Expand Up @@ -259,25 +259,19 @@ mod data {
.follow_links(true)
.max_depth(Self::dir_scan_depth(is_recursive))
.into_iter()
//
// QUESTION: should we ignore IO Error?
//
// current implementation ignore some IO error, e.g.,
//
// - `.filter_map(|entry| entry.ok())`
// - all read error when hashing
//
// but the code also interest with `fs::metadata()` error and
// propagate to event handler. It may not consistent.
//
// FIXME: Should we emit all IO error events? Or ignore them all?
.filter_map(|entry_res| match entry_res {
Ok(entry) => Some(entry),
Err(err) => {
log::warn!("walkdir error scanning {err:?}");
let crate_err =
crate::Error::new(crate::ErrorKind::Generic(err.to_string()));
data_builder.emitter.emit(Err(crate_err));
if let Some(io_error) = err.io_error() {
// clone an io::Error, so we have to create a new one.
let new_io_error = io::Error::new(io_error.kind(), err.to_string());
data_builder.emitter.emit_io_err(new_io_error, err.path());
} else {
let crate_err =
crate::Error::new(crate::ErrorKind::Generic(err.to_string()));
data_builder.emitter.emit(Err(crate_err));
}
None
}
})
Expand All @@ -298,7 +292,7 @@ mod data {
Err(e) => {
// emit event.
let path = entry.into_path();
data_builder.emitter.emit_io_err(e, path);
data_builder.emitter.emit_io_err(e, Some(path));

None
}
Expand Down Expand Up @@ -455,12 +449,17 @@ mod data {
}

/// Emit io error event.
fn emit_io_err<E, P>(&self, err: E, path: P)
fn emit_io_err<E, P>(&self, err: E, path: Option<P>)
where
E: Into<io::Error>,
P: Into<PathBuf>,
{
self.emit(Err(crate::Error::io(err.into()).add_path(path.into())))
let e = crate::Error::io(err.into());
if let Some(path) = path {
self.emit(Err(e.add_path(path.into())));
} else {
self.emit(Err(e));
}
}
}
}
Expand Down

0 comments on commit 146b1bd

Please sign in to comment.