Skip to content

Commit

Permalink
fix(launchpad): use default path for nodes data dir when root and pri…
Browse files Browse the repository at this point in the history
…mary 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)
  • Loading branch information
harismuzaffer committed Jan 1, 2025
1 parent f92438c commit 93c757a
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions node-launchpad/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -31,14 +32,23 @@ pub fn get_launchpad_nodes_data_dir_path(
should_create: bool,
) -> Result<PathBuf> {
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()
};
Expand All @@ -64,6 +74,10 @@ pub fn get_launchpad_nodes_data_dir_path(
Ok(mount_point)
}

fn get_user_data_dir() -> Result<PathBuf> {
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<PathBuf> {
Expand Down

0 comments on commit 93c757a

Please sign in to comment.