From 581110082711aefea2f9e16073df95893377b8e8 Mon Sep 17 00:00:00 2001 From: Simon Ellmann Date: Mon, 1 Jul 2019 02:31:55 +0200 Subject: [PATCH] Make pcid parse config files from directory --- pcid/src/main.rs | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/pcid/src/main.rs b/pcid/src/main.rs index 259664612a..2c247cdfda 100644 --- a/pcid/src/main.rs +++ b/pcid/src/main.rs @@ -8,7 +8,7 @@ extern crate syscall; extern crate toml; use std::env; -use std::fs::File; +use std::fs::{File, metadata, read_dir}; use std::io::Read; use std::process::Command; use syscall::iopl; @@ -161,11 +161,28 @@ fn main() { let mut args = env::args().skip(1); if let Some(config_path) = args.next() { - if let Ok(mut config_file) = File::open(&config_path) { - let mut config_data = String::new(); - if let Ok(_) = config_file.read_to_string(&mut config_data) { - config = toml::from_str(&config_data).unwrap_or(Config::default()); + if metadata(&config_path).unwrap().is_file() { + if let Ok(mut config_file) = File::open(&config_path) { + let mut config_data = String::new(); + if let Ok(_) = config_file.read_to_string(&mut config_data) { + config = toml::from_str(&config_data).unwrap_or(Config::default()); + } } + } else { + let paths = read_dir(&config_path).unwrap(); + + let mut config_data = String::new(); + + for path in paths { + if let Ok(mut config_file) = File::open(&path.unwrap().path()) { + let mut tmp = String::new(); + if let Ok(_) = config_file.read_to_string(&mut tmp) { + config_data.push_str(&tmp); + } + } + } + + config = toml::from_str(&config_data).unwrap_or(Config::default()); } }