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,
});
}
}
.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.
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()?;
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();
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();