Vendor things

This commit is contained in:
John Doty 2024-03-08 11:03:01 -08:00
parent 5deceec006
commit 977e3c17e5
19434 changed files with 10682014 additions and 0 deletions

View file

@ -0,0 +1,39 @@
use std::{
fs::File,
io,
thread,
time::Duration,
};
use futures_util::StreamExt;
use inotify::{
Inotify,
WatchMask,
};
use tempfile::TempDir;
#[tokio::main]
async fn main() -> Result<(), io::Error> {
let mut inotify = Inotify::init()
.expect("Failed to initialize inotify");
let dir = TempDir::new()?;
inotify.add_watch(dir.path(), WatchMask::CREATE | WatchMask::MODIFY)?;
thread::spawn::<_, Result<(), io::Error>>(move || {
loop {
File::create(dir.path().join("file"))?;
thread::sleep(Duration::from_millis(500));
}
});
let mut buffer = [0; 1024];
let mut stream = inotify.event_stream(&mut buffer)?;
while let Some(event_or_error) = stream.next().await {
println!("event: {:?}", event_or_error?);
}
Ok(())
}

View 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);
}
}
}
}
}