standard repo detection: handle alternative URI for PVE repos

For PVE, URIs without the final "/pve" are also valid.

Make the single URL response a vector and iterate over it, lower
index is preferred.

Reported in the community forum:
https://forum.proxmox.com/threads/pve-7-0-9-no-proxmox-ve-repository-enabled.92427/

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
[ Thomas: extend commit message slightly ]
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Fabian Ebner 2021-07-16 14:36:02 +02:00 committed by Thomas Lamprecht
parent 652f52a1f2
commit 2a1fb9bfdd
5 changed files with 69 additions and 18 deletions

View File

@ -271,14 +271,17 @@ impl APTRepository {
/// Checks if the repository is the one referenced by the handle. /// 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) -> bool {
let (package_type, uri, component) = handle.info(product); let (package_type, handle_uris, component) = handle.info(product);
self.types.contains(&package_type) let mut found_uri = false;
&& self
.uris for uri in self.uris.iter() {
.iter() let uri = uri.trim_end_matches('/');
.any(|self_uri| self_uri.trim_end_matches('/') == uri)
&& self.components.contains(&component) found_uri = found_uri || handle_uris.iter().any(|handle_uri| handle_uri == uri);
}
self.types.contains(&package_type) && found_uri && self.components.contains(&component)
} }
/// Check if a variant of the given suite is configured in this repository /// Check if a variant of the given suite is configured in this repository

View File

@ -163,42 +163,62 @@ impl APTRepositoryHandle {
} }
} }
/// Get package type, URI and the component associated with the handle. /// Get package type, possible URIs and the component associated with the handle.
pub fn info(self, product: &str) -> (APTRepositoryPackageType, String, String) { ///
/// The first URI is the preferred one.
pub fn info(self, product: &str) -> (APTRepositoryPackageType, Vec<String>, String) {
match self { match self {
APTRepositoryHandle::Enterprise => ( APTRepositoryHandle::Enterprise => (
APTRepositoryPackageType::Deb, APTRepositoryPackageType::Deb,
format!("https://enterprise.proxmox.com/debian/{}", product), match product {
"pve" => vec![
"https://enterprise.proxmox.com/debian/pve".to_string(),
"https://enterprise.proxmox.com/debian".to_string(),
],
_ => vec![format!("https://enterprise.proxmox.com/debian/{}", product)],
},
format!("{}-enterprise", product), format!("{}-enterprise", product),
), ),
APTRepositoryHandle::NoSubscription => ( APTRepositoryHandle::NoSubscription => (
APTRepositoryPackageType::Deb, APTRepositoryPackageType::Deb,
format!("http://download.proxmox.com/debian/{}", product), match product {
"pve" => vec![
"http://download.proxmox.com/debian/pve".to_string(),
"http://download.proxmox.com/debian".to_string(),
],
_ => vec![format!("http://download.proxmox.com/debian/{}", product)],
},
format!("{}-no-subscription", product), format!("{}-no-subscription", product),
), ),
APTRepositoryHandle::Test => ( APTRepositoryHandle::Test => (
APTRepositoryPackageType::Deb, APTRepositoryPackageType::Deb,
format!("http://download.proxmox.com/debian/{}", product), match product {
"pve" => vec![
"http://download.proxmox.com/debian/pve".to_string(),
"http://download.proxmox.com/debian".to_string(),
],
_ => vec![format!("http://download.proxmox.com/debian/{}", product)],
},
format!("{}test", product), format!("{}test", product),
), ),
APTRepositoryHandle::CephPacific => ( APTRepositoryHandle::CephPacific => (
APTRepositoryPackageType::Deb, APTRepositoryPackageType::Deb,
"http://download.proxmox.com/debian/ceph-pacific".to_string(), vec!["http://download.proxmox.com/debian/ceph-pacific".to_string()],
"main".to_string(), "main".to_string(),
), ),
APTRepositoryHandle::CephPacificTest => ( APTRepositoryHandle::CephPacificTest => (
APTRepositoryPackageType::Deb, APTRepositoryPackageType::Deb,
"http://download.proxmox.com/debian/ceph-pacific".to_string(), vec!["http://download.proxmox.com/debian/ceph-pacific".to_string()],
"test".to_string(), "test".to_string(),
), ),
APTRepositoryHandle::CephOctopus => ( APTRepositoryHandle::CephOctopus => (
APTRepositoryPackageType::Deb, APTRepositoryPackageType::Deb,
"http://download.proxmox.com/debian/ceph-octopus".to_string(), vec!["http://download.proxmox.com/debian/ceph-octopus".to_string()],
"main".to_string(), "main".to_string(),
), ),
APTRepositoryHandle::CephOctopusTest => ( APTRepositoryHandle::CephOctopusTest => (
APTRepositoryPackageType::Deb, APTRepositoryPackageType::Deb,
"http://download.proxmox.com/debian/ceph-octopus".to_string(), vec!["http://download.proxmox.com/debian/ceph-octopus".to_string()],
"test".to_string(), "test".to_string(),
), ),
} }
@ -209,11 +229,11 @@ impl APTRepositoryHandle {
/// An URI in the result is not '/'-terminated (under the assumption that no valid /// An URI in the result is not '/'-terminated (under the assumption that no valid
/// product name is). /// product name is).
pub fn to_repository(self, product: &str, suite: &str) -> APTRepository { pub fn to_repository(self, product: &str, suite: &str) -> APTRepository {
let (package_type, uri, component) = self.info(product); let (package_type, uris, component) = self.info(product);
APTRepository { APTRepository {
types: vec![package_type], types: vec![package_type],
uris: vec![uri], uris: vec![uris.into_iter().next().unwrap()],
suites: vec![suite.to_string()], suites: vec![suite.to_string()],
components: vec![component], components: vec![component],
options: vec![], options: vec![],

View File

@ -358,5 +358,19 @@ fn test_standard_repositories() -> Result<(), Error> {
assert_eq!(std_repos, expected); assert_eq!(std_repos, expected);
let pve_alt_list = read_dir.join("pve-alt.list");
let mut file = APTRepositoryFile::new(&pve_alt_list)?.unwrap();
file.parse()?;
let file_vec = vec![file];
expected[0].status = Some(true);
expected[1].status = Some(true);
expected[2].status = Some(false);
let std_repos = standard_repositories("pve", &file_vec);
assert_eq!(std_repos, expected);
Ok(()) Ok(())
} }

View File

@ -0,0 +1,8 @@
deb https://enterprise.proxmox.com/debian bullseye pve-enterprise
deb http://download.proxmox.com/debian/ bullseye pve-no-subscription
# deb http://download.proxmox.com/debian bullseye pvetest
deb-src http://download.proxmox.com/debian bullseye pvetest

View File

@ -0,0 +1,6 @@
deb https://enterprise.proxmox.com/debian bullseye pve-enterprise
deb http://download.proxmox.com/debian/ bullseye pve-no-subscription
# deb http://download.proxmox.com/debian bullseye pvetest
deb-src http://download.proxmox.com/debian bullseye pvetest