package_info: refactor sources parsing even more
All checks were successful
CI / build (push) Successful in 7m46s
All checks were successful
CI / build (push) Successful in 7m46s
This commit is contained in:
@@ -234,7 +234,7 @@ impl DebianSources {
|
||||
}
|
||||
}
|
||||
impl Iterator for DebianSources {
|
||||
type Item = HashMap<String, String>;
|
||||
type Item = PackageStanza;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
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)?;
|
||||
|
||||
// Find the right package, with the right version if requested
|
||||
let stanza = sources.find(|s| {
|
||||
let pkg = s.get("Package");
|
||||
pkg.is_some()
|
||||
&& 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,
|
||||
Ok(sources.find(|s| {
|
||||
s.package == target_package
|
||||
&& (target_version.is_none() || s.version == target_version.unwrap())
|
||||
}))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user