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

Closed
pushkarreddyy wants to merge 2 commits from upstream-pr/516 into main
pushkarreddyy commented 2026-11-24 04:22:45 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pushkarreddyy on 2026-11-24T04:22:45Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6574561805 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/516). Originally posted by [pushkarreddyy](https://github.com/pushkarreddyy) on 2026-11-24T04:22:45Z. --- ## 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 commented 2026-11-24 06:55:52 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pushkarreddyy on 2026-11-24T04:50:55Z.


### 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.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7122393019 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/516#issuecomment-7122393019). Originally posted by [pushkarreddyy](https://github.com/pushkarreddyy) on 2026-11-24T04:50:55Z. --- ### 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 commented 2026-11-24 06:56:21 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pushkarreddyy on 2026-11-24T06:24:22Z.


### 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!

<!-- greyfinch-sync:Marvisak/VIctory:comment:7123898742 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/516#issuecomment-7123898742). Originally posted by [pushkarreddyy](https://github.com/pushkarreddyy) on 2026-11-24T06:24:22Z. --- ### 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!
mercuryVM commented 2026-11-24 12:03:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T12:01:51Z.

Review: CHANGES_REQUESTED


Tested 0e48e5a on Windows 11, RTX 5070, MSVC: cargo test -p victory-core fails, 7 passed and 2 failed:

  • config::tests::environment_overrides_file and config::tests::empty_env_values_are_ignored panic at config.rs:167 and :179 with "cannot determine a user directory; set VICTORY_CACHE_DIR and VICTORY_DATA_DIR".
  • Why: Config::resolve now builds the defaults from the injected env closure (default_dir_from(name, &env)) instead of the process environment. Those two tests' closures only answer VICTORY_GAME_DIR, so LOCALAPPDATA, XDG_* and HOME are all None and the data default errors out. Using the injected env is the right change, since it makes the defaults testable, but the existing tests need an env that can resolve a directory.
  • Fix: have the two closures also return HOME (for example "HOME" => Some(OsString::from("/tmp/probe-home"))), as #708 does for the same tests.
  • Overlap: #708 fixes the same data_dir under the cache root problem, with a separate default_data_dir and a test asserting the data dir is not under the cache. Only one of the two should land. If you keep this one, the .filter(|v| !v.is_empty()) that #708 applies to an empty LOCALAPPDATA or XDG_* would be worth bringing over.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6038813529 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/516#pullrequestreview-6038813529). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T12:01:51Z. **Review:** CHANGES_REQUESTED --- Tested 0e48e5a on Windows 11, RTX 5070, MSVC: `cargo test -p victory-core` **fails, 7 passed and 2 failed**: - `config::tests::environment_overrides_file` and `config::tests::empty_env_values_are_ignored` panic at `config.rs:167` and `:179` with "cannot determine a user directory; set VICTORY_CACHE_DIR and VICTORY_DATA_DIR". - Why: `Config::resolve` now builds the defaults from the injected `env` closure (`default_dir_from(name, &env)`) instead of the process environment. Those two tests' closures only answer `VICTORY_GAME_DIR`, so `LOCALAPPDATA`, `XDG_*` and `HOME` are all `None` and the data default errors out. Using the injected env is the right change, since it makes the defaults testable, but the existing tests need an env that can resolve a directory. - Fix: have the two closures also return `HOME` (for example `"HOME" => Some(OsString::from("/tmp/probe-home"))`), as #708 does for the same tests. - Overlap: #708 fixes the same `data_dir` under the cache root problem, with a separate `default_data_dir` and a test asserting the data dir is not under the cache. Only one of the two should land. If you keep this one, the `.filter(|v| !v.is_empty())` that #708 applies to an empty `LOCALAPPDATA` or `XDG_*` would be worth bringing over. AI-assisted (Claude Code).
upstream-sync closed this pull request 2026-11-24 13:01:28 +00:00
catminou4 commented 2026-11-24 13:02:08 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T12:36:17Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7131670083 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/516#issuecomment-7131670083). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T12:36:17Z. --- 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.
pushkarreddyy commented 2026-11-24 13:02:09 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pushkarreddyy on 2026-11-24T12:37:50Z.


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.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7131705627 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/516#issuecomment-7131705627). Originally posted by [pushkarreddyy](https://github.com/pushkarreddyy) on 2026-11-24T12:37:50Z. --- 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 commented 2026-11-24 13:02:17 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pushkarreddyy on 2026-11-24T12:56:16Z.


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!

<!-- greyfinch-sync:Marvisak/VIctory:comment:7132122612 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/516#issuecomment-7132122612). Originally posted by [pushkarreddyy](https://github.com/pushkarreddyy) on 2026-11-24T12:56:16Z. --- 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

Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!516
No description provided.