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 Feb 4, 2020
1 parent bdf83e6 commit 1efa4e9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 18 deletions.
2 changes: 2 additions & 0 deletions src/libostree/ostree-deployment-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
27 changes: 27 additions & 0 deletions src/libostree/ostree-deployment.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

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 @@ -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
Expand Down

0 comments on commit 1efa4e9

Please sign in to comment.