package_info: refactor sources parsing even more
All checks were successful
CI / build (push) Successful in 7m46s

This commit is contained in:
2026-01-01 15:20:59 +01:00
parent a567506831
commit 5e1b0988fd

View File

@@ -234,7 +234,7 @@ impl DebianSources {
} }
} }
impl Iterator for DebianSources { impl Iterator for DebianSources {
type Item = HashMap<String, String>; type Item = PackageStanza;
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
let stanza = self.splitted_sources.next()?; let stanza = self.splitted_sources.next()?;
@@ -260,7 +260,39 @@ impl Iterator for DebianSources {
} }
} }
Some(fields) let pkg = fields.get("Package");
if pkg.is_none() {
// Skip empty stanza
return self.next();
}
// Parse package files
let mut files = Vec::new();
if let Some(checksums) = fields.get("Checksums-Sha256") {
for line in checksums.lines() {
let parts: Vec<&str> = line.split_whitespace().collect();
if parts.len() >= 3 {
files.push(FileEntry {
sha256: parts[0].to_string(),
size: parts[1].parse().unwrap_or(0),
name: parts[2].to_string(),
});
}
}
}
Some(PackageStanza {
package: fields.get("Package").unwrap().to_string(),
version: fields.get("Version").unwrap().to_string(),
directory: fields.get("Directory").cloned().unwrap_or_default(),
format: fields
.get("Format")
.cloned()
.unwrap_or_else(|| "1.0".to_string()),
vcs_git: fields.get("Vcs-Git").cloned(),
vcs_browser: fields.get("Vcs-Browser").cloned(),
files,
})
} }
} }
@@ -276,45 +308,9 @@ fn parse_sources(
let mut sources = DebianSources::new(data)?; let mut sources = DebianSources::new(data)?;
// Find the right package, with the right version if requested // Find the right package, with the right version if requested
let stanza = sources.find(|s| { Ok(sources.find(|s| {
let pkg = s.get("Package"); s.package == target_package
pkg.is_some() && (target_version.is_none() || s.version == target_version.unwrap())
&& pkg.unwrap() == target_package
&& (target_version.is_none() || s.get("Version").unwrap() == target_version.unwrap())
});
if stanza.is_none() {
return Ok(None);
}
let stanza = stanza.unwrap();
// Parse package files
let mut files = Vec::new();
if let Some(checksums) = stanza.get("Checksums-Sha256") {
for line in checksums.lines() {
let parts: Vec<&str> = line.split_whitespace().collect();
if parts.len() >= 3 {
files.push(FileEntry {
sha256: parts[0].to_string(),
size: parts[1].parse().unwrap_or(0),
name: parts[2].to_string(),
});
}
}
}
// Return package stanza
Ok(Some(PackageStanza {
package: stanza.get("Package").cloned().unwrap(),
version: stanza.get("Version").cloned().unwrap_or_default(),
directory: stanza.get("Directory").cloned().unwrap_or_default(),
format: stanza
.get("Format")
.cloned()
.unwrap_or_else(|| "1.0".to_string()),
vcs_git: stanza.get("Vcs-Git").cloned(),
vcs_browser: stanza.get("Vcs-Browser").cloned(),
files,
})) }))
} }