diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e001e17..f517d38 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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: diff --git a/Cargo.toml b/Cargo.toml index e13f1c8..d3ac0e3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "fs-librarian" version = "0.3.3" authors = ["Jason Rogena "] 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" diff --git a/Makefile b/Makefile index 8cf8663..005e7b5 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,6 @@ clean: cargo clean test: dependencies - yamllint . cargo clippy --all-targets --all-features -- -D warnings cargo fmt --all -- --check cargo test diff --git a/src/fs_notify/fanotify_notifier.rs b/src/fs_notify/fanotify_notifier.rs index 71ee19e..5fe162c 100644 --- a/src/fs_notify/fanotify_notifier.rs +++ b/src/fs_notify/fanotify_notifier.rs @@ -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)] @@ -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)]; @@ -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; diff --git a/src/fs_notify/mod.rs b/src/fs_notify/mod.rs index 4098058..0599b6c 100644 --- a/src/fs_notify/mod.rs +++ b/src/fs_notify/mod.rs @@ -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 { diff --git a/src/fs_notify/notify_notifier.rs b/src/fs_notify/notify_notifier.rs index cfd1d0e..2feee35 100644 --- a/src/fs_notify/notify_notifier.rs +++ b/src/fs_notify/notify_notifier.rs @@ -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; diff --git a/src/fs_notify/tests_supported_os.rs b/src/fs_notify/tests_supported_os.rs index 572ff38..3031bf1 100644 --- a/src/fs_notify/tests_supported_os.rs +++ b/src/fs_notify/tests_supported_os.rs @@ -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 = 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 = 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(); @@ -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 = 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 = 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(); diff --git a/src/mime_type/mod.rs b/src/mime_type/mod.rs index daa6dbf..ac126a4 100644 --- a/src/mime_type/mod.rs +++ b/src/mime_type/mod.rs @@ -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 } }