summaryrefslogtreecommitdiff
path: root/src/cfg/config.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/cfg/config.rs')
-rw-r--r--src/cfg/config.rs38
1 files changed, 25 insertions, 13 deletions
diff --git a/src/cfg/config.rs b/src/cfg/config.rs
index 687c415..f14ec93 100644
--- a/src/cfg/config.rs
+++ b/src/cfg/config.rs
@@ -49,24 +49,29 @@ pub struct Paths {
pub cache_dir: String,
#[serde(rename = "build_dir")]
pub build_dir: String,
+ pub installed_db: String,
}
impl Config {
- /// Parse the /etc/mesk.toml file and return the Config object.
+ /// Parse configuration and return the Config object.
///
- /// This function reads the /etc/mesk.toml file, parses it and returns the Config object.
- /// If the file is not available, it falls back to the `MESK_CONFIG_TOML` environment
- /// variable containing the full TOML configuration.
+ /// This function first tries to read the `MESK_CONFIG_TOML` environment variable
+ /// containing the full TOML configuration. If it is not set, it falls back to
+ /// reading the `/etc/mesk/mesk.toml` file.
pub fn parse() -> Result<Config, toml::de::Error> {
- let contents = match fs::read_to_string("/etc/mesk/mesk.toml") {
- Ok(c) => c,
- Err(_e) => std::env::var("MESK_CONFIG_TOML").map_err(|env_err| {
- DeError::custom(format!(
- "Failed to read /etc/mesk/mesk.toml and MESK_CONFIG_TOML is not set: {}",
- env_err
- ))
- })?,
- };
+ // Prefer an explicit in-memory config for tests and overrides.
+ if let Ok(env_contents) = std::env::var("MESK_CONFIG_TOML") {
+ let result: Config = toml::from_str(&env_contents)?;
+ return Ok(result);
+ }
+
+ // Fallback to the system-wide config file.
+ let contents = fs::read_to_string("/etc/mesk/mesk.toml").map_err(|io_err| {
+ DeError::custom(format!(
+ "Failed to read /etc/mesk/mesk.toml and MESK_CONFIG_TOML is not set: {}",
+ io_err
+ ))
+ })?;
let result: Config = toml::from_str(&contents)?;
Ok(result)
@@ -97,6 +102,7 @@ impl Config {
paths: Paths {
cache_dir: String::from("/var/cache/mesk"),
build_dir: String::from("/var/lib/mesk"),
+ installed_db: String::from("/var/lib/mesk/pkgdb"),
},
};
@@ -108,6 +114,7 @@ impl Config {
repo: &Option<String>,
cachedir: &Option<String>,
buildir: &Option<String>,
+ installed_db: &Option<String>,
) -> Result<String, toml::ser::Error> {
let generator: Config = Config {
repo: Repo {
@@ -135,6 +142,11 @@ impl Config {
} else {
buildir.clone().unwrap()
},
+ installed_db: if installed_db.is_none() {
+ String::from("/var/cache/mesk/pkgdb")
+ } else {
+ installed_db.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/