Skip to content

Commit

Permalink
Only check for ENOSPC on inotify_add_watch
Browse files Browse the repository at this point in the history
According to the inotify documentation, the only function that returns
ENOSPC is `inotify_add_watch`, so this moves the check for this error
code to the `inotify.add_watch()` call point. This makes sure someone
using a different watcher like PollWatcher on linux won't reinterpret
this error.

Also, this uses `libc::ENOSPC` instead of `28` because it's easier to
interpret from the inotify documentation.
  • Loading branch information
erickt committed Jun 4, 2021
1 parent 0e80a12 commit 51c7bd7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
5 changes: 0 additions & 5 deletions src/error.rs
Expand Up @@ -78,11 +78,6 @@ impl Error {

/// Creates a new i/o Error from a stdlib `io::Error`.
pub fn io(err: io::Error) -> Self {
// do not report inotify limits as "no more space" on linux #266
#[cfg(target_os = "linux")]
if err.raw_os_error() == Some(28) {
return Self::new(ErrorKind::MaxFilesWatch);
}
Self::new(ErrorKind::Io(err))
}

Expand Down
9 changes: 8 additions & 1 deletion src/inotify.rs
Expand Up @@ -481,7 +481,14 @@ impl EventLoop {

if let Some(ref mut inotify) = self.inotify {
match inotify.add_watch(&path, watchmask) {
Err(e) => Err(Error::io(e)),
Err(e) => {
// do not report inotify limits as "no more space" on linux #266
if err.raw_os_error() == Some(libc::ENOSPC) {
Err(Error::new(ErrorKind::MaxFilesWatch))
} else {
Err(Error::io(e))
}
}
Ok(w) => {
watchmask.remove(WatchMask::MASK_ADD);
self.watches
Expand Down

0 comments on commit 51c7bd7

Please sign in to comment.