use crate::error::Error;
use crate::model;
use crate::store::{KERNEL_IN_ARCHIVE, KERNEL_URL, Store};
use crate::{checked, ffi};
pub struct Builder {
store: Store,
}
impl Builder {
pub fn new(store: Store) -> Self {
Self { store }
}
pub fn store(&self) -> &Store {
&self.store
}
pub fn build(&self, plan: &model::BuildPlan) -> Result<(), Error> {
let code = ffi::czbridge_build(
plan.clone(),
&self.store.root().display().to_string(),
&self.store.kernel().display().to_string(),
self.store.initfs_reference(),
&self.store.initfs().display().to_string(),
);
checked(code)
.map(|_| ())
.map_err(|error| Error::failed(format!("build {}", plan.tag), error))
}
pub fn provision(&self) -> Result<(), Error> {
let code = ffi::czbridge_provision(
&self.store.root().display().to_string(),
&self.store.kernel().display().to_string(),
KERNEL_URL,
KERNEL_IN_ARCHIVE,
self.store.initfs_reference(),
&self.store.initfs().display().to_string(),
);
checked(code)
.map(|_| ())
.map_err(|error| Error::failed("provision the image store", error))
}
}