[pve-devel] [PATCH proxmox-apt 2/3] repository check: limit 'stable' to Proxmox and Debian origin

Fabian Ebner f.ebner at proxmox.com
Mon Jul 5 15:50:29 CEST 2021


For foreign repositories, it's a better heuristic to assume it's used
in a non-dangerous (i.e. no sudden major upgrade on release day) way.

Reported-by: Dominik Csapak <d.csapak at proxmox.com>
Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---
 src/repositories/file.rs | 57 ++++++++++++++++++----------------------
 src/repositories/mod.rs  | 12 ++++-----
 2 files changed, 30 insertions(+), 39 deletions(-)

diff --git a/src/repositories/file.rs b/src/repositories/file.rs
index 49cc358..b5bdb77 100644
--- a/src/repositories/file.rs
+++ b/src/repositories/file.rs
@@ -298,12 +298,31 @@ impl APTRepositoryFile {
         Ok(())
     }
 
-    /// Checks if old or unstable suites are configured and also that the
-    /// `stable` keyword is not used.
-    pub fn check_suites(&self) -> Result<Vec<APTRepositoryInfo>, Error> {
+    /// Checks if old or unstable suites are configured, and also tries to
+    /// determine the origin of each repository.
+    pub fn check(&self) -> Result<Vec<APTRepositoryInfo>, Error> {
         let mut infos = vec![];
 
         for (n, repo) in self.repositories.iter().enumerate() {
+            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(ref origin) = origin {
+                infos.push(APTRepositoryInfo {
+                    path: self.path.clone(),
+                    index: n,
+                    kind: "origin".to_string(),
+                    property: None,
+                    message: origin.to_string(),
+                });
+            }
+
             if !repo.types.contains(&APTRepositoryPackageType::Deb) {
                 continue;
             }
@@ -353,7 +372,9 @@ impl APTRepositoryFile {
                 }
             }
 
-            if repo.has_suite_variant("stable") {
+            if (origin == Some("Proxmox".to_string()) || origin == Some("Debian".to_string()))
+                && repo.has_suite_variant("stable")
+            {
                 add_info(
                     "warning".to_string(),
                     "use the name of the stable distribution instead of 'stable'!".to_string(),
@@ -363,32 +384,4 @@ impl APTRepositoryFile {
 
         Ok(infos)
     }
-
-    /// Checks for official URIs.
-    pub fn check_uris(&self) -> Vec<APTRepositoryInfo> {
-        let mut infos = vec![];
-
-        for (n, repo) in self.repositories.iter().enumerate() {
-            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: "origin".to_string(),
-                    property: None,
-                    message: origin,
-                });
-            }
-        }
-
-        infos
-    }
 }
diff --git a/src/repositories/mod.rs b/src/repositories/mod.rs
index 7bac333..6dd07f0 100644
--- a/src/repositories/mod.rs
+++ b/src/repositories/mod.rs
@@ -43,18 +43,16 @@ fn common_digest(files: &[APTRepositoryFile]) -> [u8; 32] {
     openssl::sha::sha256(&common_raw[..])
 }
 
-/// Provides additional information about the repositories.
+/// Currently checks if old or unstable suites are configured, and also tries to
+/// determine the origin of each repository.
 ///
-/// The kind of information can be:
-/// `warnings` for bad suites.
-/// `ignore-pre-upgrade-warning` when the next stable suite is configured.
-/// `badge` for official URIs.
+/// For problems, the kind of info will be `warning` for enabled repositories
+/// and `info` for disabled repositories. For the origin, the kind is `origin`.
 pub fn check_repositories(files: &[APTRepositoryFile]) -> Result<Vec<APTRepositoryInfo>, Error> {
     let mut infos = vec![];
 
     for file in files.iter() {
-        infos.append(&mut file.check_suites()?);
-        infos.append(&mut file.check_uris());
+        infos.append(&mut file.check()?);
     }
 
     Ok(infos)
-- 
2.30.2






More information about the pve-devel mailing list