Skip to content

Commit

Permalink
Merge pull request #4710 from jlebon/pr/srpm-name
Browse files Browse the repository at this point in the history
  • Loading branch information
jlebon authored Nov 29, 2023
2 parents ae2002c + 2544067 commit 7e17beb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
5 changes: 5 additions & 0 deletions rust/libdnf-sys/cxx/libdnf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ class DnfPackage final
{
return rust::String (::dnf_package_get_arch (pkg));
};
rust::String
get_sourcerpm ()
{
return rust::String (::dnf_package_get_sourcerpm (pkg));
};
};

std::unique_ptr<DnfPackage> dnf_package_from_ptr (FFIDnfPackage *pkg) noexcept;
Expand Down
1 change: 1 addition & 0 deletions rust/libdnf-sys/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub mod ffi {
fn get_name(self: Pin<&mut DnfPackage>) -> String;
fn get_evr(self: Pin<&mut DnfPackage>) -> String;
fn get_arch(self: Pin<&mut DnfPackage>) -> String;
fn get_sourcerpm(self: Pin<&mut DnfPackage>) -> String;
/// SAFETY: This can only be called on a valid pointer
unsafe fn dnf_package_from_ptr(pkg: *mut FFIDnfPackage) -> UniquePtr<DnfPackage>;

Expand Down
20 changes: 17 additions & 3 deletions rust/src/lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ enum LockedPackage {
Evr {
evr: String,
digest: Option<String>,
#[serde(skip_serializing)]
#[serde(skip_serializing_if = "Option::is_none")]
metadata: Option<BTreeMap<String, serde_json::Value>>,
},
Evra {
evra: String,
digest: Option<String>,
#[serde(skip_serializing)]
#[serde(skip_serializing_if = "Option::is_none")]
metadata: Option<BTreeMap<String, serde_json::Value>>,
},
}
Expand Down Expand Up @@ -333,13 +333,27 @@ pub(crate) fn lockfile_write(
let evr = pkg.pin_mut().get_evr();
let arch = pkg.pin_mut().get_arch();

// we just want the name; the EVR is redundant with `evra` and A is just 'src'
let srpm_metadata = {
let srpm_nvra = pkg.pin_mut().get_sourcerpm();
let split: Vec<&str> = srpm_nvra.rsplitn(3, '-').collect();
if split.len() != 3 {
// I don't think that can ever happen in the scenarios we care
// about, but seems excessive to fail the build for it
eprintln!("warning: RPM {name}-{evr}.{arch} has invalid SRPM field {srpm_nvra}");
None
} else {
Some(BTreeMap::from([("sourcerpm".into(), split[2].into())]))
}
};

let chksum = crate::ffi::get_repodata_chksum_repr(&mut pkg.pin_mut().get_ref())?;
output_pkgs.insert(
name.as_str().to_string(),
LockedPackage::Evra {
evra: format!("{evr}.{arch}"),
digest: Some(chksum),
metadata: None,
metadata: srpm_metadata,
},
);
}
Expand Down

0 comments on commit 7e17beb

Please sign in to comment.