Skip to content

fix(config): use canonical XDG path for default config (#741)#904

Open
ChrisJr404 wants to merge 1 commit intobee-san:masterfrom
ChrisJr404:xdg-config-path
Open

fix(config): use canonical XDG path for default config (#741)#904
ChrisJr404 wants to merge 1 commit intobee-san:masterfrom
ChrisJr404:xdg-config-path

Conversation

@ChrisJr404
Copy link
Copy Markdown

Closes #741.

Background

The XDG support originally added to RustScan in 2020 (commit a0561d4 by @mulc) was structured as $XDG_CONFIG_HOME/rustscan/config.toml. At some point that was refactored into

dirs::config_dir().push(".rustscan.toml")

which on Linux resolves to ~/.config/.rustscan.toml — a leading-dot filename inside the already-hidden .config/ directory. That isn't the form the XDG Base Directory Specification recommends, and it isn't the form mulc's commit introduced.

Change

Restore the canonical $XDG_CONFIG_HOME/rustscan/config.toml path as the primary config location, while preserving full backwards compatibility for both legacy paths.

The loader now searches, in this order:

  1. $XDG_CONFIG_HOME/rustscan/config.toml — preferred, XDG-idiomatic
  2. $XDG_CONFIG_HOME/.rustscan.toml — transitional, kept for users who already adopted it
  3. ~/.rustscan.toml — legacy

Any user who already has a working config file in path 2 or 3 keeps working unchanged.

On macOS this maps to ~/Library/Application Support/rustscan/config.toml, on Windows to {FOLDERID_RoamingAppData}/rustscan/config.toml — both via the existing dirs::config_dir() crate. The Linux behavior is what users in the issue thread are asking for; the macOS/Windows behavior was already happening because of dirs::config_dir().

Verification

$ XDG_CONFIG_HOME=/tmp/xdg-test mkdir -p /tmp/xdg-test/rustscan
$ printf 'addresses = ["127.0.0.1"]\nports = [22]\n' > /tmp/xdg-test/rustscan/config.toml
$ XDG_CONFIG_HOME=/tmp/xdg-test rustscan -a 127.0.0.1 -p 22
[~] The config file is expected to be at "/tmp/xdg-test/rustscan/config.toml"
[~] For backwards compatibility, the config file may also be at "/home/<user>/.rustscan.toml"
...

cargo test --lib passes (50 tests, including the existing config tests).

Diff is +25 / -5 lines, single file, no public-API change beyond adding the new legacy_dot_config_path() helper.

…toml (bee-san#741)

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 bee-san#741.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

use $XDG_CONFIG_HOME for default config file path

1 participant