buildkit_llb/ops/fs/
path.rs

1use std::path::{Path, PathBuf};
2
3use crate::utils::{OperationOutput, OwnOutputIdx};
4
5/// Internal representation for not yet specified path.
6#[derive(Debug)]
7pub struct UnsetPath;
8
9/// Operand of *file system operations* that defines either source or destination layer and a path.
10#[derive(Debug)]
11pub enum LayerPath<'a, P: AsRef<Path>> {
12    /// References one of the *current operation outputs* and a path.
13    Own(OwnOutputIdx, P),
14
15    /// References an *output of another operation* and a path.
16    Other(OperationOutput<'a>, P),
17
18    /// A path in an *empty* layer (equivalent of Dockerfile's scratch source).
19    Scratch(P),
20}
21
22impl<'a, P: AsRef<Path>> LayerPath<'a, P> {
23    /// Transform the layer path into owned variant (basically, with `PathBuf` as the path).
24    pub fn into_owned(self) -> LayerPath<'a, PathBuf> {
25        use LayerPath::*;
26
27        match self {
28            Other(input, path) => Other(input, path.as_ref().into()),
29            Own(output, path) => Own(output, path.as_ref().into()),
30            Scratch(path) => Scratch(path.as_ref().into()),
31        }
32    }
33}