diff --git a/src/bin/cfsctl.rs b/src/bin/cfsctl.rs index a4a2456..601c92f 100644 --- a/src/bin/cfsctl.rs +++ b/src/bin/cfsctl.rs @@ -90,24 +90,27 @@ fn main() -> Result<()> { } }, Command::Cat { name } => { - repo.merge_splitstream(&name, &mut std::io::stdout()) + repo.merge_splitstream(&name, &mut std::io::stdout())?; }, Command::ImportImage { reference, } => { - repo.import_image(&reference, &mut std::io::stdin()) + let image_id = repo.import_image(&reference, &mut std::io::stdin())?; + println!("{}", hex::encode(image_id)); }, Command::Oci{ cmd: oci_cmd } => match oci_cmd { OciCommand::ImportLayer { name } => { - oci::import_layer(&repo, &name, &mut std::io::stdin()) + let stream_id = oci::import_layer(&repo, &name, &mut std::io::stdin())?; + println!("{}", hex::encode(stream_id)); }, OciCommand::LsLayer { name } => { - oci::ls_layer(&repo, &name) + oci::ls_layer(&repo, &name)?; }, } Command::Mount { name, mountpoint } => { - repo.mount(&name, &mountpoint) + repo.mount(&name, &mountpoint)?; }, Command::GC => { - repo.gc() + repo.gc()?; } } + Ok(()) } diff --git a/src/oci/mod.rs b/src/oci/mod.rs index 04f51da..cba1e36 100644 --- a/src/oci/mod.rs +++ b/src/oci/mod.rs @@ -9,7 +9,7 @@ use crate::{ repository::Repository }; -pub fn import_layer(repo: &Repository, name: &str, tar_stream: &mut R) -> Result<()> { +pub fn import_layer(repo: &Repository, name: &str, tar_stream: &mut R) -> Result { let mut split_stream = zstd::stream::write::Encoder::new(vec![], 0)?; tar::split( diff --git a/src/repository.rs b/src/repository.rs index b962930..489427a 100644 --- a/src/repository.rs +++ b/src/repository.rs @@ -197,7 +197,7 @@ impl Repository { } /// this function is not safe for untrusted users - pub fn import_image(&self, name: &str, image: &mut R) -> Result<()> { + pub fn import_image(&self, name: &str, image: &mut R) -> Result { let mut data = vec![]; image.read_to_end(&mut data)?; let object_id = self.ensure_object(&data)?; @@ -212,14 +212,14 @@ impl Repository { pub fn link_ref( &self, name: &str, category: &str, object_id: Sha256HashValue - ) -> Result<()> { + ) -> Result { let object_path = format!("objects/{:02x}/{}", object_id[0], hex::encode(&object_id[1..])); let category_path = format!("{}/{}", category, hex::encode(object_id)); let ref_path = format!("{}/refs/{}", category, name); self.symlink(&ref_path, &category_path)?; self.symlink(&category_path, &object_path)?; - Ok(()) + Ok(object_id) } fn symlink>(&self, name: P, target: &str) -> Result<()> {