Saving more work.

This commit is contained in:
2026-08-26 11:12:06 +02:00
parent 225c3f48b7
commit 7bd95a826e
8 changed files with 494 additions and 75 deletions
+7 -5
View File
@@ -23,6 +23,8 @@ use serde::{Serialize, Deserialize};
use std::{fs, io};
use toml;
const CONFIG_PATH: &str = "/etc/hive_up.toml";
#[derive(Debug, Serialize, Deserialize)]
pub struct HiveConfig {
// Matches [kernel] in TOML
@@ -91,18 +93,18 @@ impl std::fmt::Display for ConfigError {
// Implement std::error::Error
impl std::error::Error for ConfigError {}
pub fn read_config(conf_file: &str) -> Result<HiveConfig, ConfigError> {
let file_content = fs::read_to_string(conf_file)?;
pub fn read_config() -> Result<HiveConfig, ConfigError> {
let file_content = fs::read_to_string(CONFIG_PATH)?;
let config:HiveConfig = toml::from_str(&file_content)?;
Ok(config)
}
pub fn change_updates_check_interval(conf_file: &str, new_interval: u64) -> Result<HiveConfig, ConfigError> {
let mut config: HiveConfig = read_config(conf_file)?;
pub fn change_updates_check_interval(new_interval: u64) -> Result<HiveConfig, ConfigError> {
let mut config: HiveConfig = read_config()?;
config.update.updates_check_interval = new_interval;
let conf_str = toml::to_string_pretty(&config)?;
fs::write(conf_file, conf_str)?;
fs::write(CONFIG_PATH, conf_str)?;
Ok(config)