From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH proxmox-apt 1/5] standard repos: add suite parameter for stricter detection
Date: Thu, 29 Jul 2021 14:25:48 +0200 [thread overview]
Message-ID: <20210729122554.148980-2-f.ebner@proxmox.com> (raw)
In-Reply-To: <20210729122554.148980-1-f.ebner@proxmox.com>
Require that the suite matches too when detecting standard
repositories, since no or invalid updates will be obtained when the
suite is wrong. Thus, it should not be considered to be the same
repository.
Add the parameter for get_standard_repository too, so that the two
related calls have more similar parameters, and the detection of the
current release code name can be done once in the caller once.
This also will fix an issue with the front-end, where adding a
standard repository would end up just enabling an already present
repository with the wrong suite.
Reported-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---
src/repositories/mod.rs | 20 ++++++++++----------
src/repositories/repository.rs | 13 +++++++++++--
tests/repositories.rs | 21 +++++++++++++++------
3 files changed, 36 insertions(+), 18 deletions(-)
diff --git a/src/repositories/mod.rs b/src/repositories/mod.rs
index 7bac333..8637851 100644
--- a/src/repositories/mod.rs
+++ b/src/repositories/mod.rs
@@ -12,7 +12,7 @@ mod file;
pub use file::{APTRepositoryFile, APTRepositoryFileError, APTRepositoryInfo};
mod release;
-use release::get_current_release_codename;
+pub use release::get_current_release_codename;
mod standard;
pub use standard::{APTRepositoryHandle, APTStandardRepository};
@@ -60,24 +60,24 @@ pub fn check_repositories(files: &[APTRepositoryFile]) -> Result<Vec<APTReposito
Ok(infos)
}
-/// Get the repository associated to the handle and the path where its usually configured.
+/// Get the repository associated to the handle and the path where it is usually configured.
pub fn get_standard_repository(
handle: APTRepositoryHandle,
product: &str,
-) -> Result<(APTRepository, String), Error> {
- let suite = get_current_release_codename()?;
-
+ suite: &str,
+) -> (APTRepository, String) {
let repo = handle.to_repository(product, &suite);
let path = handle.path(product);
- Ok((repo, path))
+ (repo, path)
}
-/// Return handles for standard Proxmox repositories and whether their status, where
-/// None means not configured, and Some(bool) indicates enabled or disabled
+/// Return handles for standard Proxmox repositories and their status, where
+/// `None` means not configured, and `Some(bool)` indicates enabled or disabled.
pub fn standard_repositories(
- product: &str,
files: &[APTRepositoryFile],
+ product: &str,
+ suite: &str,
) -> Vec<APTStandardRepository> {
let mut result = vec![
APTStandardRepository::from(APTRepositoryHandle::Enterprise),
@@ -101,7 +101,7 @@ pub fn standard_repositories(
continue;
}
- if repo.is_referenced_repository(entry.handle, product) {
+ if repo.is_referenced_repository(entry.handle, product, suite) {
entry.status = Some(repo.enabled);
}
}
diff --git a/src/repositories/repository.rs b/src/repositories/repository.rs
index b56ec47..fc16327 100644
--- a/src/repositories/repository.rs
+++ b/src/repositories/repository.rs
@@ -270,7 +270,12 @@ impl APTRepository {
}
/// Checks if the repository is the one referenced by the handle.
- pub fn is_referenced_repository(&self, handle: APTRepositoryHandle, product: &str) -> bool {
+ pub fn is_referenced_repository(
+ &self,
+ handle: APTRepositoryHandle,
+ product: &str,
+ suite: &str,
+ ) -> bool {
let (package_type, handle_uris, component) = handle.info(product);
let mut found_uri = false;
@@ -281,7 +286,11 @@ impl APTRepository {
found_uri = found_uri || handle_uris.iter().any(|handle_uri| handle_uri == uri);
}
- self.types.contains(&package_type) && found_uri && self.components.contains(&component)
+ self.types.contains(&package_type)
+ && found_uri
+ // using contains would require a &String
+ && self.suites.iter().any(|self_suite| self_suite == suite)
+ && self.components.contains(&component)
}
/// Check if a variant of the given suite is configured in this repository
diff --git a/tests/repositories.rs b/tests/repositories.rs
index 6435671..4cbde60 100644
--- a/tests/repositories.rs
+++ b/tests/repositories.rs
@@ -5,8 +5,8 @@ use anyhow::{bail, format_err, Error};
use proxmox_apt::config::APTConfig;
use proxmox_apt::repositories::{
- check_repositories, standard_repositories, APTRepositoryFile, APTRepositoryHandle,
- APTRepositoryInfo, APTStandardRepository,
+ check_repositories, get_current_release_codename, standard_repositories, APTRepositoryFile,
+ APTRepositoryHandle, APTRepositoryInfo, APTStandardRepository,
};
#[test]
@@ -337,7 +337,7 @@ fn test_standard_repositories() -> Result<(), Error> {
let mut file = APTRepositoryFile::new(&absolute_suite_list)?.unwrap();
file.parse()?;
- let std_repos = standard_repositories("pve", &vec![file]);
+ let std_repos = standard_repositories(&vec![file], "pve", "bullseye");
assert_eq!(std_repos, expected);
@@ -347,14 +347,14 @@ fn test_standard_repositories() -> Result<(), Error> {
let file_vec = vec![file];
- let std_repos = standard_repositories("pbs", &file_vec);
+ let std_repos = standard_repositories(&file_vec, "pbs", "bullseye");
assert_eq!(&std_repos, &expected[0..=2]);
expected[0].status = Some(false);
expected[1].status = Some(true);
- let std_repos = standard_repositories("pve", &file_vec);
+ let std_repos = standard_repositories(&file_vec, "pve", "bullseye");
assert_eq!(std_repos, expected);
@@ -368,9 +368,18 @@ fn test_standard_repositories() -> Result<(), Error> {
expected[1].status = Some(true);
expected[2].status = Some(false);
- let std_repos = standard_repositories("pve", &file_vec);
+ let std_repos = standard_repositories(&file_vec, "pve", "bullseye");
assert_eq!(std_repos, expected);
Ok(())
}
+
+#[test]
+fn test_get_current_release_codename() -> Result<(), Error> {
+ let codename = get_current_release_codename()?;
+
+ assert_eq!(&codename, "bullseye");
+
+ Ok(())
+}
--
2.30.2
next prev 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 ` Fabian Ebner [this message]
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 ` [pve-devel] [PATCH proxmox-apt 4/5] repo: remove has_suite_variant helper Fabian Ebner
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-2-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox