From f3933b990b714aacce82df2f783d8ae6a97bb585 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 11 Jul 2016 16:00:27 -0400 Subject: [PATCH] Write the correct length for literal and glob lists to the cache As pointed out in bugzilla, we were not counting 'duplicates' properly here. https://bugs.freedesktop.org/show_bug.cgi?id=94409 --- update-mime-database.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/update-mime-database.c b/update-mime-database.c index e793bed..9aa8e17 100644 --- a/update-mime-database.c +++ b/update-mime-database.c @@ -2370,6 +2370,26 @@ add_key (gpointer key, g_ptr_array_add (filter_data->keys, key); } +typedef struct +{ + GetValueFunc *get_value; + gpointer data; + guint count; + +} CountData; + +static void +count_map_entry (gpointer key, + gpointer data) +{ + CountData *count_data = (CountData *)data; + gchar **values; + + values = (* count_data->get_value) (count_data->data, key); + count_data->count += g_strv_length (values) / 3; + g_strfreev (values); +} + static gboolean write_map (FILE *cache, GHashTable *strings, @@ -2382,6 +2402,7 @@ write_map (FILE *cache, GPtrArray *keys; MapData map_data; FilterData filter_data; + CountData count_data; keys = g_ptr_array_new (); @@ -2391,7 +2412,13 @@ write_map (FILE *cache, g_ptr_array_sort (keys, strcmp2); - if (!write_card32 (cache, keys->len)) + map_data.data = map; + count_data.count = 0; + count_data.get_value = get_value; + + g_ptr_array_foreach (keys, count_map_entry, &count_data); + + if (!write_card32 (cache, count_data.count)) return FALSE; map_data.cache = cache; -- 2.9.0