Skip to content

Commit

Permalink
various: report fs-verity IDs as command results
Browse files Browse the repository at this point in the history
When creating stream or images, report the fs-verity of the resulting
object:

  - as a return value from the function on `Repository`
  - via stdout for commands run from `cfsctl`

Closes #4
  • Loading branch information
allisonkarlitskaya committed Oct 10, 2024
1 parent 85bf7a1 commit db83d53
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
15 changes: 9 additions & 6 deletions src/bin/cfsctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
2 changes: 1 addition & 1 deletion src/oci/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
repository::Repository
};

pub fn import_layer<R: Read>(repo: &Repository, name: &str, tar_stream: &mut R) -> Result<()> {
pub fn import_layer<R: Read>(repo: &Repository, name: &str, tar_stream: &mut R) -> Result<Sha256HashValue> {
let mut split_stream = zstd::stream::write::Encoder::new(vec![], 0)?;

tar::split(
Expand Down
6 changes: 3 additions & 3 deletions src/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ impl Repository {
}

/// this function is not safe for untrusted users
pub fn import_image<R: Read>(&self, name: &str, image: &mut R) -> Result<()> {
pub fn import_image<R: Read>(&self, name: &str, image: &mut R) -> Result<Sha256HashValue> {
let mut data = vec![];
image.read_to_end(&mut data)?;
let object_id = self.ensure_object(&data)?;
Expand All @@ -212,14 +212,14 @@ impl Repository {

pub fn link_ref(
&self, name: &str, category: &str, object_id: Sha256HashValue
) -> Result<()> {
) -> Result<Sha256HashValue> {
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<P: AsRef<Path>>(&self, name: P, target: &str) -> Result<()> {
Expand Down

0 comments on commit db83d53

Please sign in to comment.