rollback: allow users to undo a rollback

The new API to find pending and rollback deployments do so relative to
the booted deployment. This caused an interesting behaviour: the first
time a user uses "rpm-ostree rollback", it would (as expected) move the
previous deployment first. but the second call to "rpm-ostree rollback"
would fail since there were now no more rollback deployments.

We fine tune the logic here to allow this, as well as the more general
case of putting the booted deployment back on top.

This fixes a subtle regression from b7cf58e
(https://github.com/projectatomic/rpm-ostree/pull/767).

Closes: https://github.com/projectatomic/rpm-ostree/issues/906

Closes: #907
Approved by: cgwalters
This commit is contained in:
Jonathan Lebon 2017-08-03 06:41:18 -07:00 committed by Atomic Bot
parent d9c1e4a5d3
commit dc24dd3105
2 changed files with 24 additions and 3 deletions

View File

@ -326,11 +326,22 @@ rollback_transaction_execute (RpmostreedTransaction *transaction,
{ {
RollbackTransaction *self = (RollbackTransaction *) transaction; RollbackTransaction *self = (RollbackTransaction *) transaction;
OstreeSysroot *sysroot = rpmostreed_transaction_get_sysroot (transaction); OstreeSysroot *sysroot = rpmostreed_transaction_get_sysroot (transaction);
OstreeDeployment *booted_deployment = ostree_sysroot_get_booted_deployment (sysroot);
g_autoptr(OstreeDeployment) pending_deployment = NULL;
g_autoptr(OstreeDeployment) rollback_deployment = NULL; g_autoptr(OstreeDeployment) rollback_deployment = NULL;
ostree_sysroot_query_deployments_for (sysroot, self->osname, NULL, &rollback_deployment); ostree_sysroot_query_deployments_for (sysroot, self->osname,
if (!rollback_deployment) &pending_deployment, &rollback_deployment);
if (!rollback_deployment && !pending_deployment) /* i.e. do we just have 1 deployment? */
return glnx_throw (error, "No rollback deployment found"); return glnx_throw (error, "No rollback deployment found");
else if (!rollback_deployment)
{
/* If there isn't a rollback deployment, but there *is* a pending deployment, then we
* want "rpm-ostree rollback" to put the currently booted deployment back on top. This
* also allows users to effectively undo a rollback operation. */
rollback_deployment = g_object_ref (booted_deployment);
}
g_autoptr(GPtrArray) old_deployments = g_autoptr(GPtrArray) old_deployments =
ostree_sysroot_get_deployments (sysroot); ostree_sysroot_get_deployments (sysroot);
@ -348,7 +359,7 @@ rollback_transaction_execute (RpmostreedTransaction *transaction,
for (guint i = 0; i < old_deployments->len; i++) for (guint i = 0; i < old_deployments->len; i++)
{ {
OstreeDeployment *deployment = old_deployments->pdata[i]; OstreeDeployment *deployment = old_deployments->pdata[i];
if (deployment != rollback_deployment) if (!ostree_deployment_equal (deployment, rollback_deployment))
g_ptr_array_add (new_deployments, g_object_ref (deployment)); g_ptr_array_add (new_deployments, g_object_ref (deployment));
} }

View File

@ -73,3 +73,13 @@ vm_build_rpm foo
vm_rpmostree install foo vm_rpmostree install foo
vm_assert_status_jq ".deployments[0][\"endoflife\"] == \"${META_ENDOFLIFE_MESSAGE}\"" vm_assert_status_jq ".deployments[0][\"endoflife\"] == \"${META_ENDOFLIFE_MESSAGE}\""
echo "ok layered commit inherits the endoflife attribute" echo "ok layered commit inherits the endoflife attribute"
vm_assert_status_jq ".deployments[0][\"booted\"] == false" \
".deployments[1][\"booted\"] == true"
vm_rpmostree rollback
vm_assert_status_jq ".deployments[0][\"booted\"] == true" \
".deployments[1][\"booted\"] == false"
vm_rpmostree rollback
vm_assert_status_jq ".deployments[0][\"booted\"] == false" \
".deployments[1][\"booted\"] == true"
echo "ok rollback"