starting to add ctrlc checks for main run fn
This commit is contained in:
parent
fb8ed1ae8c
commit
fb25f0c0f4
2 changed files with 12 additions and 0 deletions
|
@ -15,6 +15,8 @@ use crate::refractr::Refractr;
|
|||
use clap::Parser;
|
||||
use std::path::PathBuf;
|
||||
use std::process;
|
||||
use std::sync::atomic::AtomicBool;
|
||||
use std::sync::Arc;
|
||||
#[cfg(target_family = "windows")]
|
||||
use username;
|
||||
#[cfg(target_family = "unix")]
|
||||
|
@ -84,6 +86,7 @@ fn main() -> Result<(), String> {
|
|||
strict: args.strict,
|
||||
unix: cfg!(unix),
|
||||
verbose: args.verbose,
|
||||
run: Arc::new(AtomicBool::new(true))
|
||||
};
|
||||
|
||||
// warn to avoid root/admin
|
||||
|
|
|
@ -29,6 +29,7 @@ pub struct Refractr {
|
|||
pub strict: bool,
|
||||
pub unix: bool,
|
||||
pub verbose: u8,
|
||||
pub run: Arc<AtomicBool>
|
||||
}
|
||||
|
||||
struct OpenedRepository {
|
||||
|
@ -334,6 +335,11 @@ impl Refractr {
|
|||
}
|
||||
|
||||
pub fn run(&self, cfgs: Vec<ConfigFile>) -> Result<(), ReturnData> {
|
||||
let r = self.run.clone();
|
||||
ctrlc::set_handler(move ||
|
||||
r.store(true, Ordering::SeqCst)
|
||||
).expect("failed to set ^c handler");
|
||||
|
||||
common::verbose(self.verbose, 3, format!("Starting main refractr loop"));
|
||||
let mut loop_repos = Vec::new();
|
||||
let mut work_dirs = Vec::new();
|
||||
|
@ -499,6 +505,9 @@ impl Refractr {
|
|||
return Err(e);
|
||||
}
|
||||
}
|
||||
if self.run.load(Ordering::SeqCst) {
|
||||
common::error_quit(format!("exiting"), ExitCode::HaltError);
|
||||
}
|
||||
}
|
||||
// end for
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue