Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[merged] RPMOSTreeSysroot: add "booted" entry to deployment variant #350

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions src/app/rpmostree-builtin-status.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,10 @@ static gboolean
status_generic (RPMOSTreeSysroot *sysroot_proxy,
RPMOSTreeOS *os_proxy,
GVariant *deployments,
GVariant *booted_deployment,
GCancellable *cancellable,
GError **error)
{
GVariantIter iter;
const char *booted_id = NULL;
gboolean first = TRUE;
const int is_tty = isatty (1);
const char *bold_prefix = is_tty ? "\x1b[1m" : "";
Expand All @@ -104,9 +102,6 @@ status_generic (RPMOSTreeSysroot *sysroot_proxy,
g_print ("State: idle\n");
g_print ("Deployments:\n");

if (booted_deployment)
g_assert (g_variant_lookup (booted_deployment, "id", "&s", &booted_id));

g_variant_iter_init (&iter, deployments);

while (TRUE)
Expand Down Expand Up @@ -174,7 +169,8 @@ status_generic (RPMOSTreeSysroot *sysroot_proxy,
else
g_print ("\n");

is_booted = g_strcmp0 (booted_id, id) == 0;
if (!g_variant_dict_lookup (dict, "booted", "b", &is_booted))
is_booted = FALSE;

g_print ("%s ", is_booted ? libsd_special_glyph (BLACK_CIRCLE) : " ");

Expand Down Expand Up @@ -248,7 +244,6 @@ rpmostree_builtin_status (int argc,
GOptionContext *context = g_option_context_new ("- Get the version of the booted system");
glnx_unref_object RPMOSTreeOS *os_proxy = NULL;
glnx_unref_object RPMOSTreeSysroot *sysroot_proxy = NULL;
g_autoptr(GVariant) booted_deployment = NULL;
g_autoptr(GVariant) deployments = NULL;

if (!rpmostree_option_context_parse (context,
Expand All @@ -265,7 +260,6 @@ rpmostree_builtin_status (int argc,
goto out;

deployments = rpmostree_sysroot_dup_deployments (sysroot_proxy);
booted_deployment = rpmostree_os_dup_booted_deployment (os_proxy);

if (opt_json)
{
Expand Down Expand Up @@ -297,7 +291,6 @@ rpmostree_builtin_status (int argc,
else
{
if (!status_generic (sysroot_proxy, os_proxy, deployments,
booted_deployment,
cancellable, error))
goto out;
}
Expand Down
1 change: 1 addition & 0 deletions src/daemon/org.projectatomic.rpmostree1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
'origin' (type 's')
'signatures' (type 'av')
'packages' (type 'as')
'booted' (type 'b')
-->

<interface name="org.projectatomic.rpmostree1.Sysroot">
Expand Down
4 changes: 4 additions & 0 deletions src/daemon/rpmostreed-deployment-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ variant_add_commit_details (GVariantDict *dict,

GVariant *
rpmostreed_deployment_generate_variant (OstreeDeployment *deployment,
const char *booted_id,
OstreeRepo *repo,
GError **error)
{
Expand Down Expand Up @@ -244,6 +245,9 @@ rpmostreed_deployment_generate_variant (OstreeDeployment *deployment,
g_variant_dict_insert (&dict, "unlocked", "s",
ostree_deployment_unlocked_state_to_string (ostree_deployment_get_unlocked (deployment)));

if (booted_id != NULL)
g_variant_dict_insert (&dict, "booted", "b", g_strcmp0 (booted_id, id) == 0);

return g_variant_dict_end (&dict);
}

Expand Down
1 change: 1 addition & 0 deletions src/daemon/rpmostreed-deployment-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ void rpmostreed_deployment_get_refspec_packages (OstreeDeployment *de
GVariant * rpmostreed_deployment_generate_blank_variant (void);

GVariant * rpmostreed_deployment_generate_variant (OstreeDeployment *deployment,
const char *booted_id,
OstreeRepo *repo,
GError **error);

Expand Down
23 changes: 12 additions & 11 deletions src/daemon/rpmostreed-os.c
Original file line number Diff line number Diff line change
Expand Up @@ -1089,6 +1089,7 @@ rpmostreed_os_load_internals (RpmostreedOS *self, GError **error)
const gchar *name;

OstreeDeployment *booted = NULL; /* owned by sysroot */
g_autofree gchar* booted_id = NULL;
glnx_unref_object OstreeDeployment *merge_deployment = NULL; /* transfered */

g_autoptr(GPtrArray) deployments = NULL;
Expand All @@ -1110,35 +1111,35 @@ rpmostreed_os_load_internals (RpmostreedOS *self, GError **error)
ot_sysroot = rpmostreed_sysroot_get_root (rpmostreed_sysroot_get ());
ot_repo = rpmostreed_sysroot_get_repo (rpmostreed_sysroot_get ());

deployments = ostree_sysroot_get_deployments (ot_sysroot);
booted = ostree_sysroot_get_booted_deployment (ot_sysroot);
if (booted && g_strcmp0 (ostree_deployment_get_osname (booted), name) == 0)
{
booted_variant = rpmostreed_deployment_generate_variant (booted, booted_id, ot_repo, error);
if (!booted_variant)
return FALSE;
booted_id = rpmostreed_deployment_generate_id (booted);
}

deployments = ostree_sysroot_get_deployments (ot_sysroot);
for (i=0; i<deployments->len; i++)
{
if (g_strcmp0 (ostree_deployment_get_osname (deployments->pdata[i]), name) == 0)
{
default_variant = rpmostreed_deployment_generate_variant (deployments->pdata[i],
booted_id,
ot_repo, error);
if (default_variant == NULL)
return FALSE;
break;
}
}

booted = ostree_sysroot_get_booted_deployment (ot_sysroot);
if (booted && g_strcmp0 (ostree_deployment_get_osname (booted),
name) == 0)
{
booted_variant = rpmostreed_deployment_generate_variant (booted, ot_repo, error);
if (!booted_variant)
return FALSE;
}

if (deployments->len >= 2)
{
rollback_index = rpmostreed_rollback_deployment_index (name, ot_sysroot, NULL);
if (rollback_index >= 0)
{
rollback_variant = rpmostreed_deployment_generate_variant (deployments->pdata[rollback_index],
rollback_variant = rpmostreed_deployment_generate_variant (deployments->pdata[rollback_index], booted_id,
ot_repo, error);
if (!rollback_variant)
return FALSE;
Expand Down
31 changes: 17 additions & 14 deletions src/daemon/rpmostreed-sysroot.c
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ sysroot_populate_deployments_unlocked (RpmostreedSysroot *self,
{
gboolean ret = FALSE;
OstreeDeployment *booted = NULL; /* owned by sysroot */
g_autofree gchar *booted_id = NULL;
g_autoptr(GPtrArray) deployments = NULL;
g_autoptr(GHashTable) seen_osnames = NULL;
GHashTableIter iter;
Expand All @@ -456,6 +457,21 @@ sysroot_populate_deployments_unlocked (RpmostreedSysroot *self,

seen_osnames = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);

/* Updated booted property */
booted = ostree_sysroot_get_booted_deployment (self->ot_sysroot);
if (booted)
{
const gchar *os = ostree_deployment_get_osname (booted);
g_autofree gchar *path = rpmostreed_generate_object_path (BASE_DBUS_PATH,
os, NULL);
rpmostree_sysroot_set_booted (RPMOSTREE_SYSROOT (self), path);
booted_id = rpmostreed_deployment_generate_id (booted);
}
else
{
rpmostree_sysroot_set_booted (RPMOSTREE_SYSROOT (self), "/");
}

/* Add deployment interfaces */
deployments = ostree_sysroot_get_deployments (self->ot_sysroot);

Expand All @@ -465,7 +481,7 @@ sysroot_populate_deployments_unlocked (RpmostreedSysroot *self,
OstreeDeployment *deployment = deployments->pdata[i];
const char *deployment_os;

variant = rpmostreed_deployment_generate_variant (deployment, self->repo, error);
variant = rpmostreed_deployment_generate_variant (deployment, booted_id, self->repo, error);
if (!variant)
goto out;
g_variant_builder_add_value (&builder, variant);
Expand All @@ -486,19 +502,6 @@ sysroot_populate_deployments_unlocked (RpmostreedSysroot *self,
g_hash_table_add (seen_osnames, (char*)deployment_os);
}

booted = ostree_sysroot_get_booted_deployment (self->ot_sysroot);
if (booted)
{
const gchar *os = ostree_deployment_get_osname (booted);
g_autofree gchar *path = rpmostreed_generate_object_path (BASE_DBUS_PATH,
os, NULL);
rpmostree_sysroot_set_booted (RPMOSTREE_SYSROOT (self), path);
}
else
{
rpmostree_sysroot_set_booted (RPMOSTREE_SYSROOT (self), "/");
}

/* Remove dead os paths */
g_hash_table_iter_init (&iter, self->os_interfaces);
while (g_hash_table_iter_next (&iter, &hashkey, &value))
Expand Down