mirror of
https://github.com/edera-dev/krata.git
synced 2025-08-04 13:41:31 +00:00
feat: oci compliance work (#85)
* chore: rework oci crate to be more composable * feat: image pull is now internally explicit * feat: utilize vfs for assembling oci images * feat: rework oci to preserve permissions via a vfs
This commit is contained in:
@ -1,24 +1,40 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use indexmap::IndexMap;
|
||||
use tokio::sync::broadcast::Sender;
|
||||
use tokio::sync::{mpsc::Sender, Mutex};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct OciProgress {
|
||||
pub id: String,
|
||||
pub phase: OciProgressPhase,
|
||||
pub layers: IndexMap<String, OciProgressLayer>,
|
||||
pub value: u64,
|
||||
pub total: u64,
|
||||
}
|
||||
|
||||
impl Default for OciProgress {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl OciProgress {
|
||||
pub fn add_layer(&mut self, id: &str) {
|
||||
pub fn new() -> Self {
|
||||
OciProgress {
|
||||
phase: OciProgressPhase::Resolving,
|
||||
layers: IndexMap::new(),
|
||||
value: 0,
|
||||
total: 1,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_layer(&mut self, id: &str, size: usize) {
|
||||
self.layers.insert(
|
||||
id.to_string(),
|
||||
OciProgressLayer {
|
||||
id: id.to_string(),
|
||||
phase: OciProgressLayerPhase::Waiting,
|
||||
value: 0,
|
||||
total: 0,
|
||||
total: size as u64,
|
||||
},
|
||||
);
|
||||
}
|
||||
@ -92,6 +108,33 @@ impl OciProgressContext {
|
||||
}
|
||||
|
||||
pub fn update(&self, progress: &OciProgress) {
|
||||
let _ = self.sender.send(progress.clone());
|
||||
let _ = self.sender.try_send(progress.clone());
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct OciBoundProgress {
|
||||
context: OciProgressContext,
|
||||
instance: Arc<Mutex<OciProgress>>,
|
||||
}
|
||||
|
||||
impl OciBoundProgress {
|
||||
pub fn new(context: OciProgressContext, progress: OciProgress) -> OciBoundProgress {
|
||||
OciBoundProgress {
|
||||
context,
|
||||
instance: Arc::new(Mutex::new(progress)),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn update(&self, function: impl FnOnce(&mut OciProgress)) {
|
||||
let mut progress = self.instance.lock().await;
|
||||
function(&mut progress);
|
||||
self.context.update(&progress);
|
||||
}
|
||||
|
||||
pub fn update_blocking(&self, function: impl FnOnce(&mut OciProgress)) {
|
||||
let mut progress = self.instance.blocking_lock();
|
||||
function(&mut progress);
|
||||
self.context.update(&progress);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user