distro_info: accept case-insensitive dist in effective_series, fix UNRELEASED fallbacks
This commit is contained in:
+24
-3
@@ -220,18 +220,24 @@ pub async fn get_ordered_series_name(dist: &str) -> Result<Vec<String>, Box<dyn
|
|||||||
/// the development series of `dist`, i.e. the first entry of
|
/// the development series of `dist`, i.e. the first entry of
|
||||||
/// [`get_ordered_series_name`] (which is documented "development series
|
/// [`get_ordered_series_name`] (which is documented "development series
|
||||||
/// first"). UNRELEASED work conventionally targets the next release, not
|
/// first"). UNRELEASED work conventionally targets the next release, not
|
||||||
/// the last stable one. Any other `series` is returned unchanged. Errors
|
/// the last stable one. `dist` is matched case-insensitively, so vendor
|
||||||
|
/// names with original casing (dpkg's `Vendor:` field is e.g. "Ubuntu")
|
||||||
|
/// are accepted as-is. Any other `series` is returned unchanged. Errors
|
||||||
/// when `dist` is unknown or has no series list.
|
/// when `dist` is unknown or has no series list.
|
||||||
pub async fn effective_series(series: &str, dist: &str) -> Result<String, Box<dyn Error>> {
|
pub async fn effective_series(series: &str, dist: &str) -> Result<String, Box<dyn Error>> {
|
||||||
if !is_unreleased(series) {
|
if !is_unreleased(series) {
|
||||||
return Ok(series.to_string());
|
return Ok(series.to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
get_ordered_series_name(dist)
|
// The series data keys are lowercase, unlike the vendor names that
|
||||||
|
// callers typically resolve from dpkg
|
||||||
|
let dist = dist.to_lowercase();
|
||||||
|
|
||||||
|
get_ordered_series_name(&dist)
|
||||||
.await?
|
.await?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.next()
|
.next()
|
||||||
.ok_or_else(|| format!("Distribution '{}' has no series to target", dist).into())
|
.ok_or_else(|| format!("Distribution '{dist}' has no series to target").into())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the latest released series for a dist (excluding future releases and special cases like sid)
|
/// Get the latest released series for a dist (excluding future releases and special cases like sid)
|
||||||
@@ -587,6 +593,21 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_effective_series_unreleased_dist_case_insensitive() {
|
||||||
|
// Distro data keys are lowercase but dpkg vendors keep original
|
||||||
|
// casing ("Ubuntu"): the UNRELEASED lookup must resolve both
|
||||||
|
let expected = effective_series(UNRELEASED, "ubuntu").await.unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
effective_series(UNRELEASED, "Ubuntu").await.unwrap(),
|
||||||
|
expected
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
effective_series(UNRELEASED, "UBUNTU").await.unwrap(),
|
||||||
|
expected
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_effective_series_unknown_dist() {
|
async fn test_effective_series_unknown_dist() {
|
||||||
// UNRELEASED on an unknown distribution cannot be resolved
|
// UNRELEASED on an unknown distribution cannot be resolved
|
||||||
|
|||||||
+3
-1
@@ -206,7 +206,9 @@ fn main() {
|
|||||||
// its own distribution.
|
// its own distribution.
|
||||||
match rt.block_on(async {
|
match rt.block_on(async {
|
||||||
if pkh::distro_info::is_unreleased(¤t_series) {
|
if pkh::distro_info::is_unreleased(¤t_series) {
|
||||||
let dist = pkh::build::env::current_vendor();
|
// Vendors keep original casing ("Ubuntu"),
|
||||||
|
// while the series data keys are lowercase
|
||||||
|
let dist = pkh::build::env::current_vendor().to_lowercase();
|
||||||
let mut series_list =
|
let mut series_list =
|
||||||
vec![pkh::distro_info::UNRELEASED.to_string()];
|
vec![pkh::distro_info::UNRELEASED.to_string()];
|
||||||
series_list.extend(
|
series_list.extend(
|
||||||
|
|||||||
Reference in New Issue
Block a user