[gnome-software] Warn when overwriting metadata keys that already exist



commit 6f4d6c8238bc267abd2d0adfb6e83695d989892c
Author: Richard Hughes <richard hughsie com>
Date:   Tue Feb 25 14:43:51 2014 +0000

    Warn when overwriting metadata keys that already exist
    
    Also, ignore setting an existing key with the same value as we're trying to set,
    we don't want the memory address to be changed for no reason.
    
    Resolves: https://bugzilla.gnome.org/show_bug.cgi?id=723702

 src/gs-app.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)
---
diff --git a/src/gs-app.c b/src/gs-app.c
index 955a601..d7411ff 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -1385,7 +1385,19 @@ gs_app_get_metadata_item (GsApp *app, const gchar *key)
 void
 gs_app_set_metadata (GsApp *app, const gchar *key, const gchar *value)
 {
+       const gchar *found;
+
        g_return_if_fail (GS_IS_APP (app));
+
+       /* check we're not overwriting */
+       found = g_hash_table_lookup (app->priv->metadata, key);
+       if (found != NULL) {
+               if (g_strcmp0 (found, value) == 0)
+                       return;
+               g_warning ("tried overwriting key %s from %s to %s",
+                          key, found, value);
+               return;
+       }
        g_hash_table_insert (app->priv->metadata,
                             g_strdup (key),
                             g_strdup (value));


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