From 9cdd83c8ae8fc6dd149b88ffeac126e1d59decec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C5=A1a=20Tomi=C4=87?= Date: Fri, 13 Dec 2024 13:35:00 +0100 Subject: [PATCH] fix: ensure local cache and registry directories are created if they do not exist (#1150) --- rs/ic-management-backend/src/registry.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/rs/ic-management-backend/src/registry.rs b/rs/ic-management-backend/src/registry.rs index f4f7d52dd..7319c5da3 100644 --- a/rs/ic-management-backend/src/registry.rs +++ b/rs/ic-management-backend/src/registry.rs @@ -901,18 +901,26 @@ fn node_ip_addr(nr: &NodeRecord) -> Ipv6Addr { } pub fn local_cache_path() -> PathBuf { - match std::env::var("LOCAL_REGISTRY_PATH") { + let path = match std::env::var("LOCAL_REGISTRY_PATH") { Ok(path) => PathBuf::from(path), Err(_) => match dirs::cache_dir() { Some(cache_dir) => cache_dir, None => PathBuf::from("/tmp"), }, } - .join("ic-registry-cache") + .join("ic-registry-cache"); + if !path.exists() { + std::fs::create_dir_all(&path).expect("failed to create local cache directory"); + } + path } pub fn local_registry_path(network: &Network) -> PathBuf { - local_cache_path().join(Path::new(network.name.as_str())).join("local_registry") + let path = local_cache_path().join(Path::new(network.name.as_str())).join("local_registry"); + if !path.exists() { + std::fs::create_dir_all(&path).expect("failed to create local registry directory"); + } + path } #[allow(dead_code)]