Skip to content

Commit 9cd286e

Browse files
authored
Fix fanotify add_path() bug (#263)
Fix an issue in the call to fanotify add_path() which was using low level flags instead of high level flags and ending in an incorrect number of arguments provided error. Testing ======= Run the fs-notify watch command in a linux box. Signed-off-by: Jason Rogena <jason@rogena.me>
1 parent 0f2817a commit 9cd286e

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

src/fs_notify/fanotify_notifier.rs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use tokio_util::sync::CancellationToken;
44
#[cfg(target_os = "linux")]
55
use {
66
super::FsOp,
7-
fanotify::{
8-
high_level::{FanEvent, Fanotify, FanotifyMode},
9-
low_level::{FAN_CLOSE_WRITE, FAN_CREATE, FAN_MODIFY, FAN_MOVE_SELF},
7+
fanotify::high_level::{
8+
FanEvent, Fanotify, FanotifyMode, FAN_ACCESS, FAN_CLOSE, FAN_CLOSE_WRITE,
9+
FAN_EVENT_ON_CHILD, FAN_MODIFY, FAN_ONDIR,
1010
},
1111
nix::poll::{poll, PollFd, PollFlags},
1212
std::os::fd::AsFd,
@@ -20,7 +20,7 @@ pub enum Error {
2020
#[error("The feature '{0}' is unsupported")]
2121
UnsupportedFeature(String),
2222
#[error("An error was thrown by the filesystem notification system: {0}")]
23-
Faotify(String),
23+
Fanotify(String),
2424
#[error("An error was thrown while trying to interract with the notification system")]
2525
Send(#[from] std::sync::mpsc::SendError<bool>),
2626
}
@@ -59,14 +59,27 @@ impl FanotifyNotifier {
5959
let local_paths = paths.clone();
6060
let fd = match Fanotify::new_nonblocking(FanotifyMode::NOTIF) {
6161
Ok(f) => f,
62-
Err(e) => return Err(Error::Faotify(e.to_string())),
62+
Err(e) => {
63+
return Err(Error::Fanotify(
64+
format!("While initializing Fanotify object: {}", e).to_string(),
65+
))
66+
}
6367
};
6468
for cur_path in local_paths {
6569
fd.add_path(
66-
FAN_CREATE | FAN_CLOSE_WRITE | FAN_MOVE_SELF | FAN_MODIFY,
70+
FAN_ACCESS
71+
| FAN_CLOSE
72+
| FAN_EVENT_ON_CHILD
73+
| FAN_MODIFY
74+
| FAN_ONDIR
75+
| FAN_CLOSE_WRITE,
6776
&cur_path,
6877
)
69-
.map_err(|err| Error::Faotify(err.to_string()))?;
78+
.map_err(|err| {
79+
Error::Fanotify(
80+
format!("While adding path '{}': {}", cur_path.display(), err).to_string(),
81+
)
82+
})?;
7083
}
7184
thread::spawn(move || {
7285
let fd_handle = fd.as_fd();

0 commit comments

Comments
 (0)