From e497adf530a63d230bf70e46edb793ab48d2d8ae Mon Sep 17 00:00:00 2001 From: ChrisJr404 Date: Thu, 1 Oct 2026 06:55:08 -0400 Subject: [PATCH] fix(config): use canonical XDG path for default config (#904) Look for the config file at the XDG-style `$XDG_CONFIG_HOME/rustscan/config.toml` first (via `dirs::config_dir()`, so the platform equivalent on macOS/Windows), then fall back to the previous `$XDG_CONFIG_HOME/.rustscan.toml` and `~/.rustscan.toml` locations so existing configs keep working. Fixes #741. --- src/input.rs | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/src/input.rs b/src/input.rs index dd5828a..a4e6dd8 100644 --- a/src/input.rs +++ b/src/input.rs @@ -295,11 +295,18 @@ impl Config { pub fn read(custom_config_path: Option) -> Self { let mut content = String::new(); let config_path = custom_config_path.unwrap_or_else(|| { - let path = default_config_path(); - match path.exists() { - true => path, - false => old_default_config_path(), + // Try the XDG-idiomatic location first, then fall back to legacy + // paths so existing users keep working unchanged. + for path in [ + default_config_path(), + legacy_dot_config_path(), + old_default_config_path(), + ] { + if path.exists() { + return path; + } } + default_config_path() }); if config_path.exists() { @@ -323,8 +330,21 @@ impl Config { } } -/// Constructs default path to config toml +/// Returns the preferred config file path: `$XDG_CONFIG_HOME/rustscan/config.toml` +/// on Linux (with the usual `~/.config` fallback when the variable is unset), +/// and the platform-equivalent `dirs::config_dir()` location on macOS / Windows. pub fn default_config_path() -> PathBuf { + let Some(mut config_path) = dirs::config_dir() else { + panic!("Could not infer config file path."); + }; + config_path.push("rustscan"); + config_path.push("config.toml"); + config_path +} + +/// Returns the transitional `$XDG_CONFIG_HOME/.rustscan.toml` path that older +/// builds wrote to. Kept readable for backwards compatibility. +pub fn legacy_dot_config_path() -> PathBuf { let Some(mut config_path) = dirs::config_dir() else { panic!("Could not infer config file path."); };