Skip to content

Commit

Permalink
fix: create parent directories
Browse files Browse the repository at this point in the history
When saving the node registry, it should create all the directories in its path.
  • Loading branch information
jacderida committed Jan 18, 2024
1 parent fd2dedc commit 932daa8
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions sn_protocol/src/node_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ pub struct NodeRegistry {

impl NodeRegistry {
pub fn save(&self) -> Result<()> {
let path = Path::new(&self.save_path);
if let Some(parent) = path.parent() {
std::fs::create_dir_all(parent)?;
}

let json = serde_json::to_string(self)?;
let mut file = std::fs::File::create(self.save_path.clone())?;
file.write_all(json.as_bytes())?;
Expand Down

0 comments on commit 932daa8

Please sign in to comment.