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