Skip to content

Commit

Permalink
gs-plugin-apk: make sure the list-apps query is always valid
Browse files Browse the repository at this point in the history
This is a pattern taken from upstream
  • Loading branch information
pabloyoyoista committed Aug 30, 2024
1 parent 11ab699 commit ca73722
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions src/gs-plugin-apk/gs-plugin-apk.c
Original file line number Diff line number Diff line change
Expand Up @@ -1093,18 +1093,41 @@ gs_plugin_apk_list_apps_async (GsPlugin *plugin,
{
GsPluginApk *self = GS_PLUGIN_APK (plugin);
g_autoptr (GTask) task = NULL;
gboolean is_source, is_for_updates;

task = g_task_new (plugin, cancellable, callback, user_data);
g_task_set_source_tag (task, gs_plugin_apk_list_apps_async);

if (gs_app_query_get_is_source (query) == GS_APP_QUERY_TRISTATE_TRUE)
if (query == NULL)
{
g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
"Unsupported query");
return;
}

is_source = gs_app_query_get_is_source (query);
is_for_updates = gs_app_query_get_is_for_update (query);

/* Currently only support a subset of query properties, and only one set at once.
* This is a pattern taken from upstream!
*/
if (is_source == is_for_updates ||
is_source == GS_APP_QUERY_TRISTATE_FALSE ||
is_for_updates == GS_APP_QUERY_TRISTATE_FALSE ||)
{
g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
"Unsupported query");
return;
}

if (is_source == GS_APP_QUERY_TRISTATE_TRUE)
{
g_debug ("Adding repositories");
apk_polkit2_call_list_repositories (self->proxy, cancellable,
apk_polkit_list_repositories_cb,
g_steal_pointer (&task));
}
else if (gs_app_query_get_is_for_update (query) == GS_APP_QUERY_TRISTATE_TRUE)
else if (is_for_updates == GS_APP_QUERY_TRISTATE_TRUE)
{
/* I believe we have to invalidate the cache here! */
g_debug ("Adding updates");
Expand All @@ -1116,8 +1139,7 @@ gs_plugin_apk_list_apps_async (GsPlugin *plugin,
}
else
{
g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
"Unsupported query");
g_assert_not_reached ();
}
}

Expand Down

0 comments on commit ca73722

Please sign in to comment.