From 4ea80a819b8cd33091ee05cb0b653c00c2cf3657 Mon Sep 17 00:00:00 2001 From: guochao Date: Thu, 3 Apr 2025 14:12:21 +0000 Subject: [PATCH] chore: cargo fmt --- fanotify-demo/src/main.rs | 14 +++++++------- fanotify/src/error.rs | 2 +- fanotify/src/fanotify.rs | 5 +++-- fanotify/src/lib.rs | 4 ++-- fanotify/src/macros.rs | 4 ++-- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/fanotify-demo/src/main.rs b/fanotify-demo/src/main.rs index 4be748b..9ba5942 100644 --- a/fanotify-demo/src/main.rs +++ b/fanotify-demo/src/main.rs @@ -24,7 +24,9 @@ extern "C" fn interrupt_handler(_: i32) { } #[derive(Debug, clap::Parser)] -#[clap(about="fanotify demo", long_about=" +#[clap( + about = "fanotify demo", + long_about = " monitor filesystem changes demo to use as storage provider: @@ -35,7 +37,8 @@ to use as storage provider: --mask-flags FAN_ACCESS_PERM setup permission notification --mask-flags FAN_ON_DIR create events for directories itself --mask-flags FAN_EVENT_ON_CHILD create events for direct children -")] +" +)] struct Args { #[clap(required(true))] path: Vec, @@ -146,7 +149,7 @@ fn main() -> Result<(), Error> { let whitelist = args.whitelist; let storage_provider = args.providers; - + let mut ready = HashSet::new(); let mut bufferdfds: HashMap> = HashMap::new(); let mut arg0map = HashMap::new(); @@ -233,9 +236,7 @@ fn main() -> Result<(), Error> { // is a directory or filled with content metadata.is_dir() || ready.contains(&path) } - Err(error) => { - error.kind() == std::io::ErrorKind::NotFound - } + Err(error) => error.kind() == std::io::ErrorKind::NotFound, }; if allowed || whitelist.contains(&arg0) || storage_provider.contains(&arg0) { info!("<<<<< {} allowed", fd.as_raw_fd()); @@ -252,7 +253,6 @@ fn main() -> Result<(), Error> { } else { bufferdfds.insert(path, vec![fd]); } - } } MaskFlags::FAN_CLOSE_WRITE => { diff --git a/fanotify/src/error.rs b/fanotify/src/error.rs index 984a885..ef94d5e 100644 --- a/fanotify/src/error.rs +++ b/fanotify/src/error.rs @@ -12,7 +12,7 @@ impl Errno { Self { raw_errno: errno } } pub fn errno() -> Self { - Self::new(unsafe { *libc::__errno_location() } ) + Self::new(unsafe { *libc::__errno_location() }) } } diff --git a/fanotify/src/fanotify.rs b/fanotify/src/fanotify.rs index 3fc7646..b1b600d 100644 --- a/fanotify/src/fanotify.rs +++ b/fanotify/src/fanotify.rs @@ -96,7 +96,8 @@ impl Fanotify { // (long)(meta) ->event_len >= (long)FAN_FAN_EVENT_METADATA_LEN && // struct contains valid size (not implemented) // (long)(meta) ->event_len <= (long)(len) // struct does not read over buffer boundary (not implemented) while offset + EVENT_SIZE <= nread { - let mut uninited: MaybeUninit = MaybeUninit::uninit(); + let mut uninited: MaybeUninit = + MaybeUninit::uninit(); std::ptr::copy( buffer.as_ptr().add(offset), uninited.as_mut_ptr().cast(), @@ -108,7 +109,7 @@ impl Fanotify { // meta = FAN_EVENT_NEXT(meta, len) translate to: // len -= meta->event_len; // shrink rest length // , // comma operator, evaluate first express, but not using its result - // + // // meta = (struct fanotify_event_metadata*) ( // cast pointer back to metadata type // ((char*)(meta)) // discard metadata type to increase pointer by 1 // + (meta) -> event_len // add event_len to move to next diff --git a/fanotify/src/lib.rs b/fanotify/src/lib.rs index 4b0bb6a..81518d4 100644 --- a/fanotify/src/lib.rs +++ b/fanotify/src/lib.rs @@ -1,10 +1,10 @@ #[macro_use] mod macros; +pub mod consts; pub mod error; pub mod fanotify; -pub mod consts; pub use bitflags; -pub use fanotify::{Fanotify, Error, Response, Response as FanotifyResponse, Event}; \ No newline at end of file +pub use fanotify::{Error, Event, Fanotify, Response, Response as FanotifyResponse}; diff --git a/fanotify/src/macros.rs b/fanotify/src/macros.rs index 7ef1a29..e1d13a7 100644 --- a/fanotify/src/macros.rs +++ b/fanotify/src/macros.rs @@ -37,7 +37,7 @@ macro_rules! fa_bitflags { } }; - // from nix: input: accept a list of pub struct + // from nix: input: accept a list of pub struct ( // first $(#[$outer:meta])* @@ -72,4 +72,4 @@ macro_rules! fa_bitflags { // modified part: empty block don't produce anything. () => {} -} \ No newline at end of file +}