From e064f28435e4edeac7e3128f80af3ecfc5e09bb9 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Tue, 29 Jan 2008 10:20:49 +0000 Subject: [PATCH] Use list_parents, not get_parents from xdgmime, because the later doesn't 2008-01-29 Alexander Larsson * gcontenttype.c: (_g_unix_content_type_get_parents): Use list_parents, not get_parents from xdgmime, because the later doesn't use the cache. * xdgmime/xdgmimecache.c: (_xdg_mime_cache_list_mime_parents): Don't list the same type as parent multiple times. svn path=/trunk/; revision=6407 --- gio/ChangeLog | 11 +++++++++++ gio/gcontenttype.c | 5 ++++- gio/xdgmime/xdgmimecache.c | 15 +++++++++++++-- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/gio/ChangeLog b/gio/ChangeLog index fa61097ba..ed1039a00 100644 --- a/gio/ChangeLog +++ b/gio/ChangeLog @@ -1,3 +1,14 @@ +2008-01-29 Alexander Larsson + + * gcontenttype.c: + (_g_unix_content_type_get_parents): + Use list_parents, not get_parents from xdgmime, because + the later doesn't use the cache. + + * xdgmime/xdgmimecache.c: + (_xdg_mime_cache_list_mime_parents): + Don't list the same type as parent multiple times. + 2008-01-28 Matthias Clasen * === Released 2.15.4 === diff --git a/gio/gcontenttype.c b/gio/gcontenttype.c index 0dfbeeaf2..97eef6a01 100644 --- a/gio/gcontenttype.c +++ b/gio/gcontenttype.c @@ -331,12 +331,15 @@ _g_unix_content_type_get_parents (const char *type) G_LOCK (gio_xdgmime); umime = xdg_mime_unalias_mime_type (type); + g_ptr_array_add (array, g_strdup (umime)); - parents = xdg_mime_get_mime_parents (umime); + parents = xdg_mime_list_mime_parents (umime); for (i = 0; parents && parents[i] != NULL; i++) g_ptr_array_add (array, g_strdup (parents[i])); + free (parents); + G_UNLOCK (gio_xdgmime); g_ptr_array_add (array, NULL); diff --git a/gio/xdgmime/xdgmimecache.c b/gio/xdgmime/xdgmimecache.c index f17ddf245..5182a6af7 100644 --- a/gio/xdgmime/xdgmimecache.c +++ b/gio/xdgmime/xdgmimecache.c @@ -865,7 +865,7 @@ _xdg_mime_cache_unalias_mime_type (const char *mime) char ** _xdg_mime_cache_list_mime_parents (const char *mime) { - int i, j, k, p; + int i, j, k, l, p; char *all_parents[128]; /* we'll stop at 128 */ char **result; @@ -892,7 +892,18 @@ _xdg_mime_cache_list_mime_parents (const char *mime) for (k = 0; k < n_parents && p < 127; k++) { parent_mime_offset = GET_UINT32 (cache->buffer, parents_offset + 4 + 4 * k); - all_parents[p++] = cache->buffer + parent_mime_offset; + + /* Don't add same parent multiple times. + * This can happen for instance if the same type is listed in multiple directories + */ + for (l = 0; l < p; l++) + { + if (strcmp (all_parents[l], cache->buffer + parent_mime_offset) == 0) + break; + } + + if (l == p) + all_parents[p++] = cache->buffer + parent_mime_offset; } break;