[pve-devel] [PATCH proxmox-apt 2/5] repo: make suite_variant helper more general

Fabian Ebner f.ebner at proxmox.com
Thu Jul 29 14:25:49 CEST 2021


use the first appearance of '-' or '/' to detect the variant instead
of keeping a list of possible variants, which would need to include
things like "-proposed-updates-debug".

Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---
 src/repositories/repository.rs | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/src/repositories/repository.rs b/src/repositories/repository.rs
index fc16327..d85f063 100644
--- a/src/repositories/repository.rs
+++ b/src/repositories/repository.rs
@@ -433,16 +433,12 @@ fn host_from_uri(uri: &str) -> Option<&str> {
 }
 
 /// Splits the suite into its base part and variant.
+/// Does not expect the base part to contain either `-` or `/`.
 fn suite_variant(suite: &str) -> (&str, &str) {
-    let variants = ["-backports-sloppy", "-backports", "-updates", "/updates"];
-
-    for variant in variants.iter() {
-        if let Some(base) = suite.strip_suffix(variant) {
-            return (base, variant);
-        }
+    match suite.find(&['-', '/'][..]) {
+        Some(n) => (&suite[0..n], &suite[n..]),
+        None => (suite, ""),
     }
-
-    (suite, "")
 }
 
 /// Strips existing double quotes from the string first, and then adds double quotes at
-- 
2.30.2






More information about the pve-devel mailing list