Skip to content

Commit

Permalink
status: Make --booted --json do the expected thing together
Browse files Browse the repository at this point in the history
Unfortunately the implement involves some ugly grubbing through
GVariant...really need to port this stuff to Rust.

Closes: coreos#2829
  • Loading branch information
cgwalters committed Oct 13, 2022
1 parent 88fff5d commit 7a17f2c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
24 changes: 23 additions & 1 deletion src/app/rpmostree-builtin-status.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1213,7 +1213,29 @@ rpmostree_builtin_status (int argc, char **argv, RpmOstreeCommandInvocation *inv
json_builder_begin_object (builder);

json_builder_set_member_name (builder, "deployments");
json_builder_add_value (builder, json_gvariant_serialize (deployments));
g_autoptr (GVariant) deployments_to_list = g_variant_ref (deployments);
if (opt_only_booted)
{
g_autoptr (GVariantBuilder) filtered_deployments
= g_variant_builder_new (g_variant_get_type (deployments));
const guint n = g_variant_n_children (deployments);
for (guint i = 0; i < n; i++)
{
g_autoptr (GVariant) deployment = g_variant_get_child_value (deployments, i);
g_auto (GVariantDict) dict;
g_variant_dict_init (&dict, deployment);
gboolean is_booted = FALSE;
(void)g_variant_dict_lookup (&dict, "booted", "b", &is_booted);
if (is_booted)
{
g_variant_builder_add_value (filtered_deployments, deployment);
}
}
g_variant_unref (deployments_to_list);
deployments_to_list = g_variant_ref (g_variant_builder_end (filtered_deployments));
}

json_builder_add_value (builder, json_gvariant_serialize (deployments_to_list));
json_builder_set_member_name (builder, "transaction");
GVariant *txn = get_active_txn (sysroot_proxy);
JsonNode *txn_node = txn ? json_gvariant_serialize (txn) : json_node_new (JSON_NODE_NULL);
Expand Down
2 changes: 1 addition & 1 deletion tests/kolainst/destructive/apply-live
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ assert_file_has_content out_ap.txt 'pkgsystemd.service'
# that adds content, but doesn't change any packages -
# i.e. there's no package diff. This is a bit of a corner
# case in various bits of the code.
booted_commit=$(rpm-ostree status --json | jq -r '.deployments[0].checksum')
booted_commit=$(rpm-ostree status -b --json | jq -r '.deployments[0].checksum')
ostree refs --create "localref" ${booted_commit}
td=$(mktemp -d)
mkdir -p ${td}/usr/share/localdata
Expand Down
4 changes: 4 additions & 0 deletions tests/kolainst/nondestructive/misc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ assert_jq status.json \
rm status.json
echo "ok empty pkg arrays, and commit meta correct in status json"

rpm-ostree status -b --json > status.json
assert_jq status.json 'deployments|length == 1'
echo "ok --booted --json"

# All tests which require a booted system, but are nondestructive
rpm-ostree testutils integration-read-only

Expand Down

0 comments on commit 7a17f2c

Please sign in to comment.