From 1d464a4b327e90f1aa314de20f6d9a38ee4b6f35 Mon Sep 17 00:00:00 2001 From: Vincenzo Palazzo Date: Sat, 30 Dec 2023 11:43:56 +0100 Subject: [PATCH] fix(cmd): check if the ln path that we know are good Sometime we may do operation like delete a directory that it is linked with coffee, but we forget it. So this code make sure that we are operating on a safe information. Link: https://github.com/coffee-tools/coffee/issues/209 Signed-off-by: Vincenzo Palazzo --- coffee_core/src/coffee.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/coffee_core/src/coffee.rs b/coffee_core/src/coffee.rs index 6b087799..d83681de 100644 --- a/coffee_core/src/coffee.rs +++ b/coffee_core/src/coffee.rs @@ -196,6 +196,16 @@ impl CoffeeManager { return Ok(()); } let root = self.config.cln_root.clone().unwrap(); + // We check if there is some problem we the path that we know + if !fs::try_exists(root.clone()).await? { + return Err(error!("lightning root path `{}` do not exist", root)); + } else if !fs::try_exists(format!("{root}/{}", self.config.network)).await? { + return Err(error!( + "lightning network path `{root}/{}` do not exist", + self.config.network + )); + } + // All safe, we can move with the logic let rpc = Client::new(format!("{root}/{}/lightning-rpc", self.config.network)); self.rpc = Some(rpc); let path = self.config.cln_config_path.clone().unwrap();