From f3d98b21d0b66952501aed5403df6773716f9e0b Mon Sep 17 00:00:00 2001 From: Namilskyy Date: Sat, 29 Nov 2025 16:08:17 +0300 Subject: Connected some functions to main.rs. --- src/cfg/config.rs | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'src/cfg') diff --git a/src/cfg/config.rs b/src/cfg/config.rs index 7c81e21..ffccbad 100644 --- a/src/cfg/config.rs +++ b/src/cfg/config.rs @@ -1,5 +1,4 @@ use std::fs; -use std::env; use serde::{Deserialize, Serialize}; use toml; @@ -57,7 +56,7 @@ impl Config { /// /// This function reads the /etc/mesk.toml file, parses it and returns the Config object. pub fn parse() -> Result { - let contents = fs::read_to_string("/etc/mesk.toml").unwrap(); + let contents = fs::read_to_string("/etc/mesk/mesk.toml").unwrap(); let result: Config = toml::from_str(&contents)?; Ok(result) } @@ -74,6 +73,7 @@ impl Config { auto_update: true, destination: (String::from("mesk"), String::from("mesk")), // Its a hurt place, you need to generate destinations by i2pd and paste here (to mesk.toml) + // Better to leave it empty or set it to (mesk, mesk), now destination conn not implemented }, log: Log { log_file: String::from("/var/log/mesk.log"), @@ -88,4 +88,28 @@ impl Config { let toml_str = toml::to_string(&default)?; Ok(toml_str) } -} \ No newline at end of file + + pub fn generate(repo: &Option, cachedir: &Option, buildir: &Option) -> Result { + let generator: Config = Config { + repo: Repo { + repo_url: if repo.is_none() { format!("https://mesk.anthrill.i2p/repo/{}/", std::env::consts::ARCH ) } else { repo.clone().unwrap() }, + auto_update: true, + destination: (String::from("mesk"), String::from("mesk")), + }, + log: Log { + log_file: String::from("/var/log/mesk.log"), + log_level: Loglevel::Info, + }, + paths: Paths { + cache_dir: if cachedir.is_none() { String::from("/var/cache/mesk") } else { cachedir.clone().unwrap() }, + build_dir: if buildir.is_none() { String::from("/var/cache/mesk/build") } else { buildir.clone().unwrap() }, + + /* + FIXME: I can leave this parameter, but I think it would be better to make the build + path in the /var/cache/mesk/$pkgname-$pkgver/BUILD/ + */ + }, + }; + Ok(toml::to_string(&generator)?) + } +} -- cgit v1.2.3