aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar sommerfeld <sommerfeld@sommerfeld.dev>2024-07-05 12:20:53 +0100
committerLibravatar sommerfeld <sommerfeld@sommerfeld.dev>2024-07-05 12:20:53 +0100
commite83ebdbfbd3328ce9c3bb2e4c3abe70e9f90c1cc (patch)
tree379896483b3b0f75f5fd169f11ebfca5f7355af6
parent8740011534ac85451a92f5c331fa408304a905e9 (diff)
downloadviewercount-e83ebdbfbd3328ce9c3bb2e4c3abe70e9f90c1cc.tar.gz
viewercount-e83ebdbfbd3328ce9c3bb2e4c3abe70e9f90c1cc.tar.bz2
viewercount-e83ebdbfbd3328ce9c3bb2e4c3abe70e9f90c1cc.zip
Backup datafile when reseting NIP46 config
Instead of just deleting it.
-rw-r--r--src/main.rs8
1 files changed, 6 insertions, 2 deletions
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)?;