Skip to content

Commit

Permalink
add --original-blob-digest args for merge
Browse files Browse the repository at this point in the history
the default merge command is to get the name of the original
blob from the bootstrap name, and add a cli args for it

Signed-off-by: zyfjeff <[email protected]>
  • Loading branch information
zyfjeff committed Aug 28, 2023
1 parent 1abf0ae commit efa9814
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
32 changes: 31 additions & 1 deletion builder/src/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ use super::{
pub struct Merger {}

impl Merger {
fn get_string_from_list(
original_digests: &Option<Vec<String>>,
idx: usize,
) -> Result<Option<String>> {
Ok(if let Some(digests) = &original_digests {
let digest = digests
.get(idx)
.ok_or_else(|| anyhow!("unmatched digest index {}", idx))?;
Some(digest.clone())
} else {
None
})
}

fn get_digest_from_list(digests: &Option<Vec<String>>, idx: usize) -> Result<Option<[u8; 32]>> {
Ok(if let Some(digests) = &digests {
let digest = digests
Expand Down Expand Up @@ -62,6 +76,7 @@ impl Merger {
parent_bootstrap_path: Option<String>,
sources: Vec<PathBuf>,
blob_digests: Option<Vec<String>>,
original_blob_digests: Option<Vec<String>>,
blob_sizes: Option<Vec<u64>>,
blob_toc_digests: Option<Vec<String>>,
blob_toc_sizes: Option<Vec<u64>>,
Expand All @@ -80,6 +95,14 @@ impl Merger {
sources.len(),
);
}
if let Some(original_digests) = original_blob_digests.as_ref() {
ensure!(
original_digests.len() == sources.len(),
"number of original blob digest entries {} doesn't match number of sources {}",
original_digests.len(),
sources.len(),
);
}
if let Some(sizes) = blob_sizes.as_ref() {
ensure!(
sizes.len() == sources.len(),
Expand Down Expand Up @@ -194,7 +217,14 @@ impl Merger {
} else {
// The blob id (blob sha256 hash) in parent bootstrap is invalid for nydusd
// runtime, should change it to the hash of whole tar blob.
blob_ctx.blob_id = BlobInfo::get_blob_id_from_meta_path(bootstrap_path)?;
if let Some(original_id) =
Self::get_string_from_list(&original_blob_digests, layer_idx)?
{
blob_ctx.blob_id = original_id;
} else {
blob_ctx.blob_id =
BlobInfo::get_blob_id_from_meta_path(bootstrap_path)?;
}
}
if let Some(digest) = Self::get_digest_from_list(&blob_digests, layer_idx)? {
if blob.has_feature(BlobFeatures::SEPARATE) {
Expand Down
14 changes: 14 additions & 0 deletions src/bin/nydus-image/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,12 @@ fn prepare_cmd_args(bti_string: &'static str) -> App {
.required(false)
.help("RAFS blob digest list separated by comma"),
)
.arg(
Arg::new("original-blob-digest")
.long("original-blob-digest")
.required(false)
.help("original blob digest list separated by comma"),
)
.arg(
Arg::new("blob-sizes")
.long("blob-sizes")
Expand Down Expand Up @@ -1194,6 +1200,13 @@ impl Command {
.map(|item| item.trim().to_string())
.collect()
});
let original_blob_digest: Option<Vec<String>> = matches
.get_one::<String>("original-blob-digest")
.map(|list| {
list.split(',')
.map(|item| item.trim().to_string())
.collect()
});
let blob_toc_sizes: Option<Vec<u64>> =
matches.get_one::<String>("blob-toc-sizes").map(|list| {
list.split(',')
Expand Down Expand Up @@ -1234,6 +1247,7 @@ impl Command {
parent_bootstrap_path,
source_bootstrap_paths,
blob_digests,
original_blob_digest,
blob_sizes,
blob_toc_digests,
blob_toc_sizes,
Expand Down

0 comments on commit efa9814

Please sign in to comment.