deb: cross uses new apt sources parser

This commit is contained in:
2026-01-10 00:46:04 +01:00
parent d2914c63c6
commit 64b51563e7
2 changed files with 128 additions and 157 deletions

View File

@@ -16,8 +16,8 @@ pub struct SourceEntry {
pub architectures: Vec<String>,
/// Source URI
pub uri: String,
/// Source suite (series-pocket)
pub suite: String,
/// Source suites (series-pocket)
pub suite: Vec<String>,
}
impl SourceEntry {
@@ -28,7 +28,7 @@ impl SourceEntry {
components: Vec::new(),
architectures: Vec::new(),
uri: String::new(),
suite: String::new(),
suite: Vec::new(),
};
for line in data.lines() {
@@ -55,7 +55,10 @@ impl SourceEntry {
// We only care about deb types
}
"URIs" => current_entry.uri = value.to_string(),
"Suites" => current_entry.suite = value.to_string(),
"Suites" => {
current_entry.suite =
value.split_whitespace().map(|s| s.to_string()).collect();
}
"Components" => {
current_entry.components =
value.split_whitespace().map(|s| s.to_string()).collect();
@@ -123,7 +126,7 @@ impl SourceEntry {
}
let uri = parts[1].to_string();
let suite = parts[2].to_string();
let suite = vec![parts[2].to_string()];
let components: Vec<String> = parts[3..].iter().map(|&s| s.to_string()).collect();
Some(SourceEntry {
@@ -139,26 +142,31 @@ impl SourceEntry {
pub fn to_legacy(&self) -> String {
let mut result = String::new();
// Start with "deb" type
result.push_str("deb");
// Legacy entries contain one suite per line
for suite in &self.suite {
// Start with "deb" type
result.push_str("deb");
// Add architectures if present
if !self.architectures.is_empty() {
result.push_str(" [arch=");
result.push_str(&self.architectures.join(","));
result.push(']');
}
// Add architectures if present
if !self.architectures.is_empty() {
result.push_str(" [arch=");
result.push_str(&self.architectures.join(","));
result.push(']');
}
// Add URI and suite
result.push(' ');
result.push_str(&self.uri);
result.push(' ');
result.push_str(&self.suite);
// Add components
if !self.components.is_empty() {
// Add URI and suite
result.push(' ');
result.push_str(&self.components.join(" "));
result.push_str(&self.uri);
result.push(' ');
result.push_str(suite);
// Add components
if !self.components.is_empty() {
result.push(' ');
result.push_str(&self.components.join(" "));
}
result.push('\n');
}
result
@@ -275,12 +283,17 @@ mod tests {
assert_eq!(sources.len(), 3);
assert_eq!(sources[0].uri, "http://fr.archive.ubuntu.com/ubuntu/");
assert_eq!(sources[0].architectures, vec!["amd64"]);
assert_eq!(
sources[0].suite,
vec!["questing", "questing-updates", "questing-backports"]
);
assert_eq!(
sources[0].components,
vec!["main", "restricted", "universe", "multiverse"]
);
assert_eq!(sources[1].uri, "http://security.ubuntu.com/ubuntu/");
assert_eq!(sources[1].architectures, vec!["amd64"]);
assert_eq!(sources[1].suite, vec!["questing-security"]);
assert_eq!(
sources[1].components,
vec!["main", "restricted", "universe", "multiverse"]
@@ -288,6 +301,10 @@ mod tests {
assert_eq!(sources[2].uri, "http://ports.ubuntu.com/ubuntu-ports/");
assert_eq!(sources[2].architectures.len(), 1);
assert_eq!(sources[2].architectures, vec!["riscv64"]);
assert_eq!(
sources[2].suite,
vec!["questing", "questing-updates", "questing-backports"]
);
assert_eq!(
sources[2].components,
vec!["main", "restricted", "universe", "multiverse"]
@@ -305,15 +322,15 @@ mod tests {
let sources = parse_legacy(legacy);
assert_eq!(sources.len(), 3);
assert_eq!(sources[0].uri, "http://archive.ubuntu.com/ubuntu");
assert_eq!(sources[0].suite, "resolute");
assert_eq!(sources[0].suite, vec!["resolute"]);
assert_eq!(sources[0].components, vec!["main", "universe"]);
assert_eq!(sources[0].architectures, vec!["amd64"]);
assert_eq!(sources[1].uri, "http://archive.ubuntu.com/ubuntu");
assert_eq!(sources[1].suite, "resolute-updates");
assert_eq!(sources[1].suite, vec!["resolute-updates"]);
assert_eq!(sources[1].components, vec!["main"]);
assert_eq!(sources[1].architectures, vec!["amd64", "i386"]);
assert_eq!(sources[2].uri, "http://security.ubuntu.com/ubuntu");
assert_eq!(sources[2].suite, "resolute-security");
assert_eq!(sources[2].suite, vec!["resolute-security"]);
assert_eq!(sources[2].components, vec!["main"]);
}
}