[gnome-software/gnome-3-12] Always show the featured background gradient



commit bfa9a0a9e71910cd75f6307032046a952d3bbc8b
Author: Richard Hughes <richard hughsie com>
Date:   Tue Apr 8 11:22:51 2014 +0100

    Always show the featured background gradient
    
    This fixes a logic thinko which appeared when two actions were racing to subsume
    the later-created GsApp. Always copy the metadata to the correct object, and add
    self tests to prevent this in the future.

 src/gs-app.c       |    7 ++++---
 src/gs-self-test.c |   17 +++++++++++++++++
 2 files changed, 21 insertions(+), 3 deletions(-)
---
diff --git a/src/gs-app.c b/src/gs-app.c
index b4915a2..deeae0b 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -1701,14 +1701,15 @@ gs_app_subsume (GsApp *app, GsApp *other)
        }
        priv->kudos |= priv2->kudos;
 
-       /* also metadata */
+       /* copy metadata from @other to @app unless the app already has a key
+        * of that name */
        keys = g_hash_table_get_keys (priv2->metadata);
        for (l = keys; l != NULL; l = l->next) {
                tmp = g_hash_table_lookup (priv->metadata, l->data);
-               if (tmp == NULL)
+               if (tmp != NULL)
                        continue;
                tmp = g_hash_table_lookup (priv2->metadata, l->data);
-               gs_app_set_metadata (other, l->data, tmp);
+               gs_app_set_metadata (app, l->data, tmp);
        }
        g_list_free (keys);
 }
diff --git a/src/gs-self-test.c b/src/gs-self-test.c
index 7bf6823..00dc670 100644
--- a/src/gs-self-test.c
+++ b/src/gs-self-test.c
@@ -275,6 +275,22 @@ gs_plugin_func (void)
 }
 
 static void
+gs_app_subsume_func (void)
+{
+       GsApp *new;
+       GsApp *old;
+
+       new = gs_app_new ("xxx.desktop");
+       old = gs_app_new ("yyy.desktop");
+       gs_app_set_metadata (old, "foo", "bar");
+       gs_app_subsume (new, old);
+       g_assert_cmpstr (gs_app_get_metadata_item (new, "foo"), ==, "bar");
+
+       g_object_unref (new);
+       g_object_unref (old);
+}
+
+static void
 gs_app_func (void)
 {
        GsApp *app;
@@ -701,6 +717,7 @@ main (int argc, char **argv)
        g_test_add_func ("/gnome-software/plugin-loader{refine}", gs_plugin_loader_refine_func);
        g_test_add_func ("/gnome-software/plugin", gs_plugin_func);
        g_test_add_func ("/gnome-software/app", gs_app_func);
+       g_test_add_func ("/gnome-software/app{subsume}", gs_app_subsume_func);
        if (g_getenv ("HAS_APPSTREAM") != NULL)
                g_test_add_func ("/gnome-software/plugin-loader{empty}", gs_plugin_loader_empty_func);
        g_test_add_func ("/gnome-software/plugin-loader{dedupe}", gs_plugin_loader_dedupe_func);


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