[pve-devel] [PATCH proxmox-apt 2/3] check: return 'origin' property instead of 'badge' for official host
Fabian Ebner
f.ebner at proxmox.com
Wed Jun 30 12:20:17 CEST 2021
which is obtained from the cached InRelease file and also works for
mirrors, host aliases, direct IPs.
The has_official_uri function was replaced by origin_from_uris.
Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---
src/repositories/file.rs | 17 +++++++++++++----
src/repositories/repository.rs | 20 +++++++++++---------
tests/repositories.rs | 21 +++++++++++++++------
3 files changed, 39 insertions(+), 19 deletions(-)
diff --git a/src/repositories/file.rs b/src/repositories/file.rs
index 6225f1c..447fd0a 100644
--- a/src/repositories/file.rs
+++ b/src/repositories/file.rs
@@ -373,13 +373,22 @@ impl APTRepositoryFile {
let mut infos = vec![];
for (n, repo) in self.repositories.iter().enumerate() {
- if repo.has_official_uri() {
+ let mut origin = match repo.get_cached_origin() {
+ Ok(option) => option,
+ Err(_) => None,
+ };
+
+ if origin.is_none() {
+ origin = repo.origin_from_uris();
+ }
+
+ if let Some(origin) = origin {
infos.push(APTRepositoryInfo {
path: self.path.clone(),
index: n,
- kind: "badge".to_string(),
- property: Some("URIs".to_string()),
- message: "official host name".to_string(),
+ kind: "origin".to_string(),
+ property: None,
+ message: origin,
});
}
}
diff --git a/src/repositories/repository.rs b/src/repositories/repository.rs
index 5eba068..cf17380 100644
--- a/src/repositories/repository.rs
+++ b/src/repositories/repository.rs
@@ -288,21 +288,23 @@ impl APTRepository {
.any(|suite| suite_variant(suite).0 == base_suite)
}
- /// Checks if an official host is configured in the repository.
- pub fn has_official_uri(&self) -> bool {
+ /// Guess the origin from the repository's URIs.
+ ///
+ /// Intended to be used as a fallback for get_cached_origin.
+ pub fn origin_from_uris(&self) -> Option<String> {
for uri in self.uris.iter() {
if let Some(host) = host_from_uri(uri) {
- if host == "proxmox.com"
- || host.ends_with(".proxmox.com")
- || host == "debian.org"
- || host.ends_with(".debian.org")
- {
- return true;
+ if host == "proxmox.com" || host.ends_with(".proxmox.com") {
+ return Some("Proxmox".to_string());
+ }
+
+ if host == "debian.org" || host.ends_with(".debian.org") {
+ return Some("Debian".to_string());
}
}
}
- false
+ None
}
/// Get the `Origin:` value from a cached InRelease file.
diff --git a/tests/repositories.rs b/tests/repositories.rs
index 4067e60..3265bce 100644
--- a/tests/repositories.rs
+++ b/tests/repositories.rs
@@ -171,6 +171,11 @@ fn test_check_repositories() -> Result<(), Error> {
let test_dir = std::env::current_dir()?.join("tests");
let read_dir = test_dir.join("sources.list.d");
+ proxmox_apt::config::init(APTConfig::new(
+ Some(&test_dir.into_os_string().into_string().unwrap()),
+ None,
+ ));
+
let absolute_suite_list = read_dir.join("absolute_suite.list");
let mut file = APTRepositoryFile::new(&absolute_suite_list)?.unwrap();
file.parse()?;
@@ -184,14 +189,18 @@ fn test_check_repositories() -> Result<(), Error> {
let path_string = pve_list.into_os_string().into_string().unwrap();
+ let origins = [
+ "Debian", "Debian", "Proxmox", "Proxmox", "Proxmox", "Debian",
+ ];
+
let mut expected_infos = vec![];
for n in 0..=5 {
expected_infos.push(APTRepositoryInfo {
path: path_string.clone(),
index: n,
- property: Some("URIs".to_string()),
- kind: "badge".to_string(),
- message: "official host name".to_string(),
+ property: None,
+ kind: "origin".to_string(),
+ message: origins[n].to_string(),
});
}
expected_infos.sort();
@@ -255,9 +264,9 @@ fn test_check_repositories() -> Result<(), Error> {
expected_infos.push(APTRepositoryInfo {
path: path_string.clone(),
index: n,
- property: Some("URIs".to_string()),
- kind: "badge".to_string(),
- message: "official host name".to_string(),
+ property: None,
+ kind: "origin".to_string(),
+ message: "Debian".to_string(),
});
}
expected_infos.sort();
--
2.30.2
More information about the pve-devel
mailing list