Your browser sucks, JavaScript disabled! Gunnar's console needs JavaScript and WebAssembly. Git over SSH on port 2222 does not.

nordisk/holger

server/repository/znippy-rpm/src/header.rs

//! The native rpm header read now lives in `holger-index-rows` (lane HOL-PERF-2): the scan
//! worker runs it at intake and answers the fields as an index row; this crate keeps
//! calling the same function for an archive that carries neither rows nor a typed rpm view.

use holger_index_rows::rpm::RpmHeader;
use znippy_common::views::RpmMetaRow;

/// The in-memory `.rpm` builder, for this crate's tests and holger's fuzz seeds.
#[cfg(any(test, feature = "fixtures"))]
pub use holger_index_rows::rpm::tests_support;

/// The rpm-md row of a package: the NEVRA the caller derived from the file name and the
/// header's fields.
pub fn meta_row(name: &str, version: &str, release: &str, arch: &str, h: RpmHeader) -> RpmMetaRow {
    RpmMetaRow {
        name: name.to_string(),
        version: version.to_string(),
        release: release.to_string(),
        arch: arch.to_string(),
        epoch: h.epoch,
        summary: h.summary,
        license: h.license,
        url: h.url,
        vendor: h.vendor,
        sourcerpm: h.sourcerpm,
        provides: h.provides,
        requires: h.requires,
    }
}

/// Parse the header fields of a `.rpm` into an [`RpmMetaRow`], keyed by the coords
/// the caller already derived from the filename. Returns `None` when the bytes
/// aren't a decodable RPM (bad lead, truncated headers, …).
pub fn parse_rpm_header(
    rpm: &[u8],
    name: &str,
    version: &str,
    release: &str,
    arch: &str,
) -> Option<RpmMetaRow> {
    holger_index_rows::rpm::header(rpm).map(|h| meta_row(name, version, release, arch, h))
}