[pbs-devel] [PATCH v6 pve-rs 3/4] apt: add upgrade_repositories call

Fabian Ebner f.ebner at proxmox.com
Fri Jun 11 13:44:12 CEST 2021


Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---

Changes from v5:
    * Add doc comment.
    * Make digest an Option<&str>.
    * use new/renamed release_upgrade function.
    * Require that all files can be parsed.

 src/apt/repositories.rs | 42 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/src/apt/repositories.rs b/src/apt/repositories.rs
index 1643a23..c8a06a6 100644
--- a/src/apt/repositories.rs
+++ b/src/apt/repositories.rs
@@ -66,4 +66,46 @@ mod export {
             to_value(&no_subscription_enabled)?,
         ))
     }
+
+    /// Upgrade the repository configuration to the next major release.
+    ///
+    /// If `digest` is specified and doesn't match the current one, the operation is aborted.
+    #[export]
+    fn upgrade_repositories(digest: Option<&str>) -> Result<(), Error> {
+        let (mut files, errors) = proxmox_apt::repositories::repositories()?;
+
+        if files.is_empty() {
+            bail!("no APT repository files could be parsed!");
+        }
+
+        if !errors.is_empty() {
+            let message = errors
+                .iter()
+                .fold("Problem parsing file(s):".to_string(), |message, error| {
+                    format!("{}\n{}", message, error)
+                });
+            bail!(message);
+        }
+
+        if let Some(digest) = digest {
+            let expected_digest = proxmox::tools::hex_to_digest(digest)?;
+            let current_digest = proxmox_apt::repositories::common_digest(&files);
+            if current_digest != expected_digest {
+                bail!("detected modified configuration - file changed by other user? Try again.");
+            }
+        }
+
+        proxmox_apt::repositories::release_upgrade(&mut files)?;
+
+        if let Err(errors) = proxmox_apt::repositories::write_repositories(&files) {
+            let message = errors
+                .iter()
+                .fold("Problem writing file(s):".to_string(), |message, error| {
+                    format!("{}\n{}", message, error)
+                });
+            bail!(message);
+        }
+
+        Ok(())
+    }
 }
-- 
2.20.1






More information about the pbs-devel mailing list