fn extract_zbi_from_update_package(
        reader: &mut Box<dyn ArtifactReader>,
        package: &PackageDefinition,
    ) -> Result<Zbi> {
        info!("Extracting the ZBI from {}", package.url);
        for (path, merkle) in package.contents.iter() {
            if path == "zbi" || path == "zbi.signed" {
                let zbi_data = reader.read_raw(&format!("blobs/{}", merkle))?;
                let mut reader = ZbiReader::new(zbi_data);
                let sections = reader.parse()?;
                let mut bootfs = HashMap::new();
                let mut cmdline = String::new();
                info!("Extracted {} sections from the ZBI", sections.len());
                for section in sections.iter() {
                    info!("Extracted sections {:?}", section.section_type);
                    if section.section_type == ZbiType::StorageBootfs {
                        let mut bootfs_reader = BootfsReader::new(section.buffer.clone());
                        let bootfs_result = bootfs_reader.parse();
                        if let Err(err) = bootfs_result {
                            warn!("Bootfs parse failed {}", err);
                        } else {
                            bootfs = bootfs_result.unwrap();
                            info!("Bootfs found {} files", bootfs.len());
                        }
                    } else if section.section_type == ZbiType::Cmdline {
                        let mut cmd_str = std::str::from_utf8(&section.buffer)?;
                        if let Some(stripped) = cmd_str.strip_suffix("\u{0000}") {
                            cmd_str = stripped;
                        }
                        cmdline.push_str(&cmd_str);
                    }
                }
                return Ok(Zbi { sections, bootfs, cmdline });
            }
        }
        return Err(anyhow!("Unable to find a zbi file in the package."));
    }
/// Extracts the ZBI from the update package and parses it into the ZBI
/// model.
Extracts the ZBI from the update package and parses it into the ZBI
model.
Extracts the ZBI from the update package and parses it into the ZBI model .
fn extract_zbi_from_update_package(
        reader: &mut Box<dyn ArtifactReader>,
        package: &PackageDefinition,
    ) -> Result<Zbi> {
        info!("Extracting the ZBI from {}", package.url);
        for (path, merkle) in package.contents.iter() {
            if path == "zbi" || path == "zbi.signed" {
                let zbi_data = reader.read_raw(&format!("blobs/{}", merkle))?;
                let mut reader = ZbiReader::new(zbi_data);
                let sections = reader.parse()?;
                let mut bootfs = HashMap::new();
                let mut cmdline = String::new();
                info!("Extracted {} sections from the ZBI", sections.len());
                for section in sections.iter() {
                    info!("Extracted sections {:?}", section.section_type);
                    if section.section_type == ZbiType::StorageBootfs {
                        let mut bootfs_reader = BootfsReader::new(section.buffer.clone());
                        let bootfs_result = bootfs_reader.parse();
                        if let Err(err) = bootfs_result {
                            warn!("Bootfs parse failed {}", err);
                        } else {
                            bootfs = bootfs_result.unwrap();
                            info!("Bootfs found {} files", bootfs.len());
                        }
                    } else if section.section_type == ZbiType::Cmdline {
                        let mut cmd_str = std::str::from_utf8(&section.buffer)?;
                        if let Some(stripped) = cmd_str.strip_suffix("\u{0000}") {
                            cmd_str = stripped;
                        }
                        cmdline.push_str(&cmd_str);
                    }
                }
                return Ok(Zbi { sections, bootfs, cmdline });
            }
        }
        return Err(anyhow!("Unable to find a zbi file in the package."));
    }
fn extract_zbi_from_update_package ( reader : & mut Box < dyn ArtifactReader > , package : & PackageDefinition , ) -> Result < Zbi > { info ! ( " " package url ) ; for ( path , merkle ) in package . contents . iter ( ) { if path == " " || path == " " { let zbi_data = reader . read_raw ( & format ! ( " " merkle ) ) ? ; let mut reader = ZbiReader :: new ( zbi_data ) ; let sections = reader . parse ( ) ? ; let mut bootfs = HashMap :: new ( ) ; let mut cmdline = String :: new ( ) ; info ! ( " " sections len ( ) ) ; for section in sections . iter ( ) { info ! ( " " section section_type ) ; if section . section_type == ZbiType :: StorageBootfs { let mut bootfs_reader = BootfsReader :: new ( section . buffer . clone ( ) ) ; let bootfs_result = bootfs_reader . parse ( ) ; if let Err ( err ) = bootfs_result { warn ! ( " " err ) ; } else { bootfs = bootfs_result . unwrap ( ) ; info ! ( " " bootfs len ( ) ) ; } } else if section . section_type == ZbiType :: Cmdline { let mut cmd_str = std :: str :: from_utf8 ( & section . buffer ) ? ; if let Some ( stripped ) = cmd_str . strip_suffix ( " \u{0000} " ) { cmd_str = stripped ; } cmdline . push_str ( & cmd_str ) ; } } return Ok ( Zbi { sections , bootfs , cmdline } ) ; } } return Err ( anyhow ! ( " " ) ) ; }
Extracts the ZBI from the update package and parses it into the ZBI
model.
Extracts the ZBI from the update package and parses it into the ZBI model .
reader
&mut Box<dyn ArtifactReader>
package
&PackageDefinition
reader
&mut Box<dyn ArtifactReader>
package
&PackageDefinition