From e83ebdbfbd3328ce9c3bb2e4c3abe70e9f90c1cc Mon Sep 17 00:00:00 2001
From: sommerfeld <sommerfeld@sommerfeld.dev>
Date: Fri, 5 Jul 2024 12:20:53 +0100
Subject: Backup datafile when reseting NIP46 config

Instead of just deleting it.
---
 src/main.rs | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

(limited to 'src')

diff --git a/src/main.rs b/src/main.rs
index 9984791..24ed7de 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,6 +1,6 @@
 use std::{
     collections::HashMap,
-    fs::{remove_file, File},
+    fs::{rename, File},
     io::{stdin, BufReader, Write},
     net::IpAddr,
     path::PathBuf,
@@ -167,7 +167,11 @@ async fn setup_nostr_client(
 
 async fn create_signer(reset_nip46: bool, nip46_timeout: Duration) -> Result<Nip46Signer> {
     if reset_nip46 {
-        let _ = remove_file(get_client_data_path());
+        let path = get_client_data_path();
+        let path_str = path
+            .to_str()
+            .ok_or(anyhow!("Cannot convert path to string"))?;
+        let _ = rename(path_str, format!("{}.bak", path_str));
     }
     let client_data = get_or_generate_client_data().await?;
     let client_keys = Keys::parse(client_data.client_nsec)?;
-- 
cgit v1.2.3-70-g09d2