use anyhow::Result;
use fs_usage_sys::FsUsageMonitorBuilder;
fn main() -> Result<()> {
tracing_subscriber::fmt::init();
println!("Starting mutation-only file system monitor...");
let mut monitor = FsUsageMonitorBuilder::new()
.watch_path("/Users/madhavajay/dev/icaros/workspace2/lol")
.watch_mutations_only() .exact_path_matching(true) .build()?;
monitor.start()?;
println!("Monitor started. Watching for mutations only...");
println!(
"Try editing, saving, renaming, or changing permissions on files in the watched directory."
);
println!("Press Ctrl+C to stop");
loop {
match monitor.recv() {
Ok(event) => {
println!(
"{} {} {} {}",
event.timestamp,
event.operation.pad_to(20),
event.path,
event.process_name
);
}
Err(e) => {
eprintln!("Error receiving event: {}", e);
break;
}
}
}
Ok(())
}
trait PadTo {
fn pad_to(&self, width: usize) -> String;
}
impl PadTo for String {
fn pad_to(&self, width: usize) -> String {
format!("{:<width$}", self, width = width)
}
}