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