From 932daa897246b5e80fa9381486d3ddb8a0eeac15 Mon Sep 17 00:00:00 2001 From: Chris O'Neil Date: Wed, 17 Jan 2024 21:45:51 +0000 Subject: [PATCH] fix: create parent directories When saving the node registry, it should create all the directories in its path. --- sn_protocol/src/node_registry.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sn_protocol/src/node_registry.rs b/sn_protocol/src/node_registry.rs index 9f0f26a97e..4b58c97ea8 100644 --- a/sn_protocol/src/node_registry.rs +++ b/sn_protocol/src/node_registry.rs @@ -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())?;