Skip to content

Commit

Permalink
diag: Better errors when package archive reading fails
Browse files Browse the repository at this point in the history
  • Loading branch information
VorpalBlade committed Oct 6, 2024
1 parent 01e3aa8 commit ca0ab79
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
16 changes: 14 additions & 2 deletions crates/paketkoll_core/src/backend/arch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,9 @@ impl Files for ArchLinux {
let results: Vec<_> = archives
.par_bridge()
.map(|value| {
value.and_then(|(pkg_ref, path)| Ok((pkg_ref, archive_to_entries(pkg_ref, &path)?)))
value.and_then(|(pkg_ref, path)| {
Ok((pkg_ref, archive_to_entries(pkg_ref, &path, interner)?))
})
})
.collect();
Ok(results)
Expand Down Expand Up @@ -283,7 +285,11 @@ impl ArchLinux {
}

/// Convert deb archives to file entries
fn archive_to_entries(pkg_ref: PackageRef, pkg_file: &Path) -> eyre::Result<Vec<FileEntry>> {
fn archive_to_entries(
pkg_ref: PackageRef,
pkg_file: &Path,
interner: &Interner,
) -> eyre::Result<Vec<FileEntry>> {
// The package is a .tar.zst
let package_file = std::fs::File::open(pkg_file)?;
let decompressed = zstd::Decoder::new(package_file)?;
Expand All @@ -300,6 +306,12 @@ fn archive_to_entries(pkg_ref: PackageRef, pkg_file: &Path) -> eyre::Result<Vec<
Some(Cow::Owned(path.into_path_buf().expect("Invalid path")))
}
})
.wrap_err_with(|| {
format!(
"Failed extracting file entries from package file for {}",
pkg_ref.as_str(interner)
)
})
}

/// Files to ignore when reading archives
Expand Down
8 changes: 7 additions & 1 deletion crates/paketkoll_core/src/backend/deb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,13 @@ fn archive_to_entries(
let archive = tar::Archive::new(&mut decompressed);
// Now, lets extract the requested files from the package
let mut entries =
convert_archive_entries(archive, pkg_ref, NAME, convert_deb_archive_path)?;
convert_archive_entries(archive, pkg_ref, NAME, convert_deb_archive_path)
.wrap_err_with(|| {
format!(
"Failed extracting file entries from data archive in deb file for package {}",
pkg_ref.as_str(interner)
)
})?;

let self_pkg = packages
.get(&pkg_ref)
Expand Down

0 comments on commit ca0ab79

Please sign in to comment.