From 37bc7b381299b33caed57ff7ade249803b387daf Mon Sep 17 00:00:00 2001 From: Rafael Fonseca Date: Fri, 1 Nov 2019 17:19:51 +0100 Subject: [PATCH] deployment: add ostree_deployment_get_version API Signed-off-by: Rafael Fonseca --- src/libostree/ostree-deployment-private.h | 3 +++ src/libostree/ostree-deployment.c | 29 +++++++++++++++++++++++ src/libostree/ostree-sysroot-deploy.c | 20 ++-------------- 3 files changed, 34 insertions(+), 18 deletions(-) diff --git a/src/libostree/ostree-deployment-private.h b/src/libostree/ostree-deployment-private.h index b339ae2618..c3e4959c8c 100644 --- a/src/libostree/ostree-deployment-private.h +++ b/src/libostree/ostree-deployment-private.h @@ -56,9 +56,12 @@ struct _OstreeDeployment gboolean staged; char **overlay_initrds; char *overlay_initrds_id; + gchar *version; + gboolean version_is_cached; }; void _ostree_deployment_set_bootcsum (OstreeDeployment *self, const char *bootcsum); +char *_ostree_deployment_get_version (OstreeDeployment *self, OstreeRepo *repo, GError **error); void _ostree_deployment_set_overlay_initrds (OstreeDeployment *self, char **overlay_initrds); diff --git a/src/libostree/ostree-deployment.c b/src/libostree/ostree-deployment.c index 558434dead..78ed1be166 100644 --- a/src/libostree/ostree-deployment.c +++ b/src/libostree/ostree-deployment.c @@ -87,6 +87,32 @@ ostree_deployment_get_bootserial (OstreeDeployment *self) return self->bootserial; } +char * +_ostree_deployment_get_version (OstreeDeployment *self, + OstreeRepo *repo, + GError **error) +{ + g_return_val_if_fail (repo != NULL, NULL); + + if (self->version_is_cached) + return self->version; + + self->version_is_cached = TRUE; + + /* Try extracting a version for this deployment. */ + const gchar *csum = ostree_deployment_get_csum (self); + + g_autoptr(GVariant) variant = NULL; + if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, csum, + &variant, error)) + return NULL; + + g_autoptr(GVariant) metadata = g_variant_get_child_value (variant, 0); + g_variant_lookup (metadata, OSTREE_COMMIT_META_KEY_VERSION, "s", &self->version); + + return self->version; +} + /** * ostree_deployment_get_bootconfig: * @self: Deployment @@ -259,6 +285,8 @@ ostree_deployment_clone (OstreeDeployment *self) self->deployserial, self->bootcsum, self->bootserial); + ret->version = g_strdup (self->version); + new_bootconfig = ostree_bootconfig_parser_clone (self->bootconfig); ostree_deployment_set_bootconfig (ret, new_bootconfig); @@ -331,6 +359,7 @@ ostree_deployment_finalize (GObject *object) g_free (self->osname); g_free (self->csum); g_free (self->bootcsum); + g_free (self->version); g_clear_object (&self->bootconfig); g_clear_pointer (&self->origin, g_key_file_unref); g_strfreev (self->overlay_initrds); diff --git a/src/libostree/ostree-sysroot-deploy.c b/src/libostree/ostree-sysroot-deploy.c index 32748a62f5..9e52727930 100644 --- a/src/libostree/ostree-sysroot-deploy.c +++ b/src/libostree/ostree-sysroot-deploy.c @@ -1923,24 +1923,8 @@ install_deployment_kernel (OstreeSysroot *sysroot, if (val == NULL) return glnx_throw (error, "No PRETTY_NAME or ID in /etc/os-release"); - g_autofree char *deployment_version = NULL; - if (repo) - { - /* Try extracting a version for this deployment. */ - const char *csum = ostree_deployment_get_csum (deployment); - g_autoptr(GVariant) variant = NULL; - g_autoptr(GVariant) metadata = NULL; - - /* XXX Copying ot_admin_checksum_version() + bits from - * ot-admin-builtin-status.c. Maybe this should be - * public API in libostree? */ - if (ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, csum, - &variant, NULL)) - { - metadata = g_variant_get_child_value (variant, 0); - g_variant_lookup (metadata, OSTREE_COMMIT_META_KEY_VERSION, "s", &deployment_version); - } - } + const gchar *deployment_version = + _ostree_deployment_get_version (deployment, repo, error); /* XXX The SYSLINUX bootloader backend actually parses the title string * (specifically, it looks for the substring "(ostree"), so further