Skip to content

Commit

Permalink
Initialize fanotify in the main thread
Browse files Browse the repository at this point in the history
To allow for better error handling, initialize fanotify in the main
thread.

Signed-off-by: Jason Rogena <null+github.com@rogena.me>
  • Loading branch information
jasonrogena committed Dec 8, 2024
1 parent 8a19795 commit fcdb1de
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
28 changes: 12 additions & 16 deletions src/fs_notify/fanotify_notifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use {
pub enum Error {
#[error("The feature '{0}' is unsupported")]
UnsupportedFeature(String),
//#[error("An error was thrown by the filesystem notification system")]
//Faotify(#[from] fanotify::Error),
#[error("An error was thrown by the filesystem notification system: {0}")]
Faotify(String),
#[error("An error was thrown while trying to interract with the notification system")]
Send(#[from] std::sync::mpsc::SendError<bool>),
}
Expand Down Expand Up @@ -57,21 +57,17 @@ impl FanotifyNotifier {
) -> Result<(), Error> {
let stop_cancellation_token = self.stop_cancellation_token.clone();
let local_paths = paths.clone();
let fd = match Fanotify::new_nonblocking(FanotifyMode::NOTIF) {
Ok(f) => f,
Err(e) => return Err(Error::Faotify(e.to_string())),
};
for cur_path in local_paths {
fd.add_path(
FAN_CREATE | FAN_CLOSE_WRITE | FAN_MOVE_SELF | FAN_MODIFY,
&cur_path,
).map_err(|err| Error::Faotify(err.to_string()))?;
}
thread::spawn(move || {
let fd = match Fanotify::new_nonblocking(FanotifyMode::NOTIF) {
Ok(f) => f,
Err(e) => panic!(
"An error occurred while trying to initialise the fanotify watcher: {}",
e
),
};
for cur_path in local_paths {
fd.add_path(
FAN_CREATE | FAN_CLOSE_WRITE | FAN_MOVE_SELF | FAN_MODIFY,
&cur_path,
)
.unwrap();
}
let fd_handle = fd.as_fd();
let mut fds = [PollFd::new(fd_handle.as_raw_fd(), PollFlags::POLLIN)];
loop {
Expand Down
1 change: 1 addition & 0 deletions src/library/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ impl<'a> Library<'a> {
}

fn run_command(&self, path: &Path, mime_type: &str) -> Result<bool, Error> {
println!("Processing '{}'", path.display());
if *self.skip_running_commands {
match path.as_os_str().to_str() {
None => {
Expand Down

0 comments on commit fcdb1de

Please sign in to comment.