pull: split into package_info::lookup and pull
Some checks failed
CI / build (push) Failing after 1m47s

This commit is contained in:
2026-01-11 12:12:19 +01:00
parent b724d46f2c
commit 650adc28a3
5 changed files with 92 additions and 80 deletions

View File

@@ -332,7 +332,7 @@ fn parse_sources(
}
/// Get package information from a package, distribution series, and pocket
pub async fn get(
async fn get(
package_name: &str,
series: &str,
pocket: &str,
@@ -406,7 +406,7 @@ pub async fn get(
}
/// Try to find package information in a distribution, trying all series and pockets
pub async fn find_package(
async fn find_package(
package_name: &str,
dist: &str,
pocket: &str,
@@ -452,6 +452,58 @@ pub async fn find_package(
Err(format!("Package '{}' not found.", package_name).into())
}
/// Lookup package information for a source package
///
/// This function obtains package information either directly from a specific series
/// or by searching across all series in a distribution.
pub async fn lookup(
package: &str,
version: Option<&str>,
series: Option<&str>,
pocket: &str,
dist: Option<&str>,
progress: ProgressCallback<'_>,
) -> Result<PackageInfo, Box<dyn Error>> {
// Obtain the package information, either directly in a series or with a search in all series
let package_info = if let Some(s) = series {
if let Some(cb) = progress {
cb(
&format!("Resolving package info for {}...", package),
"",
0,
0,
);
}
// Get the package information from that series and pocket
get(package, s, pocket, version).await?
} else {
let dist = dist.unwrap_or_else(||
// Use auto-detection to see if current distro is ubuntu, or fallback to debian by default
if std::process::Command::new("lsb_release").arg("-i").arg("-s").output()
.map(|o| String::from_utf8_lossy(&o.stdout).trim().to_lowercase()).unwrap_or_default() == "ubuntu" {
"ubuntu"
} else {
"debian"
}
);
if let Some(cb) = progress {
cb(
&format!("Searching for package {} in {}...", package, dist),
"",
0,
0,
);
}
// Try to find the package in all series from that dist
find_package(package, dist, pocket, version, progress).await?
};
Ok(package_info)
}
#[cfg(test)]
mod tests {
use super::*;