glib r6407 - in trunk/gio: . xdgmime



Author: alexl
Date: Tue Jan 29 10:20:49 2008
New Revision: 6407
URL: http://svn.gnome.org/viewvc/glib?rev=6407&view=rev

Log:
2008-01-29  Alexander Larsson  <alexl redhat com>

        * 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.



Modified:
   trunk/gio/ChangeLog
   trunk/gio/gcontenttype.c
   trunk/gio/xdgmime/xdgmimecache.c

Modified: trunk/gio/gcontenttype.c
==============================================================================
--- trunk/gio/gcontenttype.c	(original)
+++ trunk/gio/gcontenttype.c	Tue Jan 29 10:20:49 2008
@@ -331,12 +331,15 @@
   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);

Modified: trunk/gio/xdgmime/xdgmimecache.c
==============================================================================
--- trunk/gio/xdgmime/xdgmimecache.c	(original)
+++ trunk/gio/xdgmime/xdgmimecache.c	Tue Jan 29 10:20:49 2008
@@ -865,7 +865,7 @@
 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 @@
 	      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;



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