Skip to content

Commit

Permalink
packagesystem: More API cleanup
Browse files Browse the repository at this point in the history
It doesn't make sense to hardcode the file list inside the query
function; just have the caller pass it the files it needs.

Now the packagesystem module is independent of the content.
  • Loading branch information
cgwalters committed Sep 30, 2023
1 parent 14cdf1b commit 5b5d0e6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/bios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl Component for Bios {
}

// Query the rpm database and list the package and build times for /usr/sbin/grub2-install
let meta = packagesystem::query(sysroot_path, &grub_install)?;
let meta = packagesystem::query_files(sysroot_path, [&grub_install])?;
write_update_metadata(sysroot_path, self, &meta)?;
Ok(meta)
}
Expand Down
8 changes: 7 additions & 1 deletion src/efi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,13 @@ impl Component for Efi {
Command::new("mv").args([&efisrc, &dest_efidir]).run()?;
}

let meta = packagesystem::query(sysroot_path, &dest_efidir)?;
let efidir = openat::Dir::open(&dest_efidir)?;
let files = crate::util::filenames(&efidir)?.into_iter().map(|mut f| {
f.insert_str(0, "/boot/efi/EFI/");
f
});

let meta = packagesystem::query_files(sysroot_path, files)?;
write_update_metadata(sysroot_path, self, &meta)?;
Ok(meta)
}
Expand Down
28 changes: 10 additions & 18 deletions src/packagesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,18 @@ fn rpm_parse_metadata(stdout: &[u8]) -> Result<ContentMetadata> {
})
}

/// Query the rpm database and list the package and build times, for all the
/// files in the EFI system partition, or for grub2-install file
pub(crate) fn query(sysroot_path: &str, path: &Path) -> Result<ContentMetadata> {
/// Query the rpm database and list the package and build times.
pub(crate) fn query_files<T>(
sysroot_path: &str,
paths: impl IntoIterator<Item = T>,
) -> Result<ContentMetadata>
where
T: AsRef<Path>,
{
let mut c = ostreeutil::rpm_cmd(sysroot_path);
c.args(["-q", "--queryformat", "%{nevra},%{buildtime} ", "-f"]);

match path.file_name().expect("filename").to_str() {
Some("EFI") => {
let efidir = openat::Dir::open(path)?;
c.args(crate::util::filenames(&efidir)?.drain().map(|mut f| {
f.insert_str(0, "/boot/efi/EFI/");
f
}));
}
Some("grub2-install") => {
c.arg(path);
}
_ => {
bail!("Unsupported file/directory {:?}", path)
}
for arg in paths {
c.arg(arg.as_ref());
}

let rpmout = c.output()?;
Expand Down

0 comments on commit 5b5d0e6

Please sign in to comment.