Skip to content

Commit 9f3ad52

Browse files
committed
dont rewrite cookie
1 parent 07533e2 commit 9f3ad52

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

client/src/config.rs

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -149,22 +149,33 @@ impl Args {
149149
args.rpc_password.as_ref().unwrap(),
150150
)
151151
} else {
152-
let cookie = format!(
153-
"__cookie__:{}",
154-
thread_rng()
155-
.sample_iter(&Alphanumeric)
156-
.take(64)
157-
.map(char::from)
158-
.collect::<String>()
159-
);
160152
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-
})?;
153+
let cookie = if cookie_path.exists() {
154+
fs::read_to_string(&cookie_path).map_err(|e| {
155+
anyhow!(
156+
"Failed to read cookie file '{}': {}",
157+
cookie_path.display(),
158+
e
159+
)
160+
})?
161+
} else {
162+
let cookie = format!(
163+
"__cookie__:{}",
164+
thread_rng()
165+
.sample_iter(&Alphanumeric)
166+
.take(64)
167+
.map(char::from)
168+
.collect::<String>()
169+
);
170+
fs::write(&cookie_path, &cookie).map_err(|e| {
171+
anyhow!(
172+
"Failed to write cookie file '{}': {}",
173+
cookie_path.display(),
174+
e
175+
)
176+
})?;
177+
cookie
178+
};
168179
auth_token_from_cookie(&cookie)
169180
};
170181

0 commit comments

Comments
 (0)