summaryrefslogtreecommitdiff
path: root/src/cfg/config.rs
diff options
context:
space:
mode:
authorNamilskyy <alive6863@gmail.com>2025-11-29 16:08:17 +0300
committerNamilskyy <alive6863@gmail.com>2025-11-29 16:08:17 +0300
commitf3d98b21d0b66952501aed5403df6773716f9e0b (patch)
tree90eca38f0edbda3c7caa36d4175531bab0566469 /src/cfg/config.rs
parent11ccd034109224849fff54c12785e454deba6741 (diff)
Connected some functions to main.rs.
Diffstat (limited to 'src/cfg/config.rs')
-rw-r--r--src/cfg/config.rs30
1 files changed, 27 insertions, 3 deletions
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<Config, toml::de::Error> {
- 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<String>, cachedir: &Option<String>, buildir: &Option<String>) -> Result<String, toml::ser::Error> {
+ 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)?)
+ }
+}