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 Nov 11, 2019
1 parent ad28baf commit 9aa4b00
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 49 deletions.
34 changes: 34 additions & 0 deletions src/libostree/ostree-deployment.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,40 @@ 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)
{
gchar *version = NULL;

if (!repo)
return NULL;

/* 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? */
if (ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, csum,
&variant, error))
{
metadata = g_variant_get_child_value (variant, 0);
g_variant_lookup (metadata, OSTREE_COMMIT_META_KEY_VERSION, "s", &version);
}

return version;
}

/**
* ostree_deployment_get_bootconfig:
* @self: Deployment
Expand Down
2 changes: 2 additions & 0 deletions src/libostree/ostree-deployment.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ _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
20 changes: 2 additions & 18 deletions src/libostree/ostree-sysroot-deploy.c
Original file line number Diff line number Diff line change
Expand Up @@ -1740,24 +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 = 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);
}
}
g_autofree char *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
40 changes: 9 additions & 31 deletions src/libostree/ostree-sysroot.c
Original file line number Diff line number Diff line change
Expand Up @@ -1554,32 +1554,6 @@ ostree_sysroot_init_osname (OstreeSysroot *self,
return TRUE;
}

static gchar *
get_deployment_version (OstreeSysroot *sysroot,
OstreeDeployment *deployment,
GError **error)
{
gchar *deployment_version = NULL;

/* Try extracting a version for this deployment. */
const gchar *csum = ostree_deployment_get_csum (deployment);
g_autoptr(GVariant) variant = NULL;
g_autoptr(GVariant) metadata = NULL;

OstreeRepo *repo = ostree_sysroot_repo (sysroot);
/* 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, error))
{
metadata = g_variant_get_child_value (variant, 0);
g_variant_lookup (metadata, OSTREE_COMMIT_META_KEY_VERSION, "s", &deployment_version);
}

return deployment_version;
}

/**
* ostree_sysroot_simple_write_deployment:
* @sysroot: Sysroot
Expand Down Expand Up @@ -1683,14 +1657,18 @@ ostree_sysroot_simple_write_deployment (OstreeSysroot *sysroot,
gboolean is_previous_version = FALSE;
if (!retained_previous_version)
{
OstreeRepo *repo = ostree_sysroot_repo (sysroot);
g_autofree char *deployment_version =
get_deployment_version (sysroot, deployment, error);
ostree_deployment_get_version (deployment, repo, error);

if (!last_version)
last_version = g_steal_pointer (&deployment_version);
if (deployment_version && *deployment_version)
{
if (!last_version)
last_version = g_steal_pointer (&deployment_version);

is_previous_version = (osname_matches && passed_crossover && last_version &&
(g_strcmp0 (deployment_version, last_version) != 0));
is_previous_version = (osname_matches && passed_crossover && last_version &&
(g_strcmp0 (deployment_version, last_version) != 0));
}
}

/* Retain deployment if:
Expand Down

0 comments on commit 9aa4b00

Please sign in to comment.