use crate::muragent::MuragentError;
use std::path::Path;
pub fn migrate_legacy(legacy_path: &Path, new_path: &Path) -> Result<(), MuragentError> {
if let Some(parent) = new_path.parent() {
std::fs::create_dir_all(parent).map_err(MuragentError::Io)?;
}
let empty = super::TrustStore::default();
let yaml = serde_yaml_ng::to_string(&empty)
.map_err(|e| MuragentError::Other(format!("trust store serialize: {e}")))?;
std::fs::write(new_path, &yaml).map_err(MuragentError::Io)?;
let backup = legacy_path.with_extension("json.legacy.bak");
if let Err(e) = std::fs::rename(legacy_path, &backup) {
tracing::warn!(
"could not move legacy trust.json to {}: {e}",
backup.display()
);
}
tracing::info!("migrated legacy trust.json → trust/trust.yaml (legacy preserved as .bak)");
Ok(())
}