Instead of deleting everything and re-writing the config/secret key is changed only if updated (as per #733)
DOEG3V7UAVYBKLIPHSNWWONYDORKNJEZL2LD4EWGGUDB2SK6BOFQC 4OJWMSOWWNT5N4W4FDMKBZB5UARCLGV3SRZVKGR4EFAYFUMUHM7AC 4KJ45IJLTIE35KQZUSFMFS67RNENG4P2FZMKMULJLGGYMKJUVRSQC 5BB266P6HPUGYEVR7QNNOA62EFPYPUYJ3UMLE5J3LLYMSUWXANIQC EEBKW7VTILH6AGGV57ZIJ3DJGYHDSYBWGU3C7Q4WWAKSVNUGIYMQC SXEYMYF7P4RZMZ46WPL4IZUTSQ2ATBWYZX7QNVMS3SGOYXYOHAGQC DWSAYGVEOR4D2EKIICEZUWCRGJTUXQQLOUWMYIFV7XN62K44F4FAC A3RM526Y7LUXNYW4TL56YKQ5GVOK2R5D7JJVTSQ6TT5MEXIR6YAAC /// Write an identity to disk.////// # Arguments/// * `replace_current` - If the new identity will replace an existing onefn write(&self, replace_current: bool) -> Result<(), anyhow::Error> {
fn write_config(&self, identity_dir: &PathBuf) -> Result<(), anyhow::Error> {let config_data = toml::to_string_pretty(&self)?;let mut config_file = std::fs::File::create(identity_dir.join("identity.toml"))?;config_file.write_all(config_data.as_bytes())?;Ok(())}fn write_secret_key(&self, identity_dir: &PathBuf) -> Result<(), anyhow::Error> {let key_data = serde_json::to_string_pretty(&self.secret_key())?;let mut key_file = super::load::open_secret_file(&identity_dir.join("secret_key.json"))?;key_file.write_all(key_data.as_bytes())?;Ok(())}/// Write a complete identity to disk.fn write(&self) -> Result<(), anyhow::Error> {
let config_data = toml::to_string_pretty(&self)?;let mut config_file = std::fs::File::create(identity_dir.join("identity.toml"))?;config_file.write_all(config_data.as_bytes())?;let key_data = serde_json::to_string_pretty(&self.secret_key())?;let mut key_file = super::load::open_secret_file(&identity_dir.join("secret_key.json"))?;key_file.write_all(key_data.as_bytes())?;
// Remove the old datalet old_identity_path = path(&self.name, true)?;debug!("Removing old directory: {old_identity_path:?}");fs::remove_dir_all(old_identity_path).context("Could not remove old identity.")?;
let changed_names = self.name != new_identity.name;// If changing the identity name, remove old directoryif changed_names {let old_identity_path = path(&self.name, true)?;debug!("Removing old directory: {old_identity_path:?}");fs::remove_dir_all(old_identity_path).context("Could not remove old identity.")?;let new_identity_path = path(&new_identity.name, false)?;debug!("Creating new directory: {new_identity_path:?}");fs::create_dir_all(new_identity_path).context("Could not create new identity.")?;