bstinson / rpms / rpm-ostree

Forked from rpms/rpm-ostree 5 years ago
Clone

Blame SOURCES/0001-rollback-allow-users-to-undo-a-rollback.patch

43e38f
From 6ca072af941cd6f1fd2a094b2daa17219c9adc96 Mon Sep 17 00:00:00 2001
43e38f
From: Jonathan Lebon <jlebon@redhat.com>
43e38f
Date: Thu, 3 Aug 2017 06:41:18 -0700
43e38f
Subject: [PATCH] rollback: allow users to undo a rollback
43e38f
43e38f
The new API to find pending and rollback deployments do so relative to
43e38f
the booted deployment. This caused an interesting behaviour: the first
43e38f
time a user uses "rpm-ostree rollback", it would (as expected) move the
43e38f
previous deployment first. but the second call to "rpm-ostree rollback"
43e38f
would fail since there were now no more rollback deployments.
43e38f
43e38f
We fine tune the logic here to allow this, as well as the more general
43e38f
case of putting the booted deployment back on top.
43e38f
43e38f
This fixes a subtle regression from b7cf58e
43e38f
(https://github.com/projectatomic/rpm-ostree/pull/767).
43e38f
43e38f
Closes: https://github.com/projectatomic/rpm-ostree/issues/906
43e38f
43e38f
Closes: #907
43e38f
Approved by: cgwalters
43e38f
---
43e38f
 src/daemon/rpmostreed-transaction-types.c | 17 ++++++++++++++---
43e38f
 1 file changed, 14 insertions(+), 3 deletions(-)
43e38f
43e38f
diff --git a/src/daemon/rpmostreed-transaction-types.c b/src/daemon/rpmostreed-transaction-types.c
43e38f
index 9f614e4..067adbf 100644
43e38f
--- a/src/daemon/rpmostreed-transaction-types.c
43e38f
+++ b/src/daemon/rpmostreed-transaction-types.c
43e38f
@@ -322,11 +322,22 @@ rollback_transaction_execute (RpmostreedTransaction *transaction,
43e38f
 {
43e38f
   RollbackTransaction *self = (RollbackTransaction *) transaction;
43e38f
   OstreeSysroot *sysroot = rpmostreed_transaction_get_sysroot (transaction);
43e38f
+  OstreeDeployment *booted_deployment = ostree_sysroot_get_booted_deployment (sysroot);
43e38f
 
43e38f
+  g_autoptr(OstreeDeployment) pending_deployment = NULL;
43e38f
   g_autoptr(OstreeDeployment) rollback_deployment = NULL;
43e38f
-  rpmostree_syscore_query_deployments (sysroot, self->osname, NULL, &rollback_deployment);
43e38f
-  if (!rollback_deployment)
43e38f
+  rpmostree_syscore_query_deployments (sysroot, self->osname,
43e38f
+                                       &pending_deployment, &rollback_deployment);
43e38f
+
43e38f
+  if (!rollback_deployment && !pending_deployment) /* i.e. do we just have 1 deployment? */
43e38f
     return glnx_throw (error, "No rollback deployment found");
43e38f
+  else if (!rollback_deployment)
43e38f
+    {
43e38f
+      /* If there isn't a rollback deployment, but there *is* a pending deployment, then we
43e38f
+       * want "rpm-ostree rollback" to put the currently booted deployment back on top. This
43e38f
+       * also allows users to effectively undo a rollback operation. */
43e38f
+      rollback_deployment = g_object_ref (booted_deployment);
43e38f
+    }
43e38f
 
43e38f
   g_autoptr(GPtrArray) old_deployments =
43e38f
     ostree_sysroot_get_deployments (sysroot);
43e38f
@@ -344,7 +355,7 @@ rollback_transaction_execute (RpmostreedTransaction *transaction,
43e38f
   for (guint i = 0; i < old_deployments->len; i++)
43e38f
     {
43e38f
       OstreeDeployment *deployment = old_deployments->pdata[i];
43e38f
-      if (deployment != rollback_deployment)
43e38f
+      if (!ostree_deployment_equal (deployment, rollback_deployment))
43e38f
         g_ptr_array_add (new_deployments, g_object_ref (deployment));
43e38f
     }
43e38f
 
43e38f
-- 
43e38f
2.14.0
43e38f