Skip to content

Commit

Permalink
Oops, reversed accidental delietion of examples/poll_sysfs
Browse files Browse the repository at this point in the history
  • Loading branch information
jasta authored and 0xpr03 committed Apr 28, 2022
1 parent 6077ef0 commit 7d8cbbc
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions examples/poll_sysfs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#![cfg(not(target_os = "windows"))]

use std::path::Path;
use std::time::Duration;
use notify::poll::PollWatcherConfig;
use notify::{PollWatcher, RecursiveMode, Watcher};

fn main() -> notify::Result<()> {
let mut paths: Vec<_> = std::env::args().skip(1)
.map(|arg| Path::new(&arg).to_path_buf())
.collect();
if paths.is_empty() {
let lo_stats = Path::new("/sys/class/net/lo/statistics/tx_bytes").to_path_buf();
if !lo_stats.exists() {
eprintln!("Must provide path to watch, default system path was not found (probably you're not running on Linux?)");
std::process::exit(1);
}
println!("Trying {:?}, use `ping localhost` to see changes!", lo_stats);
paths.push(lo_stats);
}

println!("watching {:?}...", paths);

let config = PollWatcherConfig {
compare_contents: true,
poll_interval: Duration::from_secs(2),
};
let (tx, rx) = std::sync::mpsc::channel();
let mut watcher = PollWatcher::with_config(tx, config)?;
for path in paths {
watcher.watch(&path, RecursiveMode::Recursive)?;
}

for res in rx {
match res {
Ok(event) => println!("changed: {:?}", event),
Err(e) => println!("watch error: {:?}", e),
}
}

Ok(())
}

0 comments on commit 7d8cbbc

Please sign in to comment.