Bug 551681 – g_content_type_guess() too naive with filenames
authorMatthias Clasen <matthiasc@src.gnome.org>
Mon, 15 Sep 2008 16:06:05 +0000 (16:06 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Mon, 15 Sep 2008 16:06:05 +0000 (16:06 +0000)
        * gcontenttype.c (g_content_type_guess): Check whether there's a '/'
        at the end of the filename, and declare it a directory.
        Patch by Bastien Nocera

svn path=/trunk/; revision=7491

gio/ChangeLog
gio/gcontenttype.c

index 89a7cd4..7b519e7 100644 (file)
@@ -1,3 +1,11 @@
+2008-09-15  Matthias Clasen  <mclasen@redhat.com>
+
+       Bug 551681 – g_content_type_guess() too naive with filenames
+
+       * gcontenttype.c (g_content_type_guess): Check whether there's a '/'
+       at the end of the filename, and declare it a directory.
+       Patch by Bastien Nocera
+
 2008-09-14  Cosimo Cecchi  <cosimoc@gnome.org>
 
        Bug 551887 – Docs for g_desktop_app_info_new_from_filename ()
index 88f25be..7f47806 100644 (file)
@@ -895,9 +895,18 @@ g_content_type_guess (const char   *filename,
   
   if (filename)
     {
-      basename = g_path_get_basename (filename);
-      n_name_mimetypes = xdg_mime_get_mime_types_from_file_name (basename, name_mimetypes, 10);
-      g_free (basename);
+      i = strlen (filename);
+      if (filename[i - 1] == '/') {
+        char *mimetypes[] = { "inode/directory", NULL };
+        name_mimetypes = g_strdupv (mimetypes);
+        n_name_mimetypes = 1;
+        if (result_uncertain)
+          *result_uncertain = TRUE;
+      } else {
+        basename = g_path_get_basename (filename);
+       n_name_mimetypes = xdg_mime_get_mime_types_from_file_name (basename, name_mimetypes, 10);
+       g_free (basename);
+      }
     }
 
   /* Got an extension match, and no conflicts. This is it. */