summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDavid Lönnhager <david.l@mullvad.net>2025-02-25 14:41:12 +0100
committerDavid Lönnhager <david.l@mullvad.net>2025-03-06 00:09:15 +0100
commit8aae07d50daf461e6288ae734589fc52032da54f (patch)
tree9aefa1015ec4d1e0b067ec5d573fc207ace82bab
parent541079d02c4b3d09cb2f89831ec20a3aa6761e19 (diff)
downloadmullvadvpn-8aae07d50daf461e6288ae734589fc52032da54f.tar.xz
mullvadvpn-8aae07d50daf461e6288ae734589fc52032da54f.zip
Generate default meta.toml
-rw-r--r--mullvad-update/meta/src/config.rs19
1 files changed, 13 insertions, 6 deletions
diff --git a/mullvad-update/meta/src/config.rs b/mullvad-update/meta/src/config.rs
index bbfa923cc6..378726587b 100644
--- a/mullvad-update/meta/src/config.rs
+++ b/mullvad-update/meta/src/config.rs
@@ -5,26 +5,33 @@ use serde::{Deserialize, Serialize};
use tokio::{fs, io};
/// Path to the configuration file. Currently a file in the working directory.
-const CONFIG_FILENAME: &str = "config.toml";
+const CONFIG_FILENAME: &str = "meta.toml";
#[derive(Default, Deserialize, Serialize)]
pub struct Config {
/// URLs to use as bases for installers.
- /// Files are expected at (example): `<base>/MullvadVPN-2025.1.exe`.
+ /// Files are expected at (example): `<base>/<version>/MullvadVPN-<version>.exe`.
pub base_urls: Vec<String>,
}
impl Config {
pub async fn load_or_create() -> anyhow::Result<Self> {
- println!("Reading {CONFIG_FILENAME}");
-
match fs::read_to_string(CONFIG_FILENAME).await {
Ok(toml_str) => toml::from_str(&toml_str).context("Failed to parse TOML file"),
Err(err) if err.kind() == io::ErrorKind::NotFound => {
- println!("Creating default {CONFIG_FILENAME}");
- Ok(Self::default())
+ eprintln!("Creating default {CONFIG_FILENAME}");
+ let self_ = Self::default();
+ self_.save().await?;
+ Ok(self_)
}
Err(err) => Err(err).context(format!("Failed to read {CONFIG_FILENAME}")),
}
}
+
+ async fn save(&self) -> anyhow::Result<()> {
+ let toml_str = toml::to_string_pretty(self).expect("Expected valid toml");
+ fs::write(CONFIG_FILENAME, toml_str.as_bytes())
+ .await
+ .context(format!("Failed to save {CONFIG_FILENAME}"))
+ }
}