-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e366065
Showing
6 changed files
with
357 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/target |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[package] | ||
name = "nissyncd" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
notify-debouncer-mini = "0.4.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
hello, world |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use notify_debouncer_mini::{ | ||
new_debouncer_opt, Config, | ||
notify::{self, PollWatcher}, notify::{ErrorKind as NotifyErrorKind, RecursiveMode, Result}, Debouncer, | ||
}; | ||
use std::env; | ||
use std::io::ErrorKind as IoErrorKind; | ||
use std::path::Path; | ||
use std::process::Command; | ||
use std::sync::mpsc::channel; | ||
use std::time::Duration; | ||
|
||
fn main() -> Result<()> { | ||
let yp_directory = env::var("YP_DIRECTORY").unwrap_or("/var/yp".to_string()); | ||
let notify_config = notify::Config::default().with_poll_interval(Duration::from_secs(2)); | ||
let (tx, rx) = channel(); | ||
let mut debouncer: Debouncer<PollWatcher> = new_debouncer_opt(Config::default().with_timeout(Duration::from_secs(2)).with_notify_config(notify_config), tx)?; | ||
|
||
let watcher = debouncer.watcher(); | ||
|
||
for filename in ["/etc/passwd", "/etc/group", "/etc/shadow", "/etc/gshadow"] { | ||
match watcher.watch(Path::new(filename), RecursiveMode::NonRecursive) { | ||
Ok(_) => println!("{} watched", filename), | ||
Err(err) => match err.kind { | ||
NotifyErrorKind::Io(err) => match err.kind() { | ||
IoErrorKind::NotFound => println!( | ||
"No such file {}, it may related to your distribution", | ||
filename | ||
), | ||
_ => panic!("Unable to watch file: {}, reason: \n{:?}", filename, err), | ||
}, | ||
_ => panic!("Filed to watch file {}, error: {:?}", filename, err), | ||
}, | ||
} | ||
} | ||
|
||
for event in rx { | ||
match event { | ||
Ok(_) => { | ||
println!("Files changed!"); | ||
Command::new("make") | ||
.current_dir(&yp_directory) | ||
.spawn() | ||
.expect("failed to execute rebuild process, is make command and the yp directory exist?") | ||
.wait() | ||
.expect("failed to wait for the rebuild process"); | ||
println!("Rebuild finished!") | ||
} | ||
Err(err) => println!("Something is wrong: {:?}", err), | ||
} | ||
} | ||
|
||
Ok(()) | ||
} |