From 78d5bafae34f3c1c356ece3ca73f7667d1230a26 Mon Sep 17 00:00:00 2001 From: Thelie Date: Wed, 12 May 2021 00:13:16 +0200 Subject: [PATCH] Added function for reading server config dirs. It's not complete yet. --- src/config.rs | 26 ++++++++++++++++++++++---- src/main.rs | 8 ++++---- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/config.rs b/src/config.rs index 5dd2761..318ea4e 100644 --- a/src/config.rs +++ b/src/config.rs @@ -16,16 +16,34 @@ */ use std::{ - path::Path, + path::PathBuf, io::Read, fs::read_dir, }; use toml::value::Value; +fn parse_server_dir(mut config: Value, server_config_path: PathBuf) + -> Result> { + let mut config = config.as_table_mut().unwrap().clone(); + if server_config_path.is_dir() { + for entry in read_dir(server_config_path)? { + let entry = entry?; + match entry.file_name().to_str().ok_or("Could not read file name")? { + "config.toml" => (), + "clients.toml" => (), + "channels.toml" => (), + _ => (), + } + } + } + + Ok(Value::from(config)) +} + /// parses a toml config file and sets some default values /// if the corresponding fields are not set. // TODO: Document config file options once they are stable. -pub fn get_main_config(config_path: &Path) +pub fn get_main_config(config_path: PathBuf) -> Result> { // I once read that this multiple let style @@ -55,14 +73,14 @@ pub fn get_main_config(config_path: &Path) Ok(Value::from(config)) } -pub fn get_server_config (config: Value, config_path: &Path) +pub fn get_server_config(mut config: Value, config_path: PathBuf) -> Result> { if config_path.is_dir() { for entry in read_dir(config_path)? { let entry = entry?; let server_path = entry.path(); if server_path.is_dir(){ - config = server_config_helper(config, server_path)?; + config = parse_server_dir(config, server_path)?; } } } diff --git a/src/main.rs b/src/main.rs index a402bc2..3d7f23b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,7 +21,7 @@ pub mod config; use std::{ format, env::args, - path::Path, + path::PathBuf, collections::VecDeque, }; use irc_proto::command::{ @@ -155,14 +155,14 @@ fn main() { let mut config; match config_path { - Some(p) => config = config::get_main_config(&Path::from(p)) + Some(p) => config = config::get_main_config(PathBuf::from(p)) .expect("Could not get config"), - None => config = config::get_main_config(&Path::from("/etc/Mention2Mail/config.toml")) + None => config = config::get_main_config(PathBuf::from("/etc/Mention2Mail/config.toml")) .expect("Could not get default config in /etc/Mention2Mail/default.toml"), } match server_conf_path { - Some(p) => config = config::get_server_config(config, p) + Some(p) => config = config::get_server_config(config, PathBuf::from(p)) .expect("Could not get server config."), None => (), }