Vendor things
This commit is contained in:
parent
5deceec006
commit
977e3c17e5
19434 changed files with 10682014 additions and 0 deletions
54
third-party/vendor/inotify/examples/watch.rs
vendored
Normal file
54
third-party/vendor/inotify/examples/watch.rs
vendored
Normal file
|
|
@ -0,0 +1,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue