mirror of
https://git.proxmox.com/git/rustc
synced 2025-08-17 16:31:32 +00:00
55 lines
1.6 KiB
Rust
55 lines
1.6 KiB
Rust
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);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|