all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH proxmox-apt 4/5] repo: remove has_suite_variant helper
Date: Thu, 29 Jul 2021 14:25:51 +0200	[thread overview]
Message-ID: <20210729122554.148980-5-f.ebner@proxmox.com> (raw)
In-Reply-To: <20210729122554.148980-1-f.ebner@proxmox.com>

by exchanging loops in the check_suites function, which was the only
user. Exchanging loops also helps for introducing a type for Debian condenames.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---

Breaking change, as the helper was publicly accessable via the type,
but it was not actually used outside the library by us.

 src/repositories/file.rs       | 35 ++++++++++++++++++++++------------
 src/repositories/repository.rs | 16 ----------------
 2 files changed, 23 insertions(+), 28 deletions(-)

diff --git a/src/repositories/file.rs b/src/repositories/file.rs
index 254af4d..fe994f7 100644
--- a/src/repositories/file.rs
+++ b/src/repositories/file.rs
@@ -326,37 +326,39 @@ impl APTRepositoryFile {
                 None => bail!("unknown release {}", current_suite),
             };
 
-            for (n, suite) in DEBIAN_SUITES.iter().enumerate() {
-                if repo.has_suite_variant(suite) {
+            for suite in repo.suites.iter() {
+                let base_suite = suite_variant(suite).0;
+
+                if base_suite == "stable" {
+                    add_info(
+                        "warning".to_string(),
+                        "use the name of the stable distribution instead of 'stable'!".to_string(),
+                    );
+                }
+
+                if let Some(n) = DEBIAN_SUITES.iter().position(|&suite| suite == base_suite) {
                     if n < current_index {
                         add_info(
                             "warning".to_string(),
-                            format!("old suite '{}' configured!", suite),
+                            format!("old suite '{}' configured!", base_suite),
                         );
                     }
 
                     if n == current_index + 1 {
                         add_info(
                             "ignore-pre-upgrade-warning".to_string(),
-                            format!("suite '{}' should not be used in production!", suite),
+                            format!("suite '{}' should not be used in production!", base_suite),
                         );
                     }
 
                     if n > current_index + 1 {
                         add_info(
                             "warning".to_string(),
-                            format!("suite '{}' should not be used in production!", suite),
+                            format!("suite '{}' should not be used in production!", base_suite),
                         );
                     }
                 }
             }
-
-            if repo.has_suite_variant("stable") {
-                add_info(
-                    "warning".to_string(),
-                    "use the name of the stable distribution instead of 'stable'!".to_string(),
-                );
-            }
         }
 
         Ok(infos)
@@ -390,3 +392,12 @@ impl APTRepositoryFile {
         infos
     }
 }
+
+/// 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) {
+    match suite.find(&['-', '/'][..]) {
+        Some(n) => (&suite[0..n], &suite[n..]),
+        None => (suite, ""),
+    }
+}
diff --git a/src/repositories/repository.rs b/src/repositories/repository.rs
index d85f063..85c8bdd 100644
--- a/src/repositories/repository.rs
+++ b/src/repositories/repository.rs
@@ -293,13 +293,6 @@ impl APTRepository {
             && self.components.contains(&component)
     }
 
-    /// Check if a variant of the given suite is configured in this repository
-    pub fn has_suite_variant(&self, base_suite: &str) -> bool {
-        self.suites
-            .iter()
-            .any(|suite| suite_variant(suite).0 == base_suite)
-    }
-
     /// Guess the origin from the repository's URIs.
     ///
     /// Intended to be used as a fallback for get_cached_origin.
@@ -432,15 +425,6 @@ fn host_from_uri(uri: &str) -> Option<&str> {
     Some(host)
 }
 
-/// 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) {
-    match suite.find(&['-', '/'][..]) {
-        Some(n) => (&suite[0..n], &suite[n..]),
-        None => (suite, ""),
-    }
-}
-
 /// Strips existing double quotes from the string first, and then adds double quotes at
 /// the beginning and end if there is an ASCII whitespace in the `string`, which is not
 /// escaped by `[]`.
-- 
2.30.2





  parent reply	other threads:[~2021-07-29 12:26 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-29 12:25 [pve-devel] [PATCH-SERIES proxmox-apt/pve-rs] better detection of standard repositories Fabian Ebner
2021-07-29 12:25 ` [pve-devel] [PATCH proxmox-apt 1/5] standard repos: add suite parameter for stricter detection Fabian Ebner
2021-07-29 12:25 ` [pve-devel] [PATCH proxmox-apt 2/5] repo: make suite_variant helper more general Fabian Ebner
2021-07-29 12:25 ` [pve-devel] [PATCH proxmox-apt 3/5] check repos: have caller specify the current suite Fabian Ebner
2021-07-29 12:25 ` Fabian Ebner [this message]
2021-07-29 12:25 ` [pve-devel] [PATCH proxmox-apt 5/5] add type DebianCodename Fabian Ebner
2021-07-29 12:25 ` [pve-devel] [PATCH pve-rs 1/2] apt: repos: adapt to back-end changes Fabian Ebner
2021-07-29 12:25 ` [pve-devel] [PATCH pve-rs 2/2] apt: repos: adapt to further " Fabian Ebner
2021-07-30  8:47 ` [pve-devel] applied-series: Re: [PATCH-SERIES proxmox-apt/pve-rs] better detection of standard repositories Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210729122554.148980-5-f.ebner@proxmox.com \
    --to=f.ebner@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal