[pbs-devel] [RFC v5 proxmox-backup 14/23] RFC: add upgrade_repositories call

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


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

New in v5.

Should the call be root-only?
How do we want to enable/disable the call pre-/post- upgrade?

 src/api2/node/apt.rs | 52 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)

diff --git a/src/api2/node/apt.rs b/src/api2/node/apt.rs
index deb481a7..6a56a5b5 100644
--- a/src/api2/node/apt.rs
+++ b/src/api2/node/apt.rs
@@ -509,6 +509,57 @@ pub fn get_repositories() -> Result<Value, Error> {
     }))
 }
 
+#[api(
+    input: {
+        properties: {
+            node: {
+                schema: NODE_SCHEMA,
+            },
+            digest: {
+                schema: PROXMOX_CONFIG_DIGEST_SCHEMA,
+                optional: true,
+            },
+        },
+    },
+    protected: true,
+    access: {
+        permission: &Permission::Privilege(&["system"], PRIV_SYS_MODIFY, false),
+    },
+)]
+/// Upgrade the repository configuration to the next major release.
+pub fn upgrade_repositories(digest: Option<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.len() == 0 {
+        bail!("no APT repository files could be parsed!");
+    }
+
+    if let Some(digest) = digest {
+        let expected_digest = proxmox::tools::hex_to_digest(&digest)?;
+        let current_digest = proxmox_apt::repositories::common_digest(&files);
+        crate::tools::detect_modified_configuration_file(&current_digest, &expected_digest)?;
+    }
+
+    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(())
+}
+
 const SUBDIRS: SubdirMap = &[
     ("changelog", &Router::new().get(&API_METHOD_APT_GET_CHANGELOG)),
     ("checkrepositories", &Router::new().get(&API_METHOD_CHECK_REPOSITORIES)),
@@ -517,6 +568,7 @@ const SUBDIRS: SubdirMap = &[
         .get(&API_METHOD_APT_UPDATE_AVAILABLE)
         .post(&API_METHOD_APT_UPDATE_DATABASE)
     ),
+    ("upgraderepositories", &Router::new().put(&API_METHOD_UPGRADE_REPOSITORIES)),
     ("versions", &Router::new().get(&API_METHOD_GET_VERSIONS)),
 ];
 
-- 
2.20.1






More information about the pbs-devel mailing list