Skip to content

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

Closed
SkippySteve wants to merge 1 commit into
Marvisak:mainfrom
SkippySteve:SkippySteve/core-default-dir-env
Closed

SkippySteve wants to merge 1 commit into
Marvisak:mainfrom
SkippySteve:SkippySteve/core-default-dir-env

Conversation

@SkippySteve

Copy link
Copy Markdown

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.
@SkippySteve

Copy link
Copy Markdown
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant