From 7382eda9dd705f1cc53007fb11ce0740714a5a03 Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Fri, 24 Jun 2016 17:40:46 -0400 Subject: [PATCH 1/2] RPMOSTreeSysroot: add "booted" entry to deployment variant Now that the `status` command learned a `--json` option, we can pretty much avoid parsing human-readable output. The only piece of information that is missing from the JSON output compared to the output for humans is *which* deployment we're currently booted in. This patch fixes that shortcoming by adding a "booted" boolean variant to the deployment variant. --- src/app/rpmostree-builtin-status.c | 11 ++------ src/daemon/org.projectatomic.rpmostree1.xml | 1 + src/daemon/rpmostreed-deployment-utils.c | 4 +++ src/daemon/rpmostreed-deployment-utils.h | 1 + src/daemon/rpmostreed-os.c | 24 ++++++++-------- src/daemon/rpmostreed-sysroot.c | 31 +++++++++++---------- 6 files changed, 38 insertions(+), 34 deletions(-) diff --git a/src/app/rpmostree-builtin-status.c b/src/app/rpmostree-builtin-status.c index 9786d91835..66ceb1dc2f 100644 --- a/src/app/rpmostree-builtin-status.c +++ b/src/app/rpmostree-builtin-status.c @@ -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" : ""; @@ -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) @@ -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) : " "); @@ -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, @@ -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) { @@ -297,7 +291,6 @@ rpmostree_builtin_status (int argc, else { if (!status_generic (sysroot_proxy, os_proxy, deployments, - booted_deployment, cancellable, error)) goto out; } diff --git a/src/daemon/org.projectatomic.rpmostree1.xml b/src/daemon/org.projectatomic.rpmostree1.xml index 88beabf3e3..17b36f7dc6 100644 --- a/src/daemon/org.projectatomic.rpmostree1.xml +++ b/src/daemon/org.projectatomic.rpmostree1.xml @@ -13,6 +13,7 @@ 'origin' (type 's') 'signatures' (type 'av') 'packages' (type 'as') + 'booted' (type 'b') --> diff --git a/src/daemon/rpmostreed-deployment-utils.c b/src/daemon/rpmostreed-deployment-utils.c index e233c266a8..44f481fcc2 100644 --- a/src/daemon/rpmostreed-deployment-utils.c +++ b/src/daemon/rpmostreed-deployment-utils.c @@ -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) { @@ -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); } diff --git a/src/daemon/rpmostreed-deployment-utils.h b/src/daemon/rpmostreed-deployment-utils.h index eeb0324a61..8dbc273c1e 100644 --- a/src/daemon/rpmostreed-deployment-utils.h +++ b/src/daemon/rpmostreed-deployment-utils.h @@ -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); diff --git a/src/daemon/rpmostreed-os.c b/src/daemon/rpmostreed-os.c index 2166211d78..4a2c84c53d 100644 --- a/src/daemon/rpmostreed-os.c +++ b/src/daemon/rpmostreed-os.c @@ -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; @@ -1110,13 +1111,23 @@ 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; ilen; 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; @@ -1124,21 +1135,12 @@ rpmostreed_os_load_internals (RpmostreedOS *self, GError **error) } } - 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; diff --git a/src/daemon/rpmostreed-sysroot.c b/src/daemon/rpmostreed-sysroot.c index 82345e0b27..e0be9f11b7 100644 --- a/src/daemon/rpmostreed-sysroot.c +++ b/src/daemon/rpmostreed-sysroot.c @@ -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; @@ -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); @@ -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); @@ -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)) From 8682d809702d3f79409304d6c600edba3d65472b Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Fri, 24 Jun 2016 22:12:35 -0400 Subject: [PATCH 2/2] fixup! RPMOSTreeSysroot: add "booted" entry to deployment variant --- src/daemon/rpmostreed-os.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/daemon/rpmostreed-os.c b/src/daemon/rpmostreed-os.c index 4a2c84c53d..172d6044d0 100644 --- a/src/daemon/rpmostreed-os.c +++ b/src/daemon/rpmostreed-os.c @@ -1112,12 +1112,11 @@ rpmostreed_os_load_internals (RpmostreedOS *self, GError **error) ot_repo = rpmostreed_sysroot_get_repo (rpmostreed_sysroot_get ()); booted = ostree_sysroot_get_booted_deployment (ot_sysroot); - if (booted && g_strcmp0 (ostree_deployment_get_osname (booted), - name) == 0) + 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; + return FALSE; booted_id = rpmostreed_deployment_generate_id (booted); }