use std::path::PathBuf;
use crate::api::extension::{HostBindEntry, ProviderId};
use super::{SpecError, SpecErrorCategory, SpecResource};
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct FilesystemSpec {
pub root: Option<TreeSource>,
pub read_only: bool,
pub mounts: Vec<HostBindEntry>,
pub coherence: Option<CoherenceHandle>,
pub ownership: Vec<InitialOwnership>,
}
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct CoherenceHandle(PathBuf);
impl CoherenceHandle {
pub fn from_host_file(path: impl Into<PathBuf>) -> Result<Self, SpecError> {
let path = path.into();
if !path.is_absolute() || path.as_os_str().as_encoded_bytes().contains(&0) {
return Err(SpecError {
category: SpecErrorCategory::Invalid,
field: "filesystem.coherence".into(),
resource: Some(SpecResource::Path(path)),
context: "coherence host paths must be absolute".into(),
});
}
Ok(Self(path))
}
#[doc(hidden)]
#[must_use]
pub fn host_path(&self) -> &std::path::Path {
&self.0
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct InitialOwnership {
pub path: PathBuf,
pub uid: u32,
pub gid: u32,
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum TreeSource {
HostDirectory(PathBuf),
ImageLayer(ImageLayerHandle),
Overlay {
lower: Vec<TreeSource>,
upper: PathBuf,
work: PathBuf,
},
Provider(ProviderId),
}
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub struct ImageLayerHandle(pub u64);