From 973c574a29b9c8f75f55327f01824977bd6e71ae Mon Sep 17 00:00:00 2001 From: Bruce Rosier Date: Wed, 16 Oct 2024 00:19:18 +0200 Subject: [PATCH] [eclipse-iceoryx#432] Set default location for default configuration file --- Cargo.toml | 1 + iceoryx2-bb/posix/src/system_configuration.rs | 2 +- iceoryx2-cli/Cargo.toml | 1 + iceoryx2-cli/iox2-config/src/commands.rs | 10 +++++----- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9971a7ed6..b38cc6ca6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -102,6 +102,7 @@ thiserror = { version = "1.0.56" } tiny-fn = { version = "0.1.6" } toml = { version = "0.8.13" } tracing = { version = "0.1.40" } +dirs = { version = "5.0" } windows-sys = { version = "0.48.0", features = ["Win32_Security", "Win32_Security_Authorization", "Win32_System_Memory", "Win32_System_Threading", "Win32_Foundation", "Win32_System_WindowsProgramming", "Win32_Storage_FileSystem", "Win32_System_IO", "Win32_System_Diagnostics_Debug", "Win32_System_SystemInformation", "Win32_System_Diagnostics_ToolHelp", "Win32_System_Console", "Win32_Networking_WinSock", "Win32_System_SystemServices", "Win32_System_ProcessStatus"] } diff --git a/iceoryx2-bb/posix/src/system_configuration.rs b/iceoryx2-bb/posix/src/system_configuration.rs index dd49f825b..12ace09c5 100644 --- a/iceoryx2-bb/posix/src/system_configuration.rs +++ b/iceoryx2-bb/posix/src/system_configuration.rs @@ -13,7 +13,7 @@ //! Provides information about the POSIX [`SystemInfo`], [`Limit`]s, available [`SysOption`] and //! [`Feature`]s. -use enum_iterator::{all, Sequence}; +use enum_iterator::Sequence; use iceoryx2_bb_log::{fatal_panic, warn}; use iceoryx2_pal_posix::posix::Struct; use iceoryx2_pal_posix::*; diff --git a/iceoryx2-cli/Cargo.toml b/iceoryx2-cli/Cargo.toml index 1411eccb2..b2379e95f 100644 --- a/iceoryx2-cli/Cargo.toml +++ b/iceoryx2-cli/Cargo.toml @@ -54,6 +54,7 @@ serde_yaml = { workspace = true } serde_json = { workspace = true } ron = { workspace = true } toml = { workspace = true } +dirs = { workspace = true } [dev-dependencies] iceoryx2-bb-testing = { workspace = true } diff --git a/iceoryx2-cli/iox2-config/src/commands.rs b/iceoryx2-cli/iox2-config/src/commands.rs index 5967bf1ed..f5bed05e7 100644 --- a/iceoryx2-cli/iox2-config/src/commands.rs +++ b/iceoryx2-cli/iox2-config/src/commands.rs @@ -14,9 +14,8 @@ use anyhow::Result; use enum_iterator::all; use iceoryx2::config::Config; use iceoryx2_bb_posix::system_configuration::*; -use std::fs::File; +use std::fs::{self, File}; use std::io::Write; -use std::path::Path; /// Prints the whole system configuration with all limits, features and details to the console. pub fn print_system_configuration() { @@ -109,11 +108,12 @@ pub fn show() -> Result<()> { } pub fn generate() -> Result<()> { - let default_file_path = Path::new("config/iceoryx2.toml"); + let config_dir = dirs::config_dir().unwrap().join("iceoryx2/"); + fs::create_dir_all(&config_dir)?; - let default_config = Config::default(); + let default_file_path = config_dir.join("config.toml"); - let toml_string = toml::to_string_pretty(&default_config)?; + let toml_string = toml::to_string_pretty(&Config::default())?; let mut file = File::create(&default_file_path)?; file.write_all(toml_string.as_bytes())?;