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

Only check for ENOSPC on inotify_add_watch #330

Merged
merged 1 commit into from
Jun 8, 2021
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
Only check for ENOSPC on inotify_add_watch
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
commit 1749566cf56e01b155f06ba68d1b787817d12df5
5 changes: 0 additions & 5 deletions src/error.rs
Original file line number Diff line number Diff line change
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
11 changes: 9 additions & 2 deletions src/inotify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//! will return events for the directory itself, and for files inside the directory.

use super::event::*;
use super::{Config, Error, EventFn, RecursiveMode, Result, Watcher};
use super::{Config, Error, ErrorKind, EventFn, RecursiveMode, Result, Watcher};
use crossbeam_channel::{bounded, unbounded, Sender};
use inotify as inotify_sys;
use inotify_sys::{EventMask, Inotify, WatchDescriptor, WatchMask};
Expand Down 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 e.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