Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve IO errors in PollWatcher #634

Merged
merged 1 commit into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is just running cargo fmt.

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?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment was left behind when #507 started returning IO Errors.

//
// 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