From 356b4b172806b7e63f35920950b18b535651de52 Mon Sep 17 00:00:00 2001 From: 0Ky <16103757+0Ky@users.noreply.github.com> Date: Sat, 21 Oct 2023 08:44:49 +1100 Subject: [PATCH] fix(paths): add os specific directory handling for windows Adjusted the path generation in `get_results_dir_path`, `handle_main_command`, and `setup_terminal` to account for Windows-specific local config directory conventions using the `cfg!` macro. --- src/main.rs | 29 +++++++++++++++++++---------- src/test_results.rs | 14 +++++++++----- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/src/main.rs b/src/main.rs index a34197a..a94dcd6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -130,11 +130,16 @@ fn handle_main_command( terminal: &mut Terminal>, args: Args, ) -> Result<()> { - let config_file_path = dirs::home_dir() - .context("Unable to get home directory")? - .join(".config") - .join("donkeytype") - .join("donkeytype-config.json"); + let config_file_path = if cfg!(target_os = "windows") { + dirs::config_local_dir().context("Unable to get local config directory")? + } else { + dirs::home_dir() + .context("Unable to get home directory")? + .join(".config") + } + .join("donkeytype") + .join("donkeytype-config.json"); + let config = Config::new(args, config_file_path).context("Unable to create config")?; let expected_input = ExpectedInput::new(&config).context("Unable to create expected input")?; @@ -234,11 +239,15 @@ mod tests { } fn setup_terminal(args: Args) -> Result<(Config, ExpectedInput, Terminal)> { - let config_file_path = dirs::home_dir() - .context("Unable to get home directory")? - .join(".config") - .join("donkeytype") - .join("donkeytype-config.json"); + let config_file_path = if cfg!(target_os = "windows") { + dirs::config_local_dir().context("Unable to get local config directory")? + } else { + dirs::home_dir() + .context("Unable to get home directory")? + .join(".config") + } + .join("donkeytype") + .join("donkeytype-config.json"); let config = Config::new(args, config_file_path).context("Unable to create config")?; let expected_input = diff --git a/src/test_results.rs b/src/test_results.rs index e9164eb..0b34479 100644 --- a/src/test_results.rs +++ b/src/test_results.rs @@ -404,11 +404,15 @@ fn render_chart( } fn get_results_dir_path() -> Result { - let dir_path = dirs::home_dir() - .context("Unable to get home directory")? - .join(".local") - .join("share") - .join("donkeytype"); + let dir_path = if cfg!(target_os = "windows") { + dirs::config_local_dir().context("Unable to get local config directory")? + } else { + dirs::home_dir() + .context("Unable to get home directory")? + .join(".local") + .join("share") + } + .join("donkeytype"); Ok(dir_path) }