1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
use std::env;
use inotify::{
EventMask,
Inotify,
WatchMask,
};
fn main() {
let mut inotify = Inotify::init()
.expect("Failed to initialize inotify");
let current_dir = env::current_dir()
.expect("Failed to determine current directory");
inotify
.add_watch(
current_dir,
WatchMask::MODIFY | WatchMask::CREATE | WatchMask::DELETE,
)
.expect("Failed to add inotify watch");
println!("Watching current directory for activity...");
let mut buffer = [0u8; 4096];
loop {
let events = inotify
.read_events_blocking(&mut buffer)
.expect("Failed to read inotify events");
for event in events {
if event.mask.contains(EventMask::CREATE) {
if event.mask.contains(EventMask::ISDIR) {
println!("Directory created: {:?}", event.name);
} else {
println!("File created: {:?}", event.name);
}
} else if event.mask.contains(EventMask::DELETE) {
if event.mask.contains(EventMask::ISDIR) {
println!("Directory deleted: {:?}", event.name);
} else {
println!("File deleted: {:?}", event.name);
}
} else if event.mask.contains(EventMask::MODIFY) {
if event.mask.contains(EventMask::ISDIR) {
println!("Directory modified: {:?}", event.name);
} else {
println!("File modified: {:?}", event.name);
}
}
}
}
}
|