From d4f97070501b32863ccf0dd8de454f2a86433f0f Mon Sep 17 00:00:00 2001 From: "Chris (ChrisJr404)" <11917633+ChrisJr404@users.noreply.github.com> Date: Sun, 3 May 2026 10:50:43 -0400 Subject: [PATCH] fix(config): use canonical XDG path $XDG_CONFIG_HOME/rustscan/config.toml (#741) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The XDG support added in 2020 was rewritten at some point into dirs::config_dir().push(".rustscan.toml") which produces `~/.config/.rustscan.toml` on Linux — a leading-dot filename inside the already-hidden `.config` directory, which isn't the form the spec recommends (and isn't the form mulc's original commit a0561d4 introduced). This restores the canonical `$XDG_CONFIG_HOME/rustscan/config.toml` path as the primary config location while preserving full backwards compatibility: the loader now searches, in order, 1. $XDG_CONFIG_HOME/rustscan/config.toml (preferred, XDG-idiomatic) 2. $XDG_CONFIG_HOME/.rustscan.toml (transitional) 3. ~/.rustscan.toml (legacy) so any user who already adopted the leading-dot form keeps working unchanged, and `~/.rustscan.toml` continues to be honoured. Closes #741. --- src/input.rs | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/src/input.rs b/src/input.rs index 8a08845af..7f1b24035 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() { @@ -321,8 +328,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."); };