mirror of
https://github.com/Cuprate/cuprate.git
synced 2025-04-23 06:18:12 +00:00
Use blank peer list if saved peer list cannot be read. (#426)
* Use blank peer list if saved peer list cannot be read. * Format corrections * The delete operation is not needed.
This commit is contained in:
parent
95aca1d4a5
commit
24265ac43c
2 changed files with 11 additions and 3 deletions
|
@ -67,8 +67,11 @@ pub async fn init_address_book<Z: BorshNetworkZone>(
|
|||
Ok(res) => res,
|
||||
Err(e) if e.kind() == ErrorKind::NotFound => (vec![], vec![]),
|
||||
Err(e) => {
|
||||
tracing::error!("Failed to open peer list, {}", e);
|
||||
panic!("{e}");
|
||||
tracing::error!(
|
||||
"Error: Failed to open peer list,\n{},\nstarting with an empty list",
|
||||
e
|
||||
);
|
||||
(vec![], vec![])
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -41,10 +41,15 @@ pub(crate) fn save_peers_to_disk<Z: BorshNetworkZone>(
|
|||
|
||||
let dir = cfg.peer_store_directory.clone();
|
||||
let file = dir.join(Z::NAME);
|
||||
let mut tmp_file = file.clone();
|
||||
tmp_file.set_extension("tmp");
|
||||
|
||||
spawn_blocking(move || {
|
||||
fs::create_dir_all(dir)?;
|
||||
fs::write(&file, &data)
|
||||
match fs::write(&tmp_file, &data) {
|
||||
Ok(_) => fs::rename(tmp_file, file),
|
||||
Err(x) => Err(x),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue