fix: Try raw hash before formatted digest in payload fetch fallback

The previous digest fallback used Display format (source:algorithm:hash)
which caused REST servers to look up files by SHA256 compressed hash
instead of the expected SHA1 primary hash. Now tries raw hash first
(compatible with pkg5 REST servers), then formatted variants with
algorithm info (compatible with local FileBackend storage).
This commit is contained in:
Till Wegmueller 2026-03-15 20:39:50 +01:00
parent d5ed328ab2
commit 0a28909e9e

View file

@ -228,12 +228,22 @@ impl<'a, S: ReadableRepository + Sync> PackageReceiver<'a, S> {
.map(|file| {
let payload = file.payload.as_ref().unwrap();
// Collect all candidate digests: primary first, then additional (compressed hash)
// Use Display format (source:algorithm:hash) so fetch_payload parses correctly
let mut digests = vec![payload.primary_identifier.to_string()];
// Collect candidate digests to try: raw primary hash first (works with
// REST servers that use SHA1), then formatted digests with algorithm info
// (works with FileBackend that may store under compressed hash)
let mut digests = vec![payload.primary_identifier.hash.clone()];
// Add formatted primary with algorithm info as second attempt
let formatted_primary = payload.primary_identifier.to_string();
if formatted_primary != payload.primary_identifier.hash {
digests.push(formatted_primary);
}
for additional in &payload.additional_identifiers {
if !additional.hash.is_empty() {
digests.push(additional.to_string());
digests.push(additional.hash.clone());
let formatted = additional.to_string();
if formatted != additional.hash {
digests.push(formatted);
}
}
}