mirror of
https://github.com/edera-dev/krata.git
synced 2025-08-06 06:31:31 +00:00
feat: oci tar format support
This commit is contained in:
@ -7,12 +7,13 @@ use crate::{
|
||||
};
|
||||
use anyhow::{anyhow, Result};
|
||||
use log::warn;
|
||||
use tokio::{pin, process::Command, select};
|
||||
use tokio::{fs::File, pin, process::Command, select};
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum OciPackerBackendType {
|
||||
MkSquashfs,
|
||||
MkfsErofs,
|
||||
Tar,
|
||||
}
|
||||
|
||||
impl OciPackerBackendType {
|
||||
@ -20,6 +21,7 @@ impl OciPackerBackendType {
|
||||
match self {
|
||||
OciPackerBackendType::MkSquashfs => OciPackedFormat::Squashfs,
|
||||
OciPackerBackendType::MkfsErofs => OciPackedFormat::Erofs,
|
||||
OciPackerBackendType::Tar => OciPackedFormat::Tar,
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,6 +33,7 @@ impl OciPackerBackendType {
|
||||
OciPackerBackendType::MkfsErofs => {
|
||||
Box::new(OciPackerMkfsErofs {}) as Box<dyn OciPackerBackend>
|
||||
}
|
||||
OciPackerBackendType::Tar => Box::new(OciPackerTar {}) as Box<dyn OciPackerBackend>,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -199,3 +202,30 @@ impl OciPackerBackend for OciPackerMkfsErofs {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct OciPackerTar {}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl OciPackerBackend for OciPackerTar {
|
||||
async fn pack(&self, progress: OciBoundProgress, vfs: Arc<VfsTree>, file: &Path) -> Result<()> {
|
||||
progress
|
||||
.update(|progress| {
|
||||
progress.phase = OciProgressPhase::Packing;
|
||||
progress.total = 1;
|
||||
progress.value = 0;
|
||||
})
|
||||
.await;
|
||||
|
||||
let file = File::create(file).await?;
|
||||
vfs.write_to_tar(file).await?;
|
||||
|
||||
progress
|
||||
.update(|progress| {
|
||||
progress.phase = OciProgressPhase::Packing;
|
||||
progress.total = 1;
|
||||
progress.value = 1;
|
||||
})
|
||||
.await;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ pub enum OciPackedFormat {
|
||||
#[default]
|
||||
Squashfs,
|
||||
Erofs,
|
||||
Tar,
|
||||
}
|
||||
|
||||
impl OciPackedFormat {
|
||||
@ -21,6 +22,7 @@ impl OciPackedFormat {
|
||||
match self {
|
||||
OciPackedFormat::Squashfs => "squashfs",
|
||||
OciPackedFormat::Erofs => "erofs",
|
||||
OciPackedFormat::Tar => "tar",
|
||||
}
|
||||
}
|
||||
|
||||
@ -28,6 +30,7 @@ impl OciPackedFormat {
|
||||
match self {
|
||||
OciPackedFormat::Squashfs => OciPackerBackendType::MkSquashfs,
|
||||
OciPackedFormat::Erofs => OciPackerBackendType::MkfsErofs,
|
||||
OciPackedFormat::Tar => OciPackerBackendType::Tar,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user