buildkit_llb/ops/exec/
mount.rs1use std::path::{Path, PathBuf};
2
3use crate::utils::{OperationOutput, OutputIdx};
4
5#[derive(Debug, Clone)]
7pub enum Mount<'a, P: AsRef<Path>> {
8 ReadOnlyLayer(OperationOutput<'a>, P),
10
11 ReadOnlySelector(OperationOutput<'a>, P, P),
13
14 Scratch(OutputIdx, P),
16
17 Layer(OutputIdx, OperationOutput<'a>, P),
19
20 SharedCache(P),
22
23 OptionalSshAgent(P),
25}
26
27impl<'a, P: AsRef<Path>> Mount<'a, P> {
28 pub fn into_owned(self) -> Mount<'a, PathBuf> {
30 use Mount::*;
31
32 match self {
33 ReadOnlySelector(op, path, selector) => {
34 ReadOnlySelector(op, path.as_ref().into(), selector.as_ref().into())
35 }
36
37 ReadOnlyLayer(op, path) => ReadOnlyLayer(op, path.as_ref().into()),
38 Scratch(output, path) => Scratch(output, path.as_ref().into()),
39 Layer(output, input, path) => Layer(output, input, path.as_ref().into()),
40 SharedCache(path) => SharedCache(path.as_ref().into()),
41 OptionalSshAgent(path) => OptionalSshAgent(path.as_ref().into()),
42 }
43 }
44
45 pub fn is_root(&self) -> bool {
46 use Mount::*;
47
48 let path = match self {
49 ReadOnlySelector(_, path, ..) => path,
50 ReadOnlyLayer(_, path) => path,
51 Scratch(_, path) => path,
52 Layer(_, _, path) => path,
53 SharedCache(path) => path,
54 OptionalSshAgent(_) => return false,
55 };
56
57 path.as_ref() == Path::new("/")
58 }
59}