Skip to content

Commit 0875f72

Browse files
committed
fix cookie on first run
1 parent 2987c04 commit 0875f72

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

client/src/config.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ use std::{
55
path::PathBuf,
66
};
77

8-
use rand::{
9-
distributions::Alphanumeric,
10-
{thread_rng, Rng},
11-
};
12-
8+
use anyhow::anyhow;
139
use clap::{ArgGroup, Parser, ValueEnum};
1410
use directories::ProjectDirs;
1511
use jsonrpsee::core::Serialize;
1612
use log::error;
13+
use rand::{
14+
distributions::Alphanumeric,
15+
{thread_rng, Rng},
16+
};
1717
use serde::Deserialize;
1818
use spaces_protocol::bitcoin::Network;
1919

@@ -127,6 +127,7 @@ impl Args {
127127
Some(data_dir) => data_dir,
128128
}
129129
.join(args.chain.to_string());
130+
fs::create_dir_all(data_dir.clone())?;
130131

131132
let default_port = args.rpc_port.unwrap();
132133
let rpc_bind_addresses: Vec<SocketAddr> = args
@@ -156,7 +157,14 @@ impl Args {
156157
.map(char::from)
157158
.collect::<String>()
158159
);
159-
fs::write(data_dir.join(".cookie"), &cookie)?;
160+
let cookie_path = data_dir.join(".cookie");
161+
fs::write(&cookie_path, &cookie).map_err(|e| {
162+
anyhow!(
163+
"Failed to write cookie file '{}': {}",
164+
cookie_path.display(),
165+
e
166+
)
167+
})?;
160168
auth_token_from_cookie(&cookie)
161169
};
162170

@@ -177,8 +185,6 @@ impl Args {
177185

178186
let genesis = Spaced::genesis(args.chain);
179187

180-
fs::create_dir_all(data_dir.clone())?;
181-
182188
let proto_db_path = data_dir.join("protocol.sdb");
183189
let initial_sync = !proto_db_path.exists();
184190

0 commit comments

Comments
 (0)