daemon: Reimplement ClearRollbackTarget in terms of cleanup txn

I didn't realize we had this dbus method.  It was added in the initial
drop of the DBus API, and AFAICS nothing uses it; it's not exposed
via the cmdline, and a quick `git grep` in Cockpit shows it's
not used there either.

It's tempting to delete it.

However, before we take that step, let's reimplement it in terms of the new,
shiny, more powerful "cleanup" txn.

The particular reason I'm doing this is I want to change how we handle
rollbacks.

Closes: #767
Approved by: jlebon
This commit is contained in:
Colin Walters 2017-05-07 08:23:24 -04:00 committed by Atomic Bot
parent e7a16c561b
commit 3f3090ee7e
2 changed files with 10 additions and 140 deletions

View File

@ -703,6 +703,7 @@ out:
return TRUE;
}
/* This is an older variant of Cleanup, kept for backcompat */
static gboolean
os_handle_clear_rollback_target (RPMOSTreeOS *interface,
GDBusMethodInvocation *invocation,
@ -712,9 +713,8 @@ os_handle_clear_rollback_target (RPMOSTreeOS *interface,
glnx_unref_object RpmostreedTransaction *transaction = NULL;
glnx_unref_object OstreeSysroot *ot_sysroot = NULL;
g_autoptr(GCancellable) cancellable = g_cancellable_new ();
RpmOstreeTransactionCleanupFlags flags = 0;
const char *osname;
gboolean opt_reboot = FALSE;
GVariantDict options_dict;
GError *local_error = NULL;
transaction = merge_compatible_txn (self, invocation);
@ -722,29 +722,19 @@ os_handle_clear_rollback_target (RPMOSTreeOS *interface,
goto out;
if (!rpmostreed_sysroot_load_state (rpmostreed_sysroot_get (),
cancellable,
&ot_sysroot,
NULL,
&local_error))
cancellable, &ot_sysroot, NULL, &local_error))
goto out;
g_variant_dict_init (&options_dict, arg_options);
g_variant_dict_lookup (&options_dict,
"reboot", "b",
&opt_reboot);
g_variant_dict_clear (&options_dict);
osname = rpmostree_os_get_name (interface);
transaction = rpmostreed_transaction_new_clear_rollback (invocation,
ot_sysroot,
osname,
opt_reboot,
cancellable,
&local_error);
/* Note - intentionally ignoring the reboot option since I don't
* know why anyone would want that.
*/
flags = RPMOSTREE_TRANSACTION_CLEANUP_ROLLBACK_DEPLOY;
transaction = rpmostreed_transaction_new_cleanup (invocation, ot_sysroot,
osname, flags,
cancellable, &local_error);
if (transaction == NULL)
goto out;
@ -761,7 +751,6 @@ out:
client_address = rpmostreed_transaction_get_client_address (transaction);
rpmostree_os_complete_clear_rollback_target (interface, invocation, client_address);
}
return TRUE;
}

View File

@ -446,125 +446,6 @@ rpmostreed_transaction_new_rollback (GDBusMethodInvocation *invocation,
return (RpmostreedTransaction *) self;
}
/* ============================ Clear Rollback ============================ */
typedef struct {
RpmostreedTransaction parent;
char *osname;
gboolean reboot;
} ClearRollbackTransaction;
typedef RpmostreedTransactionClass ClearRollbackTransactionClass;
GType clear_rollback_transaction_get_type (void);
G_DEFINE_TYPE (ClearRollbackTransaction,
clear_rollback_transaction,
RPMOSTREED_TYPE_TRANSACTION)
static void
clear_rollback_transaction_finalize (GObject *object)
{
ClearRollbackTransaction *self;
self = (ClearRollbackTransaction *) object;
g_free (self->osname);
G_OBJECT_CLASS (clear_rollback_transaction_parent_class)->finalize (object);
}
static gboolean
clear_rollback_transaction_execute (RpmostreedTransaction *transaction,
GCancellable *cancellable,
GError **error)
{
ClearRollbackTransaction *self;
OstreeSysroot *sysroot;
g_autoptr(GPtrArray) deployments = NULL;
gint rollback_index;
gboolean ret = FALSE;
self = (ClearRollbackTransaction *) transaction;
sysroot = rpmostreed_transaction_get_sysroot (transaction);
rollback_index = rpmostreed_rollback_deployment_index (self->osname, sysroot, error);
if (rollback_index < 0)
goto out;
deployments = ostree_sysroot_get_deployments (sysroot);
if (deployments->pdata[rollback_index] == ostree_sysroot_get_booted_deployment (sysroot))
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
"Cannot undeploy currently booted deployment %i",
rollback_index);
goto out;
}
g_ptr_array_remove_index (deployments, rollback_index);
if (!ostree_sysroot_write_deployments (sysroot,
deployments,
cancellable,
error))
goto out;
if (self->reboot)
rpmostreed_reboot (cancellable, error);
ret = TRUE;
out:
return ret;
}
static void
clear_rollback_transaction_class_init (ClearRollbackTransactionClass *class)
{
GObjectClass *object_class;
object_class = G_OBJECT_CLASS (class);
object_class->finalize = clear_rollback_transaction_finalize;
class->execute = clear_rollback_transaction_execute;
}
static void
clear_rollback_transaction_init (ClearRollbackTransaction *self)
{
}
RpmostreedTransaction *
rpmostreed_transaction_new_clear_rollback (GDBusMethodInvocation *invocation,
OstreeSysroot *sysroot,
const char *osname,
gboolean reboot,
GCancellable *cancellable,
GError **error)
{
ClearRollbackTransaction *self;
g_return_val_if_fail (G_IS_DBUS_METHOD_INVOCATION (invocation), NULL);
g_return_val_if_fail (OSTREE_IS_SYSROOT (sysroot), NULL);
g_return_val_if_fail (osname != NULL, NULL);
self = g_initable_new (clear_rollback_transaction_get_type (),
cancellable, error,
"invocation", invocation,
"sysroot-path", gs_file_get_path_cached (ostree_sysroot_get_path (sysroot)),
NULL);
if (self != NULL)
{
self->osname = g_strdup (osname);
self->reboot = reboot;
}
return (RpmostreedTransaction *) self;
}
/* ================================ Upgrade/Deploy/Rebase ================================ */
typedef struct {