From a0cf28e9133fe64cbe81dcc932c209c86cb1cd57 Mon Sep 17 00:00:00 2001 From: haris Date: Tue, 31 Dec 2024 15:17:39 +0530 Subject: [PATCH] fix(launchpad): use default path for nodes data dir when root and primary mount pt When launchpad is run as root(on unix) and base directory is same as primary mount point, use default path instead, otherwise default is to use user's data directory which in case of root, is not accessible to user ant(against which antnode binary runs) --- node-launchpad/src/config.rs | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/node-launchpad/src/config.rs b/node-launchpad/src/config.rs index 6a16aab547..fe57e3628c 100644 --- a/node-launchpad/src/config.rs +++ b/node-launchpad/src/config.rs @@ -9,6 +9,7 @@ use crate::connection_mode::ConnectionMode; use crate::system::get_primary_mount_point; use crate::{action::Action, mode::Scene}; +use ant_node_manager::config::is_running_as_root; use color_eyre::eyre::{eyre, Result}; use crossterm::event::{KeyCode, KeyEvent, KeyModifiers}; use derive_deref::{Deref, DerefMut}; @@ -31,14 +32,23 @@ pub fn get_launchpad_nodes_data_dir_path( should_create: bool, ) -> Result { let mut mount_point = PathBuf::new(); + let is_root = is_running_as_root(); let data_directory: PathBuf = if *base_dir == get_primary_mount_point() { - dirs_next::data_dir().ok_or_else(|| { - eyre!( - "Data directory is not obtainable for base_dir {:?}", - base_dir - ) - })? + if is_root { + // The root's data directory isn't accessible to the user `ant`, so we are using an + // alternative default path that `ant` can access. + #[cfg(unix)] + { + let default_data_dir_path = PathBuf::from("/var/antctl/services"); + debug!("Running as root; using default path {:?} for nodes data directory instead of primary mount point", default_data_dir_path); + default_data_dir_path + } + #[cfg(windows)] + get_user_data_dir()? + } else { + get_user_data_dir()? + } } else { base_dir.clone() }; @@ -64,6 +74,10 @@ pub fn get_launchpad_nodes_data_dir_path( Ok(mount_point) } +fn get_user_data_dir() -> Result { + dirs_next::data_dir().ok_or_else(|| eyre!("User data directory is not obtainable",)) +} + /// Where to store the Launchpad config & logs. /// pub fn get_launchpad_data_dir_path() -> Result {