[pbs-devel] [RFC v5 pve-rs 19/23] RFC: add upgrade_repositories wrapper

Fabian Ebner f.ebner at proxmox.com
Fri May 28 16:29:58 CEST 2021


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

New in v5.

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

diff --git a/perlmod/src/apt/repositories.rs b/perlmod/src/apt/repositories.rs
index 37a62f2..d9d9429 100644
--- a/perlmod/src/apt/repositories.rs
+++ b/perlmod/src/apt/repositories.rs
@@ -52,4 +52,41 @@ mod export {
             to_value(&no_subscription_enabled)?,
         ))
     }
+
+    #[export]
+    fn upgrade_repositories(digest: String) -> Result<(), Error> {
+        //bail!("next major version not released yet, or current version not fully upgraded");
+
+        // TODO should it be required that all files could be parsed?
+        let (mut files, _errors) = proxmox_apt::repositories::repositories()?;
+
+        if files.is_empty() {
+            bail!("no APT repository files could be parsed!");
+        }
+
+        if !digest.is_empty() {
+            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::replace_suite(
+            &mut files,
+            proxmox_apt::repositories::STABLE_SUITE,
+            proxmox_apt::repositories::NEXT_STABLE_SUITE,
+        );
+
+        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