[gnome-software/wip/async-plugin-repo-funcs: 34/37] packagekit: Implement repository disable as an async operation
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/wip/async-plugin-repo-funcs: 34/37] packagekit: Implement repository disable as an async operation
- Date: Thu, 16 Jun 2022 13:51:22 +0000 (UTC)
commit fab2f7f09295b91b86e55f52d39115b725ae044e
Author: Milan Crha <mcrha redhat com>
Date: Tue Jun 14 18:50:29 2022 +0200
packagekit: Implement repository disable as an async operation
plugins/packagekit/gs-plugin-packagekit.c | 111 ++++++++++++++++++++----------
1 file changed, 74 insertions(+), 37 deletions(-)
---
diff --git a/plugins/packagekit/gs-plugin-packagekit.c b/plugins/packagekit/gs-plugin-packagekit.c
index 9a435b475..78ee22ed2 100644
--- a/plugins/packagekit/gs-plugin-packagekit.c
+++ b/plugins/packagekit/gs-plugin-packagekit.c
@@ -3513,56 +3513,91 @@ gs_plugin_packagekit_enable_repository_finish (GsPlugin *plugin,
return g_task_propagate_boolean (G_TASK (result), error);
}
-gboolean
-gs_plugin_disable_repo (GsPlugin *plugin,
- GsApp *repo,
- GCancellable *cancellable,
- GError **error)
+static void
+gs_plugin_packagekit_disable_repository_ready_cb (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
{
- g_autoptr(GsPackagekitHelper) helper = gs_packagekit_helper_new (plugin);
- g_autoptr(PkTask) task_disable_repo = NULL;
+ g_autoptr(GTask) task = user_data;
g_autoptr(PkResults) results = NULL;
g_autoptr(PkError) error_code = NULL;
+ g_autoptr(GError) local_error = NULL;
+ GsPluginPackagekit *self = GS_PLUGIN_PACKAGEKIT (g_task_get_source_object (task));
+ GsPluginManageRepositoryData *data = g_task_get_task_data (task);
- /* only process this app if was created by this plugin */
- if (!gs_app_has_management_plugin (repo, plugin))
- return TRUE;
-
- /* is repo */
- g_return_val_if_fail (gs_app_get_kind (repo) == AS_COMPONENT_KIND_REPOSITORY, FALSE);
-
- /* do sync call */
- gs_plugin_status_update (plugin, repo, GS_PLUGIN_STATUS_WAITING);
- gs_app_set_state (repo, GS_APP_STATE_REMOVING);
- gs_packagekit_helper_add_app (helper, repo);
-
- task_disable_repo = gs_packagekit_task_new (plugin);
- gs_packagekit_task_setup (GS_PACKAGEKIT_TASK (task_disable_repo), GS_PLUGIN_ACTION_DISABLE_REPO,
gs_plugin_has_flags (plugin, GS_PLUGIN_FLAGS_INTERACTIVE));
-
- results = pk_client_repo_enable (PK_CLIENT (task_disable_repo),
- gs_app_get_id (repo),
- FALSE,
- cancellable,
- gs_packagekit_helper_cb, helper,
- error);
+ results = pk_client_generic_finish (PK_CLIENT (source_object), result, &local_error);
- /* pk_client_repo_enable() returns an error if the repo is already enabled. */
+ /* pk_client_repo_enable() returns an error if the repo is already disabled. */
if (results != NULL &&
(error_code = pk_results_get_error_code (results)) != NULL &&
pk_error_get_code (error_code) == PK_ERROR_ENUM_REPO_ALREADY_SET) {
- g_clear_error (error);
- } else if (!gs_plugin_packagekit_results_valid (results, error)) {
- gs_app_set_state_recover (repo);
- gs_utils_error_add_origin_id (error, repo);
- return FALSE;
+ g_clear_error (&local_error);
+ } else if (local_error != NULL || !gs_plugin_packagekit_results_valid (results, &local_error)) {
+ gs_app_set_state_recover (data->repository);
+ gs_utils_error_add_origin_id (&local_error, data->repository);
+ g_task_return_error (task, g_steal_pointer (&local_error));
+ return;
}
/* state is known */
- gs_app_set_state (repo, GS_APP_STATE_AVAILABLE);
+ gs_app_set_state (data->repository, GS_APP_STATE_AVAILABLE);
- gs_plugin_repository_changed (plugin, repo);
+ gs_plugin_repository_changed (GS_PLUGIN (self), data->repository);
- return TRUE;
+ g_task_return_boolean (task, TRUE);
+}
+
+static void
+gs_plugin_packagekit_disable_repository_async (GsPlugin *plugin,
+ GsApp *repository,
+ GsPluginManageRepositoryFlags flags,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ g_autoptr(GsPackagekitHelper) helper = NULL;
+ g_autoptr(PkTask) task_disable_repo = NULL;
+ g_autoptr(GTask) task = NULL;
+
+ task = gs_plugin_manage_repository_data_new_task (plugin, repository, flags, cancellable, callback,
user_data);
+ g_task_set_source_tag (task, gs_plugin_packagekit_disable_repository_async);
+
+ /* only process this app if was created by this plugin */
+ if (!gs_app_has_management_plugin (repository, plugin)) {
+ g_task_return_boolean (task, TRUE);
+ return;
+ }
+
+ /* is repo */
+ g_assert (gs_app_get_kind (repository) == AS_COMPONENT_KIND_REPOSITORY);
+
+ /* do the call */
+ gs_plugin_status_update (plugin, repository, GS_PLUGIN_STATUS_WAITING);
+ gs_app_set_state (repository, GS_APP_STATE_REMOVING);
+
+ helper = gs_packagekit_helper_new (plugin);
+ gs_packagekit_helper_add_app (helper, repository);
+
+ task_disable_repo = gs_packagekit_task_new (plugin);
+ gs_packagekit_task_setup (GS_PACKAGEKIT_TASK (task_disable_repo), GS_PLUGIN_ACTION_DISABLE_REPO,
+ (flags & GS_PLUGIN_MANAGE_REPOSITORY_FLAGS_INTERACTIVE) != 0);
+ gs_packagekit_task_take_helper (GS_PACKAGEKIT_TASK (task_disable_repo), helper);
+
+ pk_client_repo_enable_async (PK_CLIENT (task_disable_repo),
+ gs_app_get_id (repository),
+ FALSE,
+ cancellable,
+ gs_packagekit_helper_cb, g_steal_pointer (&helper),
+ gs_plugin_packagekit_disable_repository_ready_cb,
+ g_steal_pointer (&task));
+}
+
+static gboolean
+gs_plugin_packagekit_disable_repository_finish (GsPlugin *plugin,
+ GAsyncResult *result,
+ GError **error)
+{
+ return g_task_propagate_boolean (G_TASK (result), error);
}
static gboolean
@@ -4028,6 +4063,8 @@ gs_plugin_packagekit_class_init (GsPluginPackagekitClass *klass)
plugin_class->list_apps_finish = gs_plugin_packagekit_list_apps_finish;
plugin_class->enable_repository_async = gs_plugin_packagekit_enable_repository_async;
plugin_class->enable_repository_finish = gs_plugin_packagekit_enable_repository_finish;
+ plugin_class->disable_repository_async = gs_plugin_packagekit_disable_repository_async;
+ plugin_class->disable_repository_finish = gs_plugin_packagekit_disable_repository_finish;
}
GType
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]