-
Notifications
You must be signed in to change notification settings - Fork 228
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
} | ||
|
||
|
@@ -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? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
} | ||
}) | ||
|
@@ -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 | ||
} | ||
|
@@ -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)); | ||
} | ||
} | ||
} | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
.