Skip to content

Commit

Permalink
deployment: add ostree_deployment_get_version API
Browse files Browse the repository at this point in the history
Signed-off-by: Rafael Fonseca <[email protected]>
  • Loading branch information
r4f4 committed Apr 21, 2021
1 parent 0fcf4a3 commit 37bc7b3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 18 deletions.
3 changes: 3 additions & 0 deletions src/libostree/ostree-deployment-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
29 changes: 29 additions & 0 deletions src/libostree/ostree-deployment.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down
20 changes: 2 additions & 18 deletions src/libostree/ostree-sysroot-deploy.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 37bc7b3

Please sign in to comment.