core: resolve default data_dir via XDG_DATA_HOME on non-Windows hosts (fix on a fork) #899

Open
opened 2026-11-26 04:14:08 +00:00 by github-bot · 2 comments
Owner

@⁠DaniiL35 on GitHub · 2026-11-24 13:46 UTC · original

Pull requests are currently restricted to collaborators (#717), so I am sharing this bug report and verified fix from a clean fork branch off main (ffe310e).

• Branch: https://github.com/DaniiL35/VIctory/tree/fix/config-xdg-data-dir
• Commit: 5fcfd91 (based on main ffe310e, crates/victory-core/src/config.rs +77/-9)
• Compare: https://github.com/Marvisak/VIctory/compare/main...DaniiL35:VIctory:fix/config-xdg-data-dir

Problem

In crates/victory-core/src/config.rs (line 20), data_dir is documented:

"What titles write and must keep (persistent local storage). Never inside the cache, which may be deleted at any time."

However, default_dir (lines 130–137) resolved both "cache" and "data" using the exact same fallback chain:

let base = std::env::var_os("LOCALAPPDATA")
    .or_else(|| std::env::var_os("XDG_CACHE_HOME"))
    .map(PathBuf::from)
    .or_else(|| std::env::var_os("HOME").map(|h| PathBuf::from(h).join(".cache")))

On Linux, macOS, and POSIX environments where VICTORY_DATA_DIR is not explicitly set in victory.toml, data_dir defaulted to $XDG_CACHE_HOME/victory/data or $HOME/.cache/victory/data. A routine cache purge (e.g. rm -rf ~/.cache) would unintentionally delete the user's persistent saves, local storage, and crashes.log.

Furthermore, default_dir read from std::env::var_os directly rather than the env closure passed into Config::resolve, preventing default directory resolution from being unit-tested in isolation without mutating process environment variables.

Fix

  1. Factor default directory lookup into default_dir_with(&env, name).
  2. For "data", query XDG_DATA_HOME (and fallback $HOME/.local/share) before falling back to cache locations:
    • Windows continues using %LOCALAPPDATA%\victory\data (highest precedence).
    • Linux/macOS defaults data_dir to $XDG_DATA_HOME/victory/data or $HOME/.local/share/victory/data, keeping persistent data strictly outside the cache.
    • For "cache", behavior is unchanged (LOCALAPPDATA -> XDG_CACHE_HOME -> $HOME/.cache).
  3. Parameterizing with &env enables pure, deterministic unit testing of directory resolution.

Tests Added

Added 3 synthetic unit tests in crates/victory-core/src/config.rs:

  • default_data_dir_uses_xdg_data_home_on_unix: verifies data_dir resolves to $XDG_DATA_HOME/victory/data while cache_dir resolves to $XDG_CACHE_HOME/victory/cache.
  • default_data_dir_falls_back_to_local_share_with_home: verifies that when only HOME is present, data_dir falls back to $HOME/.local/share/victory/data and not $HOME/.cache.
  • localappdata_takes_precedence_for_both: verifies Windows %LOCALAPPDATA% takes precedence for both directories.

Verification & Policy Compliance

  • Pure synthetic paths; no game assets or SDK binaries.
  • Complies with Rule #1 (Asset Policy) and passes cargo xtask policy (text-only, <512 KiB).
  • Formatted with Rust 2024 edition.
  • Clean diff on top of main (ffe310e).

AI-assisted with Antigravity.

**@⁠DaniiL35** on GitHub · 2026-11-24 13:46 UTC · [original](https://github.com/Marvisak/VIctory/issues/899) Pull requests are currently restricted to collaborators (#717), so I am sharing this bug report and verified fix from a clean fork branch off `main` (`ffe310e`). • **Branch**: https://github.com/DaniiL35/VIctory/tree/fix/config-xdg-data-dir • **Commit**: `5fcfd91` (based on `main` `ffe310e`, `crates/victory-core/src/config.rs` +77/-9) • **Compare**: https://github.com/Marvisak/VIctory/compare/main...DaniiL35:VIctory:fix/config-xdg-data-dir ### Problem In `crates/victory-core/src/config.rs` (line 20), `data_dir` is documented: > "What titles write and must keep (persistent local storage). Never inside the cache, which may be deleted at any time." However, `default_dir` (lines 130–137) resolved both `"cache"` and `"data"` using the exact same fallback chain: ```rust let base = std::env::var_os("LOCALAPPDATA") .or_else(|| std::env::var_os("XDG_CACHE_HOME")) .map(PathBuf::from) .or_else(|| std::env::var_os("HOME").map(|h| PathBuf::from(h).join(".cache"))) ``` On Linux, macOS, and POSIX environments where `VICTORY_DATA_DIR` is not explicitly set in `victory.toml`, `data_dir` defaulted to `$XDG_CACHE_HOME/victory/data` or `$HOME/.cache/victory/data`. A routine cache purge (e.g. `rm -rf ~/.cache`) would unintentionally delete the user's persistent saves, local storage, and `crashes.log`. Furthermore, `default_dir` read from `std::env::var_os` directly rather than the `env` closure passed into `Config::resolve`, preventing default directory resolution from being unit-tested in isolation without mutating process environment variables. ### Fix 1. Factor default directory lookup into `default_dir_with(&env, name)`. 2. For `"data"`, query `XDG_DATA_HOME` (and fallback `$HOME/.local/share`) before falling back to cache locations: - Windows continues using `%LOCALAPPDATA%\victory\data` (highest precedence). - Linux/macOS defaults `data_dir` to `$XDG_DATA_HOME/victory/data` or `$HOME/.local/share/victory/data`, keeping persistent data strictly outside the cache. - For `"cache"`, behavior is unchanged (`LOCALAPPDATA` -> `XDG_CACHE_HOME` -> `$HOME/.cache`). 3. Parameterizing with `&env` enables pure, deterministic unit testing of directory resolution. ### Tests Added Added 3 synthetic unit tests in `crates/victory-core/src/config.rs`: - `default_data_dir_uses_xdg_data_home_on_unix`: verifies `data_dir` resolves to `$XDG_DATA_HOME/victory/data` while `cache_dir` resolves to `$XDG_CACHE_HOME/victory/cache`. - `default_data_dir_falls_back_to_local_share_with_home`: verifies that when only `HOME` is present, `data_dir` falls back to `$HOME/.local/share/victory/data` and not `$HOME/.cache`. - `localappdata_takes_precedence_for_both`: verifies Windows `%LOCALAPPDATA%` takes precedence for both directories. ### Verification & Policy Compliance - Pure synthetic paths; no game assets or SDK binaries. - Complies with Rule #1 (Asset Policy) and passes `cargo xtask policy` (text-only, <512 KiB). - Formatted with Rust 2024 edition. - Clean diff on top of `main` (`ffe310e`). AI-assisted with Antigravity.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:14:08 +00:00
Author
Owner

@⁠DaniiL35 on GitHub · 2026-11-24 16:17 UTC · original

PR opened directly: #1151

**@⁠DaniiL35** on GitHub · 2026-11-24 16:17 UTC · [original](https://github.com/Marvisak/VIctory/issues/899#issuecomment-7137413739) PR opened directly: #1151
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 06:50 UTC · original

Automated triage for the maintainers.

Confirmed on current main: default_dir in crates/victory-core/src/config.rs uses the same LOCALAPPDATA → XDG_CACHE_HOME → $HOME/.cache chain for both cache and data, so off Windows the persistent data directory defaults to a cache location, against the data_dir doc comment. On Windows (the supported host) it is %LOCALAPPDATA%\victory\data and unaffected. PR #1151 was closed without merging and I found no other open PR; please open one again against current main if you want it considered. Whether non-Windows defaults matter is the maintainers' call.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 06:50 UTC · [original](https://github.com/Marvisak/VIctory/issues/899#issuecomment-7155219868) <!-- victory-issue-triage v1 verdict=confirmed seen=2026-11-24T16:17:10Z at=2026-11-25T06:50:49Z --> Automated triage for the maintainers. Confirmed on current `main`: `default_dir` in `crates/victory-core/src/config.rs` uses the same `LOCALAPPDATA` → `XDG_CACHE_HOME` → `$HOME/.cache` chain for both `cache` and `data`, so off Windows the persistent data directory defaults to a cache location, against the `data_dir` doc comment. On Windows (the supported host) it is `%LOCALAPPDATA%\victory\data` and unaffected. PR #1151 was closed without merging and I found no other open PR; please open one again against current `main` if you want it considered. Whether non-Windows defaults matter is the maintainers' call. --- _Generated by [Claude Code](https://claude.ai/code)_
This discussion has been locked. Commenting is limited to contributors.
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#899
No description provided.