[gnome-software] Fix a critical warning in the shell search provider
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Fix a critical warning in the shell search provider
- Date: Sat, 22 Apr 2017 08:12:30 +0000 (UTC)
commit 629cb4ffd7b891ff5abc519de768895ee5748e28
Author: Richard Hughes <richard hughsie com>
Date: Fri Apr 21 13:24:12 2017 +0100
Fix a critical warning in the shell search provider
Using the desktop ID (rather than the unique) ID as the cache key could
potentially match different GsApp objects depending on the order they are
returned from the plugin loader.
Also, get the GsApp from the unique-id using the global cache rather than
trying to recreate it using refine -- this may be the source of a different
bug where two different GsApps had the same unique ID in the cache.
lib/gs-plugin-loader-sync.c | 19 -------------------
lib/gs-plugin-loader-sync.h | 5 -----
src/gs-search-page.c | 7 ++++++-
src/gs-shell-search-provider.c | 31 ++++++++++++++-----------------
4 files changed, 20 insertions(+), 42 deletions(-)
---
diff --git a/lib/gs-plugin-loader-sync.c b/lib/gs-plugin-loader-sync.c
index cabc784..d442aab 100644
--- a/lib/gs-plugin-loader-sync.c
+++ b/lib/gs-plugin-loader-sync.c
@@ -23,25 +23,6 @@
#include "gs-plugin-loader-sync.h"
-GsApp *
-gs_plugin_loader_get_app_by_id (GsPluginLoader *plugin_loader,
- const gchar *id,
- GsPluginRefineFlags refine_flags,
- GCancellable *cancellable,
- GError **error)
-{
- GsApp *app;
- gboolean ret;
-
- app = gs_app_new (id);
- ret = gs_plugin_loader_app_refine (plugin_loader, app, refine_flags,
- GS_PLUGIN_FAILURE_FLAGS_NONE,
- cancellable, error);
- if (!ret)
- g_clear_object (&app);
- return app;
-}
-
/* tiny helper to help us do the async operation */
typedef struct {
GError **error;
diff --git a/lib/gs-plugin-loader-sync.h b/lib/gs-plugin-loader-sync.h
index a97e8eb..e6216ea 100644
--- a/lib/gs-plugin-loader-sync.h
+++ b/lib/gs-plugin-loader-sync.h
@@ -107,11 +107,6 @@ gboolean gs_plugin_loader_refresh (GsPluginLoader *plugin_loader,
GsPluginFailureFlags failure_flags,
GCancellable *cancellable,
GError **error);
-GsApp *gs_plugin_loader_get_app_by_id (GsPluginLoader *plugin_loader,
- const gchar *id,
- GsPluginRefineFlags refine_flags,
- GCancellable *cancellable,
- GError **error);
GsApp *gs_plugin_loader_file_to_app (GsPluginLoader *plugin_loader,
GFile *file,
GsPluginRefineFlags refine_flags,
diff --git a/src/gs-search-page.c b/src/gs-search-page.c
index 469b904..b3af0e3 100644
--- a/src/gs-search-page.c
+++ b/src/gs-search-page.c
@@ -176,7 +176,12 @@ gs_search_page_get_search_cb (GObject *source_object,
if (self->appid_to_show != NULL) {
g_autoptr (GsApp) a = NULL;
- a = gs_app_new (self->appid_to_show);
+ if (as_utils_unique_id_valid (self->appid_to_show)) {
+ a = gs_plugin_loader_app_create (self->plugin_loader,
+ self->appid_to_show);
+ } else {
+ a = gs_app_new (self->appid_to_show);
+ }
gs_shell_show_app (self->shell, a);
g_clear_pointer (&self->appid_to_show, g_free);
}
diff --git a/src/gs-shell-search-provider.c b/src/gs-shell-search-provider.c
index 6a31a12..ebff5c9 100644
--- a/src/gs-shell-search-provider.c
+++ b/src/gs-shell-search-provider.c
@@ -95,7 +95,7 @@ search_done_cb (GObject *source,
GsApp *app = gs_app_list_index (list, i);
if (gs_app_get_state (app) != AS_APP_STATE_AVAILABLE)
continue;
- g_variant_builder_add (&builder, "s", gs_app_get_id (app));
+ g_variant_builder_add (&builder, "s", gs_app_get_unique_id (app));
}
g_dbus_method_invocation_return_value (search->invocation, g_variant_new ("(as)", &builder));
@@ -180,39 +180,34 @@ handle_get_result_metas (GsShellSearchProvider2 *skeleton,
GdkPixbuf *pixbuf;
gint i;
GVariantBuilder builder;
- GError *error = NULL;
g_debug ("****** GetResultMetas");
for (i = 0; results[i]; i++) {
g_autoptr(GsApp) app = NULL;
- if (g_hash_table_lookup (self->metas_cache, results[i]))
+ /* already built */
+ if (g_hash_table_lookup (self->metas_cache, results[i]) != NULL)
continue;
/* find the application with this ID */
- app = gs_plugin_loader_get_app_by_id (self->plugin_loader,
- results[i],
- GS_PLUGIN_REFINE_FLAGS_REQUIRE_ICON |
- GS_PLUGIN_REFINE_FLAGS_REQUIRE_DESCRIPTION,
- NULL,
- &error);
- if (app == NULL) {
- g_warning ("failed to refine %s: %s",
- results[i], error->message);
- g_clear_error (&error);
+ app = gs_plugin_loader_app_create (self->plugin_loader, results[i]);
+ if (gs_app_get_summary (app) == NULL) {
+ g_warning ("failed to refine find app %s in global cache", results[i]);
continue;
}
g_variant_builder_init (&meta, G_VARIANT_TYPE ("a{sv}"));
- g_variant_builder_add (&meta, "{sv}", "id", g_variant_new_string (gs_app_get_id (app)));
+ g_variant_builder_add (&meta, "{sv}", "id", g_variant_new_string (gs_app_get_unique_id
(app)));
g_variant_builder_add (&meta, "{sv}", "name", g_variant_new_string (gs_app_get_name (app)));
pixbuf = gs_app_get_pixbuf (app);
if (pixbuf != NULL)
g_variant_builder_add (&meta, "{sv}", "icon", g_icon_serialize (G_ICON (pixbuf)));
g_variant_builder_add (&meta, "{sv}", "description", g_variant_new_string (gs_app_get_summary
(app)));
meta_variant = g_variant_builder_end (&meta);
- g_hash_table_insert (self->metas_cache, g_strdup (gs_app_get_id (app)), g_variant_ref_sink
(meta_variant));
+ g_hash_table_insert (self->metas_cache,
+ g_strdup (gs_app_get_unique_id (app)),
+ g_variant_ref_sink (meta_variant));
}
@@ -306,8 +301,10 @@ search_provider_dispose (GObject *obj)
static void
gs_shell_search_provider_init (GsShellSearchProvider *self)
{
- self->metas_cache = g_hash_table_new_full (g_str_hash, g_str_equal,
- g_free, (GDestroyNotify) g_variant_unref);
+ self->metas_cache = g_hash_table_new_full ((GHashFunc) as_utils_unique_id_hash,
+ (GEqualFunc) as_utils_unique_id_equal,
+ g_free,
+ (GDestroyNotify) g_variant_unref);
self->skeleton = gs_shell_search_provider2_skeleton_new ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]