diff --git a/src/libostree/ostree-deployment-private.h b/src/libostree/ostree-deployment-private.h index ad77317d79..880f9b562d 100644 --- a/src/libostree/ostree-deployment-private.h +++ b/src/libostree/ostree-deployment-private.h @@ -52,8 +52,10 @@ struct _OstreeDeployment GKeyFile *origin; OstreeDeploymentUnlockedState unlocked; gboolean staged; + gchar *version; }; void _ostree_deployment_set_bootcsum (OstreeDeployment *self, const char *bootcsum); +char *_ostree_deployment_get_version (OstreeDeployment *self, OstreeRepo *repo, GError **error); G_END_DECLS diff --git a/src/libostree/ostree-deployment.c b/src/libostree/ostree-deployment.c index 6532a973dc..9d5763b255 100644 --- a/src/libostree/ostree-deployment.c +++ b/src/libostree/ostree-deployment.c @@ -63,6 +63,30 @@ 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 != NULL) + return self->version; + + /* 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 @@ -172,6 +196,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); @@ -236,6 +262,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); diff --git a/src/libostree/ostree-sysroot-deploy.c b/src/libostree/ostree-sysroot-deploy.c index ee00c02c5e..6fc851c29b 100644 --- a/src/libostree/ostree-sysroot-deploy.c +++ b/src/libostree/ostree-sysroot-deploy.c @@ -1783,24 +1783,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