Skip to content

Commit 7d8cbbc

Browse files
jasta0xpr03
authored andcommitted
Oops, reversed accidental delietion of examples/poll_sysfs
1 parent 6077ef0 commit 7d8cbbc

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

examples/poll_sysfs.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#![cfg(not(target_os = "windows"))]
2+
3+
use std::path::Path;
4+
use std::time::Duration;
5+
use notify::poll::PollWatcherConfig;
6+
use notify::{PollWatcher, RecursiveMode, Watcher};
7+
8+
fn main() -> notify::Result<()> {
9+
let mut paths: Vec<_> = std::env::args().skip(1)
10+
.map(|arg| Path::new(&arg).to_path_buf())
11+
.collect();
12+
if paths.is_empty() {
13+
let lo_stats = Path::new("/sys/class/net/lo/statistics/tx_bytes").to_path_buf();
14+
if !lo_stats.exists() {
15+
eprintln!("Must provide path to watch, default system path was not found (probably you're not running on Linux?)");
16+
std::process::exit(1);
17+
}
18+
println!("Trying {:?}, use `ping localhost` to see changes!", lo_stats);
19+
paths.push(lo_stats);
20+
}
21+
22+
println!("watching {:?}...", paths);
23+
24+
let config = PollWatcherConfig {
25+
compare_contents: true,
26+
poll_interval: Duration::from_secs(2),
27+
};
28+
let (tx, rx) = std::sync::mpsc::channel();
29+
let mut watcher = PollWatcher::with_config(tx, config)?;
30+
for path in paths {
31+
watcher.watch(&path, RecursiveMode::Recursive)?;
32+
}
33+
34+
for res in rx {
35+
match res {
36+
Ok(event) => println!("changed: {:?}", event),
37+
Err(e) => println!("watch error: {:?}", e),
38+
}
39+
}
40+
41+
Ok(())
42+
}

0 commit comments

Comments
 (0)