core: resolve default data_dir via XDG_DATA_HOME on non-Windows hosts #1151

Closed
DaniiL35 wants to merge 1 commit from upstream-pr/1151 into main
DaniiL35 commented 2026-11-24 16:16:09 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DaniiL35 on 2026-11-24T16:16:09Z.


Resolves #899

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 resolved both "cache" and "data" using the exact same fallback chain (LOCALAPPDATA -> XDG_CACHE_HOME -> ~/.cache).
On Linux and macOS hosts where VICTORY_DATA_DIR is not set, persistent saves, local storage, and crash logs were placed in volatile cache paths, risking deletion during standard cache cleanup.

Fix

  1. Query XDG_DATA_HOME (and fallback ~/.local/share) for "data" on non-Windows hosts before falling back to cache paths.
  2. Parameterize default directory resolution with the env lookup closure (default_dir_with), allowing pure unit testing of directory resolution.
  3. Added 3 synthetic unit tests covering Unix XDG_DATA_HOME, HOME/.local/share fallback, and Windows LOCALAPPDATA precedence.

All test inputs are synthetic; zero game data or binary blobs (Rule #1 compliant). Formatted with Rust 2024 edition.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6586276588 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1151). Originally posted by [DaniiL35](https://github.com/DaniiL35) on 2026-11-24T16:16:09Z. --- Resolves #899 ### 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` resolved both `"cache"` and `"data"` using the exact same fallback chain (`LOCALAPPDATA` -> `XDG_CACHE_HOME` -> `~/.cache`). On Linux and macOS hosts where `VICTORY_DATA_DIR` is not set, persistent saves, local storage, and crash logs were placed in volatile cache paths, risking deletion during standard cache cleanup. ### Fix 1. Query `XDG_DATA_HOME` (and fallback `~/.local/share`) for `"data"` on non-Windows hosts before falling back to cache paths. 2. Parameterize default directory resolution with the `env` lookup closure (`default_dir_with`), allowing pure unit testing of directory resolution. 3. Added 3 synthetic unit tests covering Unix `XDG_DATA_HOME`, `HOME/.local/share` fallback, and Windows `LOCALAPPDATA` precedence. All test inputs are synthetic; zero game data or binary blobs (Rule #1 compliant). Formatted with Rust 2024 edition.
upstream-sync closed this pull request 2026-11-24 17:03:31 +00:00
catminou4 commented 2026-11-24 17:03:31 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T16:29:03Z.

Review: CHANGES_REQUESTED


Two verified problems on macOS arm64 (rustc 1.98.1, merged into main ffe310e, cargo test -p victory-core --locked: 9 passed, 5 failed):

  1. Empty env vars regress: empty_env_values_are_ignored, empty_test_titles_env_is_ignored, environment_overrides_file, test_titles_env_splits_paths now return Err("cannot determine a user directory"). The .or_else chain short-circuits on Some("") (e.g. LOCALAPPDATA=""), and the .filter() is applied only after the whole chain, so an empty early var prevents fallback to HOME/XDG instead of being ignored. Filter each candidate before the chain (or map empty -> None per var).

  2. Your own new test localappdata_takes_precedence_for_both fails on Unix: PathBuf::from(r"C:\Users\User\AppData\Local").join("victory") yields mixed separators (...Local/victory/data) off Windows. Gate that test #[cfg(windows)] or build the expected path with PathBuf joins.

Also note #708 (still open) overlaps this config.rs area; worth coordinating so the data-dir fixes land consistently.

<!-- greyfinch-sync:Marvisak/VIctory:review:6043264032 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1151#pullrequestreview-6043264032). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T16:29:03Z. **Review:** CHANGES_REQUESTED --- Two verified problems on macOS arm64 (rustc 1.98.1, merged into main ffe310e, `cargo test -p victory-core --locked`: 9 passed, 5 failed): 1. Empty env vars regress: `empty_env_values_are_ignored`, `empty_test_titles_env_is_ignored`, `environment_overrides_file`, `test_titles_env_splits_paths` now return Err("cannot determine a user directory"). The `.or_else` chain short-circuits on `Some("")` (e.g. LOCALAPPDATA=""), and the `.filter()` is applied only after the whole chain, so an empty early var prevents fallback to HOME/XDG instead of being ignored. Filter each candidate before the chain (or map empty -> None per var). 2. Your own new test `localappdata_takes_precedence_for_both` fails on Unix: `PathBuf::from(r"C:\Users\User\AppData\Local").join("victory")` yields mixed separators (`...Local/victory/data`) off Windows. Gate that test `#[cfg(windows)]` or build the expected path with PathBuf joins. Also note #708 (still open) overlaps this config.rs area; worth coordinating so the data-dir fixes land consistently.

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!1151
No description provided.