Skip to content

Commit

Permalink
Clarify config selector, throw a warning if specified wasn't found
Browse files Browse the repository at this point in the history
  • Loading branch information
isbm committed Nov 29, 2024
1 parent aa01913 commit 64751b8
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 8 deletions.
4 changes: 3 additions & 1 deletion libsysinspect/src/cfg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ pub const APP_DOTCONF: &str = ".sysinspect";
pub const APP_HOME: &str = "/etc/sysinspect";

/// Select app conf
pub fn select_config(p: Option<String>) -> Result<PathBuf, SysinspectError> {
pub fn select_config(p: Option<&str>) -> Result<PathBuf, SysinspectError> {
// Override path from options
if let Some(ovrp) = p {
let ovrp = PathBuf::from(ovrp);
if ovrp.exists() {
return Ok(ovrp);
}

log::warn!("Preferred config at {} does not exist, falling back", ovrp.to_str().unwrap_or_default());
}

// Current
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn set_logger(p: &ArgMatches) {

/// Get configuration of the master
fn get_cfg(p: &ArgMatches) -> Result<MasterConfig, SysinspectError> {
MasterConfig::new(select_config(p.get_one::<String>("config").cloned())?)
MasterConfig::new(select_config(p.get_one::<&str>("config").cloned())?)
}

fn main() {
Expand Down
2 changes: 0 additions & 2 deletions sysinspect.conf
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,5 @@ config:
minion:
# Root directory where minion keeps all data.
# Default: /etc/sysinspect — same as for master
root: /etc/sysinspect
id.path: relative
master.ip: 192.168.2.31
master.port: 4200
5 changes: 1 addition & 4 deletions sysminion/src/minion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@ pub struct SysMinion {

impl SysMinion {
pub async fn new(cfp: &str, fingerprint: Option<String>) -> Result<Arc<SysMinion>, SysinspectError> {
let mut cfp = PathBuf::from(cfp);
if !cfp.exists() {
cfp = cfg::select_config(None)?;
}
let cfp = cfg::select_config(Some(cfp))?;

let cfg = MinionConfig::new(cfp)?;
let (rstm, wstm) = TcpStream::connect(cfg.master()).await.unwrap().into_split();
Expand Down

0 comments on commit 64751b8

Please sign in to comment.