[PATCH] Improve xdgmime sniffing behavior (again)



It turns out that the strategy introduced with my last patch didn't work
properly for three or more matching MIME types, and we didn't allow 0
priorities.

from xdgmime ChangeLog:

2006-02-25  Christian Neumair  <chris gnome-de org>

        * src/xdgmimemagic.c: (_xdg_mime_magic_lookup_data): Make
        priority equality check more robust so that it works for three
or more
        matches. Also allow matchlets with 0 priority.

Attached is a GnomeVFS variant. OK to commit?

-- 
Christian Neumair <chris gnome-de org>
Index: libgnomevfs/xdgmimemagic.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/xdgmimemagic.c,v
retrieving revision 1.13
diff -u -p -r1.13 xdgmimemagic.c
--- libgnomevfs/xdgmimemagic.c	19 Feb 2006 16:29:57 -0000	1.13
+++ libgnomevfs/xdgmimemagic.c	25 Feb 2006 10:47:00 -0000
@@ -661,21 +662,27 @@ _xdg_mime_magic_lookup_data (XdgMimeMagi
   const char *mime_type;
   int n;
   int priority;
+  int had_match;
 
   mime_type = NULL;
   priority = 0;
+  had_match = 0;
   for (match = mime_magic->match_list; match; match = match->next)
     {
       if (_xdg_mime_magic_match_compare_to_data (match, data, len))
 	{
-	  if ((mime_type == NULL) || (xdg_mime_mime_type_subclass (match->mime_type, mime_type)) || match->priority > priority) {
-	    mime_type = match->mime_type;
-	    priority = match->priority;
-	  } else if (match->priority == priority) {
+	  if (!had_match || match->priority > priority ||
+	      (mime_type != NULL && xdg_mime_mime_type_subclass (match->mime_type, mime_type)))
+	    {
+	      mime_type = match->mime_type;
+	      priority = match->priority;
+	    }
+	  else if (had_match && match->priority == priority)
 	    /* multiple unrelated patterns with the same priority matched,
 	     * so we can't tell what type this is. */
 	    mime_type = NULL;
-	  }
+
+	  had_match = 1;
 	}
       else 
 	{

Attachment: signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil



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