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

Closed
github-bot wants to merge 1 commit from gh-pr/243/head into gh-pr/243/base
Owner

@⁠SkippySteve on GitHub · 2026-11-24 01:45 UTC · original
SkippySteve/core-default-dir-env → main · +86 −9 · 1 files · 1 commits · closed without merging

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.

**@⁠SkippySteve** on GitHub · 2026-11-24 01:45 UTC · [original](https://github.com/Marvisak/VIctory/pull/243) `SkippySteve/core-default-dir-env` → `main` · +86 −9 · 1 files · 1 commits · closed without merging 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.
XDG_CACHE_HOME= (set but empty), or a relative LOCALAPPDATA, XDG_CACHE_HOME
or HOME, made the default cache and data directories relative to the working
directory, usually the repository, where the asset policy then refuses them.
Such values are now skipped, as the XDG base directory spec asks.

The default directories are now read through the same environment closure as
the rest of Config::resolve, so its tests no longer depend on the host's
LOCALAPPDATA/XDG_CACHE_HOME/HOME.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:56:13 +00:00
github-bot closed this pull request 2026-11-26 03:56:13 +00:00
Author
Owner

@⁠SkippySteve on GitHub · 2026-11-24 01:48 UTC · original

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.

**@⁠SkippySteve** on GitHub · 2026-11-24 01:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/243#issuecomment-7119463420) 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

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