-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Reset peers.json if the content is not loadable #405
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -176,21 +176,18 @@ impl NetworkState { | |
| let node_store = if let Some(ref path) = config.net_config_path { | ||
| let path = Path::new(path).join(NODES_FILE); | ||
| if let Ok(node_store) = JsonPeerstore::new(path.clone()) { | ||
| debug!(target: "sub-libp2p", "Initialized peer store for JSON \ | ||
| file {:?}", path); | ||
| debug!(target: "sub-libp2p", "Initialized peer store for JSON file {:?}", path); | ||
| NodeStore::Json(node_store) | ||
| } else { | ||
| warn!(target: "sub-libp2p", "Failed to open peer storage {:?}\ | ||
| ; peers file will be reset", path); | ||
| warn!(target: "sub-libp2p", "Failed to open peer storage {:?}; peers file will be reset", path); | ||
| fs::remove_file(&path).expect("Failed deleting peers.json"); | ||
|
|
||
| // we check for about 1s if the file was really deleted and move on | ||
| for _x in 0..200 { | ||
| if !Path::new(&path).exists() { | ||
| break; | ||
| } else { | ||
| debug!("Waiting for effective deletion of invalid/outdate \ | ||
| peers.json"); | ||
| debug!("Waiting for effective deletion of invalid/outdate peers.json"); | ||
| thread::sleep(time::Duration::from_millis(5)); | ||
| } | ||
| } | ||
|
|
@@ -199,14 +196,15 @@ impl NetworkState { | |
| debug!("peers.json reset"); | ||
| NodeStore::Json(peerstore) | ||
| } else { | ||
| warn!(target: "sub-libp2p", "Failed to reset peer storage\ | ||
| {:?}; peers change will not be saved", path); | ||
| warn!(target: "sub-libp2p", | ||
| "Failed to reset peer storage {:?}; peers change will not be saved", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can also happen if the user doesn't have the permission to open the file, so the message should just be
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would not the message L182 already say that? If the file cannot be open because of permissions, this should be caught by the first tests. The message |
||
| path | ||
| ); | ||
| NodeStore::Memory(MemoryPeerstore::empty()) | ||
| } | ||
| } | ||
| } else { | ||
| debug!(target: "sub-libp2p", "No peers file configured ; peers \ | ||
| won't be saved"); | ||
| debug!(target: "sub-libp2p", "No peers file configured ; peers won't be saved"); | ||
| NodeStore::Memory(MemoryPeerstore::empty()) | ||
| }; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this also happens if the file doesn't exist in the first place, ie. if the user starts polkadot for the first time, so the message is not totally correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the file does not exist in the first place, the first test L179 will kick in and the message you mention L196 will never show up.