Skip to main content

resolve_policy_path

Function resolve_policy_path 

Source
fn resolve_policy_path(
    root: &Dir,
    env_override: Option<&Path>,
    xdg_config_home: Option<&Path>,
    home: Option<&Path>,
) -> Result<File>
Expand description

Resolve the containers policy path using the same load order as the upstream Go containers/image library, with all lookups relative to root:

  1. CONTAINERS_POLICY_JSON env var (trusted, no existence check)
  2. $XDG_CONFIG_HOME/containers/policy.json (or $HOME/.config/…)
  3. /etc/containers/policy.json
  4. /usr/share/containers/policy.json

For candidates 2–4 we only return a path when the file exists on disk.

Absolute paths (from env vars) have their leading / stripped so they resolve under root. Passing root opened on / gives normal behaviour; tests can pass a cap-std Dir backed by a temporary directory.