From 480ce5f131a90fa967f076f097a1c5777bb5e505 Mon Sep 17 00:00:00 2001 From: Rafael Fonseca Date: Fri, 22 Nov 2019 22:43:16 +0100 Subject: [PATCH] fixup! deployment: add ostree_deployment_get_version API Make it private for now --- src/libostree/ostree-deployment-private.h | 2 ++ src/libostree/ostree-deployment.c | 30 +++++++++-------------- src/libostree/ostree-deployment.h | 2 -- src/libostree/ostree-sysroot-deploy.c | 4 +-- src/libostree/ostree-sysroot.c | 8 +++--- 5 files changed, 20 insertions(+), 26 deletions(-) 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 98927c5f9d..a4543fea70 100644 --- a/src/libostree/ostree-deployment.c +++ b/src/libostree/ostree-deployment.c @@ -63,37 +63,30 @@ ostree_deployment_get_bootserial (OstreeDeployment *self) return self->bootserial; } -/* - * ostree_deployment_get_version: - * @self: Deployment - * - * Returns: (transfer full): The deployment's version - */ char * -ostree_deployment_get_version (OstreeDeployment *self, - OstreeRepo *repo, - GError **error) +_ostree_deployment_get_version (OstreeDeployment *self, + OstreeRepo *repo, + GError **error) { - gchar *version = NULL; + g_return_val_if_fail (repo != NULL, NULL); - if (!repo) - return 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; - 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? */ + gchar *version = NULL; + g_autoptr(GVariant) variant = NULL; if (ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, csum, &variant, error)) { - metadata = g_variant_get_child_value (variant, 0); + g_autoptr(GVariant) metadata = g_variant_get_child_value (variant, 0); g_variant_lookup (metadata, OSTREE_COMMIT_META_KEY_VERSION, "s", &version); } + self->version = version; + return version; } @@ -270,6 +263,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-deployment.h b/src/libostree/ostree-deployment.h index 62f109ad7a..756e39d2b4 100644 --- a/src/libostree/ostree-deployment.h +++ b/src/libostree/ostree-deployment.h @@ -72,8 +72,6 @@ _OSTREE_PUBLIC OstreeBootconfigParser *ostree_deployment_get_bootconfig (OstreeDeployment *self); _OSTREE_PUBLIC GKeyFile *ostree_deployment_get_origin (OstreeDeployment *self); -_OSTREE_PUBLIC -char *ostree_deployment_get_version (OstreeDeployment *self, OstreeRepo *repo, GError **error); _OSTREE_PUBLIC gboolean ostree_deployment_is_staged (OstreeDeployment *self); diff --git a/src/libostree/ostree-sysroot-deploy.c b/src/libostree/ostree-sysroot-deploy.c index e0aa72dcff..60f08ccfaa 100644 --- a/src/libostree/ostree-sysroot-deploy.c +++ b/src/libostree/ostree-sysroot-deploy.c @@ -1740,8 +1740,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 = - ostree_deployment_get_version (deployment, repo, error); + 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 diff --git a/src/libostree/ostree-sysroot.c b/src/libostree/ostree-sysroot.c index 8ed6da6adc..4dfd5edf26 100644 --- a/src/libostree/ostree-sysroot.c +++ b/src/libostree/ostree-sysroot.c @@ -1635,7 +1635,7 @@ ostree_sysroot_simple_write_deployment (OstreeSysroot *sysroot, gboolean before_booted = TRUE; gboolean before_merge = TRUE; /* tracks last version */ - g_autofree char *last_version = NULL; + const gchar *last_version = NULL; gboolean retained_previous_version = FALSE; for (guint i = 0; i < deployments->len; i++) { @@ -1658,13 +1658,13 @@ ostree_sysroot_simple_write_deployment (OstreeSysroot *sysroot, if (!retained_previous_version) { OstreeRepo *repo = ostree_sysroot_repo (sysroot); - g_autofree char *deployment_version = - ostree_deployment_get_version (deployment, repo, error); + const gchar *deployment_version = + _ostree_deployment_get_version (deployment, repo, error); if (deployment_version && *deployment_version) { if (!last_version) - last_version = g_steal_pointer (&deployment_version); + last_version = deployment_version; is_previous_version = (osname_matches && passed_crossover && last_version && (g_strcmp0 (deployment_version, last_version) != 0));