From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id CFD2A69F2B for ; Thu, 29 Jul 2021 14:26:29 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 1892A2EE2A for ; Thu, 29 Jul 2021 14:26:01 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id DC7082EE5B for ; Thu, 29 Jul 2021 14:25:58 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id B026142C66 for ; Thu, 29 Jul 2021 14:25:58 +0200 (CEST) From: Fabian Ebner To: pve-devel@lists.proxmox.com Date: Thu, 29 Jul 2021 14:25:51 +0200 Message-Id: <20210729122554.148980-5-f.ebner@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210729122554.148980-1-f.ebner@proxmox.com> References: <20210729122554.148980-1-f.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.459 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH proxmox-apt 4/5] repo: remove has_suite_variant helper X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 29 Jul 2021 12:26:29 -0000 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 --- 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