[pbs-devel] [pve-devel] [PATCH v6 proxmox-backup 5/6] add upgrade_repositories call

Fabian Grünbichler f.gruenbichler at proxmox.com
Fri Jun 18 10:21:02 CEST 2021


On June 11, 2021 1:44 pm, Fabian Ebner wrote:
> Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
> ---
> 
> Note that the release_upgrade function is available with proxmox-apt 0.1.1
> (but disabled) so this can be applied to the master branch as well.
> 
> Changes from v5:
>     * limit to Superuser instead of SYS_MODIFY
>     * use new/renamed release_upgrade function from library.
>     * error if not all files could be parsed

not that important for the current use case, but.. we might want to add 
a lockfile for reading/writing the repo files? if we ever add 
full-fledged editing capabilities.. it's also reading/parsing multiple 
files, so a write might intermingle with that and cause inconsistent 
reads (first few files old, latter files updated)..

> 
>  src/api2/node/apt.rs | 53 ++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 53 insertions(+)
> 
> diff --git a/src/api2/node/apt.rs b/src/api2/node/apt.rs
> index deb481a7..861bc32b 100644
> --- a/src/api2/node/apt.rs
> +++ b/src/api2/node/apt.rs
> @@ -509,6 +509,58 @@ 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::Superuser,
> +    },
> +)]
> +/// Upgrade the repository configuration for the next major release.
> +pub fn upgrade_repositories(digest: Option<String>) -> Result<(), Error> {
> +    let (mut files, errors) = proxmox_apt::repositories::repositories()?;
> +
> +    if files.len() == 0 {
> +        bail!("no APT repository files could be parsed!");
> +    }
> +
> +    if errors.len() > 0 {
> +        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);
> +        crate::tools::detect_modified_configuration_file(&current_digest, &expected_digest)?;
> +    }
> +
> +    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(())
> +}
> +
>  const SUBDIRS: SubdirMap = &[
>      ("changelog", &Router::new().get(&API_METHOD_APT_GET_CHANGELOG)),
>      ("checkrepositories", &Router::new().get(&API_METHOD_CHECK_REPOSITORIES)),
> @@ -517,6 +569,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
> 
> 
> 
> _______________________________________________
> pve-devel mailing list
> pve-devel at lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
> 
> 
> 





More information about the pbs-devel mailing list