Config: skip an empty or relative cache base for the default directories #243

Closed
SkippySteve wants to merge 1 commit from upstream-pr/243 into main
SkippySteve commented 2026-11-24 01:45:39 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by SkippySteve on 2026-11-24T01:45:39Z.


When neither VICTORY_CACHE_DIR/VICTORY_DATA_DIR nor the config file sets a path, Config falls back to LOCALAPPDATA, then XDG_CACHE_HOME, then HOME/.cache. Today a variable that is set but empty (XDG_CACHE_HOME=, common in Linux shells and wrapper scripts) or relative wins anyway. The base then becomes victory/cache relative to the working directory, which is usually the repository checkout, and cache_subdir fails with the asset-policy error rather than using ~/.cache.

Change (crates/victory-core/src/config.rs)

  • default_dir skips empty and relative values, as the XDG base directory spec asks, and falls through to the next candidate. If none is usable you get the existing "set VICTORY_CACHE_DIR and VICTORY_DATA_DIR" error.
  • default_dir now reads through the same env closure that Config::resolve already takes. Production still passes std::env::var_os, so behaviour with sane values is unchanged.

Tests

  • New: precedence (LOCALAPPDATA → XDG_CACHE_HOME → HOME/.cache), skipping empty and relative values, the error when nothing is usable, and resolve taking its defaults from the given environment.
  • The two existing resolve tests used to depend on the host's real LOCALAPPDATA/XDG_CACHE_HOME/HOME (they failed with env -u HOME). They now supply HOME through the closure, so they are hermetic.

Validated on Linux: cargo test -p victory-core (11 passed, also with HOME and XDG_CACHE_HOME unset), cargo clippy -p victory-core --all-targets -D warnings for both the host and x86_64-pc-windows-msvc, cargo fmt --check, cargo xtask policy. I haven't run the tests on Windows. The test helper uses C:\… paths there so they are absolute.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6572714962 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/243). Originally posted by [SkippySteve](https://github.com/SkippySteve) on 2026-11-24T01:45:39Z. --- When neither `VICTORY_CACHE_DIR`/`VICTORY_DATA_DIR` nor the config file sets a path, `Config` falls back to `LOCALAPPDATA`, then `XDG_CACHE_HOME`, then `HOME/.cache`. Today a variable that is **set but empty** (`XDG_CACHE_HOME=`, common in Linux shells and wrapper scripts) or **relative** wins anyway. The base then becomes `victory/cache` relative to the working directory, which is usually the repository checkout, and `cache_subdir` fails with the asset-policy error rather than using `~/.cache`. **Change** (`crates/victory-core/src/config.rs`) - `default_dir` skips empty and relative values, as the XDG base directory spec asks, and falls through to the next candidate. If none is usable you get the existing "set VICTORY_CACHE_DIR and VICTORY_DATA_DIR" error. - `default_dir` now reads through the same `env` closure that `Config::resolve` already takes. Production still passes `std::env::var_os`, so behaviour with sane values is unchanged. **Tests** - New: precedence (LOCALAPPDATA → XDG_CACHE_HOME → HOME/.cache), skipping empty and relative values, the error when nothing is usable, and `resolve` taking its defaults from the given environment. - The two existing `resolve` tests used to depend on the host's real `LOCALAPPDATA`/`XDG_CACHE_HOME`/`HOME` (they failed with `env -u HOME`). They now supply `HOME` through the closure, so they are hermetic. **Validated** on Linux: `cargo test -p victory-core` (11 passed, also with `HOME` and `XDG_CACHE_HOME` unset), `cargo clippy -p victory-core --all-targets -D warnings` for both the host and `x86_64-pc-windows-msvc`, `cargo fmt --check`, `cargo xtask policy`. I haven't run the tests on Windows. The test helper uses `C:\…` paths there so they are absolute.
upstream-sync closed this pull request 2026-11-24 06:52:00 +00:00
SkippySteve commented 2026-11-24 06:55:04 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by SkippySteve on 2026-11-24T01:48:22Z.


Superseded by #241 (combined). Both PRs changed default_dir in config.rs and conflicted, so this change and its tests are now merged into #241.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7119463420 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/243#issuecomment-7119463420). Originally posted by [SkippySteve](https://github.com/SkippySteve) on 2026-11-24T01:48:22Z. --- Superseded by #241 (combined). Both PRs changed `default_dir` in `config.rs` and conflicted, so this change and its tests are now merged into #241.

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