fix: properly clear out old config file before writing new one

This commit is contained in:
beerpiss 2024-06-26 23:39:45 +07:00
parent c3f85c7397
commit 6b624dc264

View File

@ -1,7 +1,7 @@
mod defaults; mod defaults;
mod migrate; mod migrate;
use std::{collections::HashMap, path::PathBuf, str::FromStr}; use std::{collections::HashMap, fs::File, path::PathBuf, str::FromStr};
use log::{info, warn}; use log::{info, warn};
use migrate::OldSaekawaConfig; use migrate::OldSaekawaConfig;
@ -76,6 +76,12 @@ impl SaekawaConfig {
tachi: new_tachi_config, tachi: new_tachi_config,
}; };
{
// confy doesn't actually truncate the file??
if let Ok(f) = File::create("saekawa.toml") {
f.set_len(0).ok();
}
}
confy::store_path("saekawa.toml", new_config.clone()).context(ConfySnafu)?; confy::store_path("saekawa.toml", new_config.clone()).context(ConfySnafu)?;
Ok(new_config) Ok(new_config)