From 1ec5fed27e5336aaf88d85ad1423bf3f9590f05b Mon Sep 17 00:00:00 2001 From: Bruce Rosier Date: Mon, 21 Oct 2024 23:28:47 +0200 Subject: [PATCH] [eclipse-iceoryx#432] Replace the relative path of the configuration file with the standard configuration path --- iceoryx2-cli/iox2-config/src/commands.rs | 2 +- iceoryx2/Cargo.toml | 1 + iceoryx2/src/config.rs | 16 +++++++++++----- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/iceoryx2-cli/iox2-config/src/commands.rs b/iceoryx2-cli/iox2-config/src/commands.rs index adcd2a7f7..3d19e04a5 100644 --- a/iceoryx2-cli/iox2-config/src/commands.rs +++ b/iceoryx2-cli/iox2-config/src/commands.rs @@ -113,7 +113,7 @@ pub fn show() -> Result<()> { } pub fn generate() -> Result<()> { - let config_dir = dirs::config_dir().unwrap().join("iceoryx2/"); + let config_dir = dirs::config_dir().unwrap().join("iceoryx2"); fs::create_dir_all(&config_dir)?; let default_file_path = config_dir.join("config.toml"); diff --git a/iceoryx2/Cargo.toml b/iceoryx2/Cargo.toml index bf052f7b3..fa71108d1 100644 --- a/iceoryx2/Cargo.toml +++ b/iceoryx2/Cargo.toml @@ -35,6 +35,7 @@ cdr = { workspace = true } toml = { workspace = true } sha1_smol = { workspace = true } tiny-fn = { workspace = true } +dirs = { workspace = true } [dev-dependencies] iceoryx2-bb-testing = { workspace = true } diff --git a/iceoryx2/src/config.rs b/iceoryx2/src/config.rs index 4f7851240..9f83e3e0c 100644 --- a/iceoryx2/src/config.rs +++ b/iceoryx2/src/config.rs @@ -69,6 +69,7 @@ //! # } //! ``` +use dirs; use iceoryx2_bb_container::semantic_string::SemanticString; use iceoryx2_bb_elementary::lazy_singleton::*; use iceoryx2_bb_posix::{file::FileBuilder, shared_memory::AccessMode}; @@ -76,15 +77,12 @@ use iceoryx2_bb_system_types::file_name::FileName; use iceoryx2_bb_system_types::file_path::FilePath; use iceoryx2_bb_system_types::path::Path; use serde::{Deserialize, Serialize}; -use std::time::Duration; +use std::{os::unix::ffi::OsStrExt, time::Duration}; use iceoryx2_bb_log::{fail, trace, warn}; use crate::service::port_factory::publisher::UnableToDeliverStrategy; -/// Path to the default config file -pub const DEFAULT_CONFIG_FILE: &[u8] = b"config/iceoryx2.toml"; - /// Failures occurring while creating a new [`Config`] object with [`Config::from_file()`] or /// [`Config::setup_global_config_from_file()`] #[derive(Debug, Clone, Copy, Eq, Hash, PartialEq)] @@ -394,10 +392,18 @@ impl Config { /// [`Config::setup_global_config_from_file()`] /// is called after this function was called, no file will be loaded since the global default /// config was already populated. + pub fn global_config() -> &'static Config { if !ICEORYX2_CONFIG.is_initialized() && Config::setup_global_config_from_file(unsafe { - &FilePath::new_unchecked(DEFAULT_CONFIG_FILE) + &FilePath::new_unchecked( + dirs::config_dir() + .unwrap() + .join("iceoryx2") + .join("config.toml") + .as_os_str() + .as_bytes(), + ) }) .is_err() {