Skip to content

fix: ignore empty or relative XDG base directory variables - #3833

Open
M1lan wants to merge 1 commit into
atuinsh:mainfrom
M1lan:fix/xdg-ignore-relative-dirs
Open

fix: ignore empty or relative XDG base directory variables#3833
M1lan wants to merge 1 commit into
atuinsh:mainfrom
M1lan:fix/xdg-ignore-relative-dirs

Conversation

@M1lan

@M1lan M1lan commented Aug 1, 2026

Copy link
Copy Markdown

Problem

config_dir(), data_dir() and runtime_dir() in atuin-common use the raw value of XDG_CONFIG_HOME / XDG_DATA_HOME / XDG_RUNTIME_DIR without validating it. The XDG Base Directory Specification requires that empty or non-absolute values be ignored.

With XDG_CONFIG_HOME set but empty, config_dir() returns the relative path atuin, and Settings::get_config_path() then create_dir_all()s it — leaving a stray empty ./atuin directory in whatever cwd the process ran from.

Reproduce:

cd /tmp && XDG_CONFIG_HOME= atuin info >/dev/null; ls -d atuin

Fix

Shared xdg_dir() helper: use the env var only when it parses to an absolute path, otherwise fall back to the spec default. Applied to config_dir(), data_dir() and runtime_dir().

Unit tests added for the empty and relative cases (wired into the existing sequential test_dirs runner).

Per the XDG Base Directory Specification, XDG_CONFIG_HOME, XDG_DATA_HOME
and XDG_RUNTIME_DIR values that are empty or not absolute paths are
invalid and must be ignored, falling back to the defaults.

Previously an empty XDG_CONFIG_HOME made config_dir() return the
relative path "atuin", and Settings::get_config_path() would then
create a stray ./atuin directory in whatever cwd the process happened
to run from.
@greptile-apps

greptile-apps Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Fixes XDG base-directory handling by ignoring empty or relative environment values.

  • Adds a shared absolute-path validation helper.
  • Applies it to config, data, and runtime directories.
  • Adds sequential tests for invalid config and data directory values.

Confidence Score: 5/5

The PR appears safe to merge.

The changed directory functions reject invalid XDG values while retaining existing behavior for valid absolute paths and unset variables.

Important Files Changed

Filename Overview
crates/atuin-common/src/utils.rs The helper correctly validates XDG paths and preserves existing fallbacks; no actionable defect found.

Reviews (1): Last reviewed commit: "fix: ignore empty or relative XDG base d..." | Re-trigger Greptile

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.

1 participant