Skip to content

Commit

Permalink
fixup! deployment: add ostree_deployment_get_version API
Browse files Browse the repository at this point in the history
Make it private for now
  • Loading branch information
r4f4 committed Nov 22, 2019
1 parent 881a7a2 commit 480ce5f
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 26 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
30 changes: 12 additions & 18 deletions src/libostree/ostree-deployment.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

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

Expand Down
2 changes: 0 additions & 2 deletions src/libostree/ostree-deployment.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/libostree/ostree-sysroot-deploy.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/libostree/ostree-sysroot.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
{
Expand All @@ -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));
Expand Down

0 comments on commit 480ce5f

Please sign in to comment.