Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(launchpad): use default path for nodes data dir when root(unix) #2589

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading