From 7424883635050bb163d69b5c3e3c8749eeb87f8e Mon Sep 17 00:00:00 2001 From: Roland Sherwin Date: Sat, 7 Dec 2024 16:16:13 +0530 Subject: [PATCH] feat(antctl): use custom bootstrap cache path for root users --- ant-node-manager/src/cmd/node.rs | 6 ++++++ ant-node-manager/src/config.rs | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/ant-node-manager/src/cmd/node.rs b/ant-node-manager/src/cmd/node.rs index a96a0bb118..fd4b938bbc 100644 --- a/ant-node-manager/src/cmd/node.rs +++ b/ant-node-manager/src/cmd/node.rs @@ -83,6 +83,11 @@ pub async fn add( config::get_service_data_dir_path(data_dir_path, service_user.clone())?; let service_log_dir_path = config::get_service_log_dir_path(ReleaseType::AntNode, log_dir_path, service_user.clone())?; + let bootstrap_cache_dir = if let Some(user) = &service_user { + Some(config::get_bootstrap_cache_owner_path(user)?) + } else { + None + }; let mut node_registry = NodeRegistry::load(&config::get_node_registry_path()?)?; let release_repo = ::default_config(); @@ -105,6 +110,7 @@ pub async fn add( debug!("Parsing peers from PeersArgs"); peers_args.addrs.extend(PeersArgs::read_addr_from_env()); + peers_args.bootstrap_cache_dir = bootstrap_cache_dir; let options = AddNodeServiceOptions { auto_restart, diff --git a/ant-node-manager/src/config.rs b/ant-node-manager/src/config.rs index f0c47f7ab2..946afdf5ab 100644 --- a/ant-node-manager/src/config.rs +++ b/ant-node-manager/src/config.rs @@ -159,6 +159,22 @@ pub fn get_service_data_dir_path( Ok(path) } +/// Get the bootstrap cache owner path +#[cfg(unix)] +pub fn get_bootstrap_cache_owner_path(owner: &str) -> Result { + let path = PathBuf::from("/var/antctl/bootstrap_cache"); + + create_owned_dir(path.clone(), owner)?; + Ok(path) +} + +#[cfg(windows)] +pub fn get_bootstrap_cache_owner_path(_owner: &str) -> Result { + let path = PathBuf::from("C:\\ProgramData\\antctl\\bootstrap_cache"); + std::fs::create_dir_all(&path)?; + Ok(path) +} + /// Get the logging directory for the service. /// /// It's a little counter-intuitive, but the owner will be `None` in the case of a user-mode