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 ed536d038..c2ee5a7c3 100644 --- a/iceoryx2/Cargo.toml +++ b/iceoryx2/Cargo.toml @@ -39,6 +39,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 35279519c..15477181d 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::{debug, 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)] @@ -403,25 +401,23 @@ 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() { - match Config::setup_global_config_from_file(unsafe { - &FilePath::new_unchecked(DEFAULT_CONFIG_FILE) - }) { - Ok(_) => (), - Err(ConfigCreationError::FailedToOpenConfigFile) => { - debug!(from "Config::global_config()", "Default config file not found, populate config with default values."); - ICEORYX2_CONFIG.set_value(Config::default()); - } - Err(ConfigCreationError::FailedToReadConfigFileContents) => { - warn!(from "Config::global_config()", "Default config file found but unable to read content, populate config with default values."); - ICEORYX2_CONFIG.set_value(Config::default()); - } - Err(ConfigCreationError::UnableToDeserializeContents) => { - warn!(from "Config::global_config()", "Default config file found but unable to load data, populate config with default values."); - ICEORYX2_CONFIG.set_value(Config::default()); - } - } + if !ICEORYX2_CONFIG.is_initialized() + && Config::setup_global_config_from_file(unsafe { + &FilePath::new_unchecked( + dirs::config_dir() + .unwrap() + .join("iceoryx2") + .join("config.toml") + .as_os_str() + .as_bytes(), + ) + }) + .is_err() + { + warn!(from "Config::global_config()", "Default config file found but unable to read data, populate config with default values."); + ICEORYX2_CONFIG.set_value(Config::default()); } ICEORYX2_CONFIG.get()