starting to add ctrlc checks for main run fn

This commit is contained in:
Bryson Steck 2025-03-25 21:45:09 -06:00
parent fb8ed1ae8c
commit fb25f0c0f4
Signed by: bryson
SSH key fingerprint: SHA256:XpKABw/nP4z8UVaH+weLaBnEOD86+cVwif+QjuYLGT4
2 changed files with 12 additions and 0 deletions

View file

@ -15,6 +15,8 @@ use crate::refractr::Refractr;
use clap::Parser; use clap::Parser;
use std::path::PathBuf; use std::path::PathBuf;
use std::process; use std::process;
use std::sync::atomic::AtomicBool;
use std::sync::Arc;
#[cfg(target_family = "windows")] #[cfg(target_family = "windows")]
use username; use username;
#[cfg(target_family = "unix")] #[cfg(target_family = "unix")]
@ -84,6 +86,7 @@ fn main() -> Result<(), String> {
strict: args.strict, strict: args.strict,
unix: cfg!(unix), unix: cfg!(unix),
verbose: args.verbose, verbose: args.verbose,
run: Arc::new(AtomicBool::new(true))
}; };
// warn to avoid root/admin // warn to avoid root/admin

View file

@ -29,6 +29,7 @@ pub struct Refractr {
pub strict: bool, pub strict: bool,
pub unix: bool, pub unix: bool,
pub verbose: u8, pub verbose: u8,
pub run: Arc<AtomicBool>
} }
struct OpenedRepository { struct OpenedRepository {
@ -334,6 +335,11 @@ impl Refractr {
} }
pub fn run(&self, cfgs: Vec<ConfigFile>) -> Result<(), ReturnData> { 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")); common::verbose(self.verbose, 3, format!("Starting main refractr loop"));
let mut loop_repos = Vec::new(); let mut loop_repos = Vec::new();
let mut work_dirs = Vec::new(); let mut work_dirs = Vec::new();
@ -499,6 +505,9 @@ impl Refractr {
return Err(e); return Err(e);
} }
} }
if self.run.load(Ordering::SeqCst) {
common::error_quit(format!("exiting"), ExitCode::HaltError);
}
} }
// end for // end for