Skip to content

Commit

Permalink
Make ErrorKind::PathNotFound consistent on inotify
Browse files Browse the repository at this point in the history
Before this patch, watching a nonexistent path using inotify backend
would give an `ErrorKind::Io` variant. This behavior was inconsistent
with other backends.

Signed-off-by: y5c4l3 <y5c4l3@proton.me>
  • Loading branch information
y5c4l3 authored and 0xpr03 committed Jul 14, 2024
1 parent 948ca73 commit 96dec74
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions notify/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ impl Error {
Self::new(ErrorKind::Io(err))
}

/// Similar to [`Error::io`], but specifically handles [`io::ErrorKind::NotFound`].
pub fn io_watch(err: io::Error) -> Self {
if err.kind() == io::ErrorKind::NotFound {
Self::path_not_found()
} else {
Self::io(err)
}
}

/// Creates a new "path not found" error.
pub fn path_not_found() -> Self {
Self::new(ErrorKind::PathNotFound)
Expand Down
2 changes: 1 addition & 1 deletion notify/src/inotify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ impl EventLoop {
fn add_watch(&mut self, path: PathBuf, is_recursive: bool, mut watch_self: bool) -> Result<()> {
// If the watch is not recursive, or if we determine (by stat'ing the path to get its
// metadata) that the watched path is not a directory, add a single path watch.
if !is_recursive || !metadata(&path).map_err(Error::io)?.is_dir() {
if !is_recursive || !metadata(&path).map_err(Error::io_watch)?.is_dir() {
return self.add_single_watch(path, false, true);
}

Expand Down

0 comments on commit 96dec74

Please sign in to comment.