[gnome-software/wip/hughsie/unique-id-hash] f a71cce80443fe758dacf165a52fc5701b1402b19



commit 01b842b0d7eba8211ded435992db2882da258001
Author: Richard Hughes <richard hughsie com>
Date:   Thu Aug 25 19:07:41 2016 +0100

    f a71cce80443fe758dacf165a52fc5701b1402b19

 src/gs-plugin.c    |   22 ++++++++++++++++------
 src/gs-self-test.c |   39 ++++++++++++++++++++++++++++++++++++++-
 2 files changed, 54 insertions(+), 7 deletions(-)
---
diff --git a/src/gs-plugin.c b/src/gs-plugin.c
index 9ea2373..f7fec7d 100644
--- a/src/gs-plugin.c
+++ b/src/gs-plugin.c
@@ -193,13 +193,17 @@ gs_plugin_finalize (GObject *object)
        g_free (priv->language);
        g_rw_lock_clear (&priv->rwlock);
        g_object_unref (priv->profile);
-       g_ptr_array_unref (priv->auth_array);
-       g_object_unref (priv->soup_session);
-       g_object_unref (priv->global_cache);
+       if (priv->auth_array != NULL)
+               g_ptr_array_unref (priv->auth_array);
+       if (priv->soup_session != NULL)
+               g_object_unref (priv->soup_session);
+       if (priv->global_cache != NULL)
+               g_object_unref (priv->global_cache);
        g_hash_table_unref (priv->cache);
        g_mutex_clear (&priv->cache_mutex);
        g_mutex_clear (&priv->timer_mutex);
-       g_module_close (priv->module);
+       if (priv->module != NULL)
+               g_module_close (priv->module);
 }
 
 /**
@@ -1190,7 +1194,10 @@ gs_plugin_cache_lookup (GsPlugin *plugin, const gchar *key)
 
        /* global, so using a unique_id */
        if (gs_plugin_has_flags (plugin, GS_PLUGIN_FLAGS_GLOBAL_CACHE)) {
-               g_return_val_if_fail (as_utils_unique_id_valid (key), NULL);
+               if (!as_utils_unique_id_valid (key)) {
+                       g_critical ("key %s is not a unique_id", key);
+                       return NULL;
+               }
                app = gs_app_list_lookup (priv->global_cache, key);
        } else {
                app = g_hash_table_lookup (priv->cache, key);
@@ -1223,7 +1230,10 @@ gs_plugin_cache_add (GsPlugin *plugin, const gchar *key, GsApp *app)
 
        /* global, so using internal unique_id */
        if (gs_plugin_has_flags (plugin, GS_PLUGIN_FLAGS_GLOBAL_CACHE)) {
-               g_return_if_fail (as_utils_unique_id_valid (key));
+               if (!as_utils_unique_id_valid (key)) {
+                       g_critical ("key %s is not a unique_id", key);
+                       return;
+               }
                gs_app_list_add (priv->global_cache, app);
                return;
        }
diff --git a/src/gs-self-test.c b/src/gs-self-test.c
index cec0caa..4b03881 100644
--- a/src/gs-self-test.c
+++ b/src/gs-self-test.c
@@ -29,7 +29,7 @@
 #include "gs-app-private.h"
 #include "gs-app-list-private.h"
 #include "gs-os-release.h"
-#include "gs-plugin.h"
+#include "gs-plugin-private.h"
 #include "gs-plugin-loader.h"
 #include "gs-plugin-loader-sync.h"
 #include "gs-utils.h"
@@ -89,6 +89,42 @@ gs_os_release_func (void)
 }
 
 static void
+gs_plugin_global_cache_func (void)
+{
+       const gchar *unique_id;
+       g_autoptr(GsPlugin) plugin1 = NULL;
+       g_autoptr(GsPlugin) plugin2 = NULL;
+       g_autoptr(GsAppList) list = gs_app_list_new ();
+       g_autoptr(GsApp) app = gs_app_new ("gimp.desktop");
+       g_autoptr(GsApp) app1 = NULL;
+       g_autoptr(GsApp) app2 = NULL;
+
+       plugin1 = gs_plugin_new ();
+       gs_plugin_set_global_cache (plugin1, list);
+
+       plugin2 = gs_plugin_new ();
+       gs_plugin_set_global_cache (plugin2, list);
+
+       /* both plugins not opted into the global cache */
+       unique_id = gs_app_get_unique_id (app);
+       gs_plugin_cache_add (plugin1, unique_id, app);
+       g_assert (gs_plugin_cache_lookup (plugin2, unique_id) == NULL);
+       app1 = gs_plugin_cache_lookup (plugin1, unique_id);
+       g_assert (app1 != NULL);
+
+       /* one plugin opted in */
+       gs_plugin_add_flags (plugin1, GS_PLUGIN_FLAGS_GLOBAL_CACHE);
+       gs_plugin_cache_add (plugin1, unique_id, app);
+       g_assert (gs_plugin_cache_lookup (plugin2, unique_id) == NULL);
+
+       /* both plugins opted in */
+       gs_plugin_add_flags (plugin2, GS_PLUGIN_FLAGS_GLOBAL_CACHE);
+       gs_plugin_cache_add (plugin1, unique_id, app);
+       app2 = gs_plugin_cache_lookup (plugin2, unique_id);
+       g_assert (app2 != NULL);
+}
+
+static void
 gs_plugin_func (void)
 {
        GsAppList *list;
@@ -1244,6 +1280,7 @@ main (int argc, char **argv)
        g_test_add_func ("/gnome-software/os-release", gs_os_release_func);
        g_test_add_func ("/gnome-software/app", gs_app_func);
        g_test_add_func ("/gnome-software/plugin", gs_plugin_func);
+       g_test_add_func ("/gnome-software/plugin{global-cache}", gs_plugin_global_cache_func);
        g_test_add_func ("/gnome-software/auth{secret}", gs_auth_secret_func);
 
        /* we can only load this once per process */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]