Skip to content

Commit

Permalink
gs-plugin-apk: adapt to new async add updates API
Browse files Browse the repository at this point in the history
Nothing remarkable here
  • Loading branch information
pabloyoyoista committed Aug 30, 2024
1 parent 7b626bc commit 11ab699
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 61 deletions.
129 changes: 71 additions & 58 deletions src/gs-plugin-apk/gs-plugin-apk.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,53 +306,6 @@ apk_polkit_update_repositories_cb (GObject *source_object,
g_task_return_boolean (task, TRUE);
}

gboolean
gs_plugin_add_updates (GsPlugin *plugin,
GsAppList *list,
GCancellable *cancellable,
GError **error)
{
GsPluginApk *self = GS_PLUGIN_APK (plugin);
g_autoptr (GVariant) upgradable_packages = NULL;
g_autoptr (GError) local_error = NULL;

/* I believe we have to invalidate the cache here! */
g_debug ("Adding updates");

if (!apk_polkit2_call_list_upgradable_packages_sync (self->proxy,
APK_POLKIT_CLIENT_DETAILS_FLAGS_ALL,
&upgradable_packages,
cancellable,
&local_error))
{
g_dbus_error_strip_remote_error (local_error);
g_propagate_error (error, g_steal_pointer (&local_error));
return FALSE;
}

g_debug ("Found %" G_GSIZE_FORMAT " upgradable packages",
g_variant_n_children (upgradable_packages));

for (gsize i = 0; i < g_variant_n_children (upgradable_packages); i++)
{
g_autoptr (GVariant) dict = NULL;
GsApp *app;
ApkdPackage pkg = { NULL, NULL, NULL, NULL, NULL, NULL, 0, 0, Available };

dict = g_variant_get_child_value (upgradable_packages, i);
/* list_upgradable_packages doesn't have array input, thus no error output */
if (!gs_plugin_apk_variant_to_apkd (dict, &pkg))
g_assert_not_reached ();
if (pkg.packageState == Upgradable || pkg.packageState == Downgradable)
{
app = apk_package_to_app (plugin, &pkg);
gs_app_list_add (list, app);
}
}

return TRUE;
}

gboolean
gs_plugin_app_install (GsPlugin *plugin,
GsApp *app,
Expand Down Expand Up @@ -1114,8 +1067,8 @@ gs_plugin_apk_launch_async (GsPlugin *plugin,

static GsAppList *
gs_plugin_apk_list_apps_finish (GsPlugin *plugin,
GAsyncResult *result,
GError **error)
GAsyncResult *result,
GError **error)
{
return g_task_propagate_pointer (G_TASK (result), error);
}
Expand All @@ -1125,13 +1078,18 @@ apk_polkit_list_repositories_cb (GObject *object_source,
GAsyncResult *res,
gpointer user_data);

static void
apk_polkit_list_upgradable_cb (GObject *object_source,
GAsyncResult *res,
gpointer user_data);

static void
gs_plugin_apk_list_apps_async (GsPlugin *plugin,
GsAppQuery *query,
GsPluginListAppsFlags flags,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
GsAppQuery *query,
GsPluginListAppsFlags flags,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
GsPluginApk *self = GS_PLUGIN_APK (plugin);
g_autoptr (GTask) task = NULL;
Expand All @@ -1146,13 +1104,67 @@ gs_plugin_apk_list_apps_async (GsPlugin *plugin,
apk_polkit_list_repositories_cb,
g_steal_pointer (&task));
}
else if (gs_app_query_get_is_for_update (query) == GS_APP_QUERY_TRISTATE_TRUE)
{
/* I believe we have to invalidate the cache here! */
g_debug ("Adding updates");
apk_polkit2_call_list_upgradable_packages (self->proxy,
APK_POLKIT_CLIENT_DETAILS_FLAGS_ALL,
cancellable,
apk_polkit_list_upgradable_cb,
g_steal_pointer (&task));
}
else
{
g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
"Unsupported query");
}
}

static void
apk_polkit_list_upgradable_cb (GObject *object_source,
GAsyncResult *res,
gpointer user_data)
{
g_autoptr (GTask) task = G_TASK (g_steal_pointer (&user_data));
GsPluginApk *self = g_task_get_source_object (task);
g_autoptr (GVariant) upgradable_packages = NULL;
g_autoptr (GError) local_error = NULL;
g_autoptr (GsAppList) list = NULL;

if (!apk_polkit2_call_list_upgradable_packages_finish (self->proxy,
&upgradable_packages,
res,
&local_error))
{
g_dbus_error_strip_remote_error (local_error);
g_task_return_error (task, g_steal_pointer (&local_error));
return;
}

g_debug ("Found %" G_GSIZE_FORMAT " upgradable packages",
g_variant_n_children (upgradable_packages));

for (gsize i = 0; i < g_variant_n_children (upgradable_packages); i++)
{
g_autoptr (GVariant) dict = NULL;
GsApp *app;
ApkdPackage pkg = { NULL, NULL, NULL, NULL, NULL, NULL, 0, 0, Available };

dict = g_variant_get_child_value (upgradable_packages, i);
/* list_upgradable_packages doesn't have array input, thus no error output */
if (!gs_plugin_apk_variant_to_apkd (dict, &pkg))
g_assert_not_reached ();
if (pkg.packageState == Upgradable || pkg.packageState == Downgradable)
{
app = apk_package_to_app (GS_PLUGIN (self), &pkg);
gs_app_list_add (list, app);
}
}

g_task_return_pointer (task, g_steal_pointer (&list), g_object_unref);
}

static void
apk_polkit_list_repositories_cb (GObject *object_source,
GAsyncResult *res,
Expand Down Expand Up @@ -1199,10 +1211,11 @@ apk_polkit_list_repositories_cb (GObject *object_source,

g_uri_split (url, G_URI_FLAGS_NONE, &url_scheme, NULL,
NULL, NULL, &url_path, NULL, NULL, &local_error);
if (local_error) {
g_task_return_error (task, g_steal_pointer (&local_error));
return;
}
if (local_error)
{
g_task_return_error (task, g_steal_pointer (&local_error));
return;
}

/* Transform /some/repo/url into some.repo.url
We are not allowed to use '/' in the app id. */
Expand Down
8 changes: 5 additions & 3 deletions tests/gs-self-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ gs_plugins_apk_updates (GsPluginLoader *plugin_loader)
// updates.
// * Execute update: Verify packages are updated? Needs Mock improvements!
g_autoptr (GError) error = NULL;
g_autoptr (GsAppQuery) query = NULL;
g_autoptr (GsPluginJob) plugin_job = NULL;
GsApp *generic_app = NULL;
GsApp *desktop_app = NULL;
Expand All @@ -117,9 +118,10 @@ gs_plugins_apk_updates (GsPluginLoader *plugin_loader)
GsAppList *related = NULL;

// List updates
plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_GET_UPDATES,
"refine-flags", GS_PLUGIN_REFINE_FLAGS_REQUIRE_UPDATE_DETAILS,
NULL);
query = gs_app_query_new ("is-for-update", GS_APP_QUERY_TRISTATE_TRUE,
"refine-flags", GS_PLUGIN_REFINE_FLAGS_REQUIRE_UPDATE_DETAILS,
NULL);
plugin_job = gs_plugin_job_list_apps_new (query, GS_PLUGIN_LIST_APPS_FLAGS_NONE);
update_list = gs_plugin_loader_job_process (plugin_loader, plugin_job, NULL, &error);
gs_test_flush_main_context ();
g_assert_no_error (error);
Expand Down

0 comments on commit 11ab699

Please sign in to comment.