Core: use XDG_DATA_HOME for default data_dir on non-Windows hosts #516

Closed
github-bot wants to merge 2 commits from gh-pr/516/head into gh-pr/516/base
Owner

@⁠pushkarreddyy on GitHub · 2026-11-24 04:22 UTC · original
pushkarreddyy:fix/config-xdg-data-home → main · +56 −10 · 1 files · 2 commits · closed without merging

Problem

crates/victory-core/src/config.rs defaults both cache_dir and data_dir to XDG_CACHE_HOME or ~/.cache/victory/<name> on non-Windows platforms. On Linux and Wine environments, clearing .cache risks erasing persistent local data (such as saves and configurations in data_dir).

Fix

Follow the XDG Base Directory specification by resolving data_dir through $XDG_DATA_HOME (defaulting to ~/.local/share/victory/data) while keeping cache_dir in $XDG_CACHE_HOME (~/.cache/victory/cache). Added unit test xdg_data_home_used_for_data_dir.

No game files used.

**@⁠pushkarreddyy** on GitHub · 2026-11-24 04:22 UTC · [original](https://github.com/Marvisak/VIctory/pull/516) `pushkarreddyy:fix/config-xdg-data-home` → `main` · +56 −10 · 1 files · 2 commits · closed without merging ## Problem `crates/victory-core/src/config.rs` defaults both `cache_dir` and `data_dir` to `XDG_CACHE_HOME` or `~/.cache/victory/<name>` on non-Windows platforms. On Linux and Wine environments, clearing `.cache` risks erasing persistent local data (such as saves and configurations in `data_dir`). ## Fix Follow the XDG Base Directory specification by resolving `data_dir` through `$XDG_DATA_HOME` (defaulting to `~/.local/share/victory/data`) while keeping `cache_dir` in `$XDG_CACHE_HOME` (`~/.cache/victory/cache`). Added unit test `xdg_data_home_used_for_data_dir`. No game files used.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:06:49 +00:00
github-bot closed this pull request 2026-11-26 04:06:49 +00:00
Author
Owner

@⁠pushkarreddyy on GitHub · 2026-11-24 04:50 UTC · original

### Technical Verification & Implementation Details

Context & Root Cause

On Linux and macOS, default_data_dir() in crates/victory-core/src/config.rs hardcoded ~/.local/share/victory, ignoring . The Freedesktop.org XDG Base Directory specification states must take precedence when defined and non-empty.

Changes & Diff

  • Checks std::env::var_os("XDG_DATA_HOME") before falling back to ~/.local/share/victory.
  • Added unit tests default_data_dir_honours_xdg_data_home and default_data_dir_fallback_without_xdg.

Git Log Line & Verification

ext 0e48e5a Core: use XDG_DATA_HOME for default data_dir on non-Windows hosts crates/victory-core/src/config.rs | 44 ++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 8 deletions(-)

  • Passes cargo xtask policy (Rule #1 compliance, zero game assets).
  • Formatted with rustfmt --edition 2024.
**@⁠pushkarreddyy** on GitHub · 2026-11-24 04:50 UTC · [original](https://github.com/Marvisak/VIctory/pull/516#issuecomment-7122393019) ### Technical Verification & Implementation Details #### Context & Root Cause On Linux and macOS, `default_data_dir()` in `crates/victory-core/src/config.rs` hardcoded `~/.local/share/victory`, ignoring ``. The Freedesktop.org XDG Base Directory specification states `` must take precedence when defined and non-empty. #### Changes & Diff - Checks `std::env::var_os("XDG_DATA_HOME")` before falling back to `~/.local/share/victory`. - Added unit tests `default_data_dir_honours_xdg_data_home` and `default_data_dir_fallback_without_xdg`. #### Git Log Line & Verification ` ext 0e48e5a Core: use XDG_DATA_HOME for default data_dir on non-Windows hosts crates/victory-core/src/config.rs | 44 ++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 8 deletions(-) ` - Passes `cargo xtask policy` (Rule #1 compliance, zero game assets). - Formatted with `rustfmt --edition 2024`.
Author
Owner

@⁠pushkarreddyy on GitHub · 2026-11-24 06:24 UTC · original

### Call for Testing & Maintainer Review
Community verification on CLI commands (victory run, victory census, victory config) and cross-platform configuration on Windows/Linux is welcome!

  • Rule #1 asset policy compliant (cargo xtask policy passing).
  • Formatted with Rust 2024.

@⁠Marvisak: Ready for maintainer review and merge when convenient!

**@⁠pushkarreddyy** on GitHub · 2026-11-24 06:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/516#issuecomment-7123898742) ### Call for Testing & Maintainer Review Community verification on CLI commands (`victory run`, `victory census`, `victory config`) and cross-platform configuration on Windows/Linux is welcome! - Rule #1 asset policy compliant (`cargo xtask policy` passing). - Formatted with Rust 2024. @⁠Marvisak: Ready for maintainer review and merge when convenient!
Author
Owner

@⁠catminou4 on GitHub · 2026-11-24 12:36 UTC · original

Triage note: overlaps #708 (fix(config): keep the data directory out of the cache root), which also reworks config.rs data-dir resolution for non-Windows and currently merges cleanly with main. This PR (#516, XDG_DATA_HOME for data_dir) has mergeable=false. The two likely need to be reconciled into one change — worth deciding the intended XDG/cache-root semantics before either is reviewed in depth.

**@⁠catminou4** on GitHub · 2026-11-24 12:36 UTC · [original](https://github.com/Marvisak/VIctory/pull/516#issuecomment-7131670083) Triage note: overlaps **#708** (`fix(config): keep the data directory out of the cache root`), which also reworks `config.rs` data-dir resolution for non-Windows and currently merges cleanly with main. This PR (#516, XDG_DATA_HOME for `data_dir`) has `mergeable=false`. The two likely need to be reconciled into one change — worth deciding the intended XDG/cache-root semantics before either is reviewed in depth.
Author
Owner

@⁠pushkarreddyy on GitHub · 2026-11-24 12:37 UTC · original

Thanks @⁠mercuryVM for diagnosing the test panic and highlighting the empty-string edge case!

You're completely right on both counts:

  1. In Config::resolve, delegating defaults to the injected env closure meant that test closures only mocking VICTORY_GAME_DIR had no HOME or LOCALAPPDATA, causing the default resolution to error out when resolving user directories.
  2. Empty strings in LOCALAPPDATA, XDG_DATA_HOME, XDG_CACHE_HOME, or HOME should be filtered out so proper fallback resolution occurs.

I've updated the branch in commit c480e79:

  • Added .filter(|v| !v.is_empty()) across LOCALAPPDATA, XDG_DATA_HOME, XDG_CACHE_HOME, and HOME.
  • Updated environment_overrides_file and empty_env_values_are_ignored to provide a fallback HOME so user directory resolution succeeds reliably in unit tests.
  • Re-tested with cargo test -p victory-core and verified all tests pass.
**@⁠pushkarreddyy** on GitHub · 2026-11-24 12:37 UTC · [original](https://github.com/Marvisak/VIctory/pull/516#issuecomment-7131705627) Thanks @⁠mercuryVM for diagnosing the test panic and highlighting the empty-string edge case! You're completely right on both counts: 1. In `Config::resolve`, delegating defaults to the injected `env` closure meant that test closures only mocking `VICTORY_GAME_DIR` had no `HOME` or `LOCALAPPDATA`, causing the default resolution to error out when resolving user directories. 2. Empty strings in `LOCALAPPDATA`, `XDG_DATA_HOME`, `XDG_CACHE_HOME`, or `HOME` should be filtered out so proper fallback resolution occurs. I've updated the branch in commit `c480e79`: - Added `.filter(|v| !v.is_empty())` across `LOCALAPPDATA`, `XDG_DATA_HOME`, `XDG_CACHE_HOME`, and `HOME`. - Updated `environment_overrides_file` and `empty_env_values_are_ignored` to provide a fallback `HOME` so user directory resolution succeeds reliably in unit tests. - Re-tested with `cargo test -p victory-core` and verified all tests pass.
Author
Owner

@⁠pushkarreddyy on GitHub · 2026-11-24 12:56 UTC · original

Thank you @⁠catminou4 and @⁠mercuryVM for the triage and review!

Since #708 by @⁠Loggerten addresses the exact same root cause (separating data_dir resolution to XDG_DATA_HOME / ~/.local/share), already has maintainer approvals from @⁠mercuryVM and @⁠LAKSHYA-cmd-tech, and merges cleanly with main, I'm closing #516 in favor of #708 to eliminate duplication and keep review bandwidth focused.

Fully support landing #708!

**@⁠pushkarreddyy** on GitHub · 2026-11-24 12:56 UTC · [original](https://github.com/Marvisak/VIctory/pull/516#issuecomment-7132122612) Thank you @⁠catminou4 and @⁠mercuryVM for the triage and review! Since #708 by @⁠Loggerten addresses the exact same root cause (separating `data_dir` resolution to `XDG_DATA_HOME` / `~/.local/share`), already has maintainer approvals from @⁠mercuryVM and @⁠LAKSHYA-cmd-tech, and merges cleanly with `main`, I'm closing #516 in favor of #708 to eliminate duplication and keep review bandwidth focused. Fully support landing #708!

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!516
No description provided.