Skip to main content

find_context_zimagefile

Function find_context_zimagefile 

Source
pub fn find_context_zimagefile(context: &Path) -> Result<Option<PathBuf>>
Expand description

Discover a ZImagefile in the build context directory.

Resolution order matches user intuition:

  1. Literal ZImagefile in the context root — by far the most common layout (e.g. a one-image repo whose build file is just ZImagefile).
  2. Any ZImagefile.<suffix> glob — the convention this repo itself uses (ZImagefile.zlayer-node, ZImagefile.zlayer-manager, …). If exactly one match exists, use it.
  3. Zero matches → return Ok(None) so the caller falls through to the Dockerfile path.
  4. Multiple ZImagefile.<suffix> matches and no literal ZImagefile → ambiguous; return an error telling the user to pick one with -z <path>. We don’t silently pick “the first one” because that’s a correctness landmine — a repo with ZImagefile.prod and ZImagefile.dev would otherwise build whichever entry the filesystem listed first.

The lookup is sync (a single read_dir) and doesn’t follow symlinks beyond the standard DirEntry::file_type() semantics. Errors reading the directory propagate so the caller can attach a BuildError::ContextRead.

§Errors

Propagates the read_dir error when the context directory exists but cannot be read (a missing directory yields Ok(None), not an error).