app/db-diff: Diff against rollback if no pending

Often, after rebooting from an upgrade, I want to check what was just
updated. This patch makes `db diff` do the right thing in those cases.
Specifically, before `db diff` without arguments would default to
diff'ing the pending deployment with the booted deployment and error out
otherwise. This patch extends the logic so that if there's a rollback
deployment, we default to diff'ing against that.

Closes: #1565
Approved by: cgwalters
This commit is contained in:
Jonathan Lebon 2018-09-19 16:48:58 -04:00 committed by Atomic Bot
parent e76c057b0c
commit ea5bec6127
2 changed files with 19 additions and 3 deletions

View File

@ -176,9 +176,10 @@ rpmostree_db_builtin_diff (int argc, char **argv,
if (argc < 2)
{
/* diff booted against pending deployment */
/* diff booted against pending or rollback deployment */
g_autoptr(OstreeDeployment) pending = NULL;
ostree_sysroot_query_deployments_for (sysroot, NULL, &pending, NULL);
g_autoptr(OstreeDeployment) rollback = NULL;
ostree_sysroot_query_deployments_for (sysroot, NULL, &pending, &rollback);
if (pending)
{
return print_deployment_diff (repo,
@ -186,7 +187,14 @@ rpmostree_db_builtin_diff (int argc, char **argv,
"pending deployment", pending,
cancellable, error);
}
return glnx_throw (error, "No pending deployment to diff against");
if (rollback)
{
return print_deployment_diff (repo,
"rollback deployment", rollback,
"booted deployment", booted,
cancellable, error);
}
return glnx_throw (error, "No pending or rollback deployment to diff against");
}
else
{

View File

@ -137,8 +137,16 @@ vm_rpmostree install foo-1.0 --unchanged-exit-77 > foo-install.txt
assert_file_has_content_literal foo-install.txt 'Checking out packages (1/1) 100%'
echo "ok install not on a tty"
# check that by default we diff booted vs pending
vm_rpmostree db diff --format=diff > out.txt
assert_file_has_content out.txt +foo-1.0
vm_reboot
# and check that now by default we diff rollback vs booted
vm_rpmostree db diff --format=diff > out.txt
assert_file_has_content out.txt +foo-1.0
# Test `rpm-ostree status --pending-exit-77`, with no actual pending deployment
rc=0
vm_rpmostree status --pending-exit-77 || rc=$?