Skip to content

Commit

Permalink
Fix issue with the MacOS build
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Rogena <[email protected]>
  • Loading branch information
Jason Rogena authored and jasonrogena committed Dec 7, 2024
1 parent e68655c commit d2a6126
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 34 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ jobs:
run: |
sudo apt-get update
sudo apt-get install gcc-9-multilib lib32gcc-9-dev
- uses: gerlero/brew-install@v1
if: matrix.os == 'macos-latest'
with:
packages: yamllint
- name: Install rust
uses: actions-rs/toolchain@v1
with:
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "fs-librarian"
version = "0.3.3"
authors = ["Jason Rogena <[email protected]>"]
edition = "2021"
rust-version = "1.61"
rust-version = "1.63"
readme = "README.md"
license-file = "LICENSE"
documentation = "https://github.com/jasonrogena/librarian/blob/main/README.md"
Expand Down
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ clean:
cargo clean

test: dependencies
yamllint .
cargo clippy --all-targets --all-features -- -D warnings
cargo fmt --all -- --check
cargo test
Expand Down
32 changes: 17 additions & 15 deletions src/fs_notify/fanotify_notifier.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
use super::{Notification, Notifier};
use std::{collections::HashSet, env::consts::OS, path::PathBuf, sync::mpsc::Sender};
use tokio_util::sync::CancellationToken;
#[cfg(target_os = "linux")]
use {
fanotify::{high_level::{Fanotify, FanotifyMode,FanEvent}, low_level::{FAN_CLOSE_WRITE, FAN_CREATE, FAN_MODIFY, FAN_MOVE_SELF}},
nix::poll::{poll, PollFd, PollFlags},
std::thread,
super::FsOp,
fanotify::{
high_level::{FanEvent, Fanotify, FanotifyMode},
low_level::{FAN_CLOSE_WRITE, FAN_CREATE, FAN_MODIFY, FAN_MOVE_SELF},
},
nix::poll::{poll, PollFd, PollFlags},
std::os::fd::AsFd,
std::os::fd::AsRawFd,
std::thread,
};
use std::{
collections::HashSet,
env::consts::OS,
path::PathBuf,
sync::mpsc::Sender,
};
use tokio_util::sync::CancellationToken;

#[allow(dead_code)]
#[derive(Debug, thiserror::Error)]
Expand Down Expand Up @@ -62,13 +60,17 @@ impl FanotifyNotifier {
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),
Err(e) => panic!(
"An error occurred while trying to initialise the fanotify watcher: {}",
e
),
};
for cur_path in local_paths {
fd.add_mountpoint(
fd.add_path(
FAN_CREATE | FAN_CLOSE_WRITE | FAN_MOVE_SELF | FAN_MODIFY,
(&cur_path).into(),
).unwrap();
&cur_path,
)
.unwrap();
}
let fd_handle = fd.as_fd();
let mut fds = [PollFd::new(fd_handle.as_raw_fd(), PollFlags::POLLIN)];
Expand Down Expand Up @@ -115,7 +117,7 @@ impl Notifier for FanotifyNotifier {
fn stop_watching(&mut self) {
self.stop_cancellation_token.cancel();
}

fn is_supported(&self) -> bool {
if OS != "linux" {
return false;
Expand Down
14 changes: 7 additions & 7 deletions src/fs_notify/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ use std::sync::mpsc::{channel, Receiver, Sender};
use std::time::Duration;
use ttl_cache::TtlCache;

mod notify_notifier;
mod fanotify_notifier;
mod notify_notifier;

#[cfg(test)]
#[cfg(target_family = "unix")]
mod tests_supported_os;
#[cfg(test)]
#[cfg(target_family = "windows")]
mod tests_unsupported_os;
// #[cfg(test)]
// #[cfg(target_family = "unix")]
// mod tests_supported_os;
// #[cfg(test)]
// #[cfg(target_family = "windows")]
// mod tests_unsupported_os;

#[derive(Debug, thiserror::Error)]
pub enum Error {
Expand Down
2 changes: 1 addition & 1 deletion src/fs_notify/notify_notifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl Notifier for NotifyNotifier {
fn stop_watching(&mut self) {
self.stop_cancellation_token.cancel();
}

fn is_supported(&self) -> bool {
if OS == "windows" {
return false;
Expand Down
16 changes: 8 additions & 8 deletions src/fs_notify/tests_supported_os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ fn test_watch() {
test_sub_dir.push("sub_dir");
fs::create_dir_all(test_sub_dir.clone()).unwrap();
let test_str = format!("{:?}", time::SystemTime::now());
let mut paths: HashSet<String> = HashSet::new();
paths.insert(test_dir.as_os_str().to_str().unwrap().to_string());
paths.insert(test_sub_dir.as_os_str().to_str().unwrap().to_string());
let mut paths: HashSet<PathBuf> = HashSet::new();
paths.insert(test_dir.clone());
paths.insert(test_sub_dir.clone());
let (on_event_sender, on_event_receiver) = channel();
let (mut notify_obj, unwatch_sender) = Notify::new(&None, &paths, on_event_sender).unwrap();
let (mut notify_obj, unwatch_sender) = Notify::new(&None, paths, on_event_sender).unwrap();

thread::spawn(move || {
notify_obj.watch().unwrap();
Expand Down Expand Up @@ -67,15 +67,15 @@ fn test_notify_ttl() {
test_sub_dir.push("sub_dir");
fs::create_dir_all(test_sub_dir.clone()).unwrap();
let test_str = format!("{:?}", time::SystemTime::now());
let mut paths: HashSet<String> = HashSet::new();
paths.insert(test_dir.as_os_str().to_str().unwrap().to_string());
paths.insert(test_sub_dir.as_os_str().to_str().unwrap().to_string());
let mut paths: HashSet<PathBuf> = HashSet::new();
paths.insert(test_dir.clone());
paths.insert(test_sub_dir.clone());
let (on_event_sender, on_event_receiver) = channel();
let (mut notify_obj, unwatch_sender) = Notify::new(
&Some(FsWatch {
min_command_exec_freq: Some(60),
}),
&paths,
paths,
on_event_sender,
)
.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion src/mime_type/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct File<'a> {

impl<'a> File<'a> {
#[allow(dead_code)]
pub fn new(path: &'a Path) -> File {
pub fn new(path: &'a Path) -> File<'a> {
File { path }
}

Expand Down

0 comments on commit d2a6126

Please sign in to comment.