Save the config through the shared crate as well

`Config::save` was the same nine lines as dev-updater's, so it is now
`format::write(path, self)`. The reasoning that made those nine lines
correct -- the leftover temp file that keeps its old mode and is then
renamed over the token hashes -- lives with the code and its test rather
than in two places that could stop agreeing.

Verified: 35 tests, clippy silent, rustfmt clean.
This commit is contained in:
iris committed 2026-08-28 18:12:30 -04:00
1 parent b6b33dc9c5
commit 295602adfe
2 files changed
+3 -11

No files matched your search

+2 -10
View File
@@ -22,7 +22,7 @@ use std::path::{Path, PathBuf};
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use wg_app_link::{format, private}; use wg_app_link::format;
#[derive(Debug, Clone, Default, Serialize, Deserialize)] #[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase", default)] #[serde(rename_all = "camelCase", default)]
@@ -434,15 +434,7 @@ impl Config {
/// The mode is set on the temporary file *before* the rename, so the /// The mode is set on the temporary file *before* the rename, so the
/// config is never briefly world-readable at its real path. /// config is never briefly world-readable at its real path.
pub fn save(&self, path: &Path) -> Result<()> { pub fn save(&self, path: &Path) -> Result<()> {
if let Some(parent) = path.parent() { format::write(path, self)
private::create_dir(parent)?;
}
let text = format::render(self).context("serialize config")?;
let tmp = path.with_extension("ron.tmp");
private::write_file(&tmp, text.as_bytes())?;
std::fs::rename(&tmp, path)
.with_context(|| format!("replace {} with {}", path.display(), tmp.display()))?;
Ok(())
} }
} }