? xdgmime/glob.diff ? xdgmime/matchtests.diff ? xdgmime/updatemimecache.c ? xdgmime/xdgmimecache.c ? xdgmime/xdgmimecache.h Index: xdgmime/Makefile.am =================================================================== RCS file: /cvs/gnome/gtk+/gtk/xdgmime/Makefile.am,v retrieving revision 1.4 diff -u -p -r1.4 Makefile.am --- xdgmime/Makefile.am 8 Nov 2004 19:36:12 -0000 1.4 +++ xdgmime/Makefile.am 1 Apr 2005 06:42:42 -0000 @@ -5,6 +5,8 @@ noinst_LTLIBRARIES = libxdgmime.la libxdgmime_la_SOURCES = \ xdgmime.c \ xdgmime.h \ + xdgmimecache.c \ + xdgmimecache.h \ xdgmimealias.c \ xdgmimealias.h \ xdgmimeglob.c \ Index: xdgmime/test-mime.c =================================================================== RCS file: /cvs/gnome/gtk+/gtk/xdgmime/test-mime.c,v retrieving revision 1.4 diff -u -p -r1.4 test-mime.c --- xdgmime/test-mime.c 8 Nov 2004 19:36:12 -0000 1.4 +++ xdgmime/test-mime.c 1 Apr 2005 06:42:42 -0000 @@ -112,7 +112,7 @@ main (int argc, char *argv[]) printf ("File \"%s\" has a mime-type of %s\n", file_name, result); } -#if 0 +#if 1 xdg_mime_dump (); #endif return 0; Index: xdgmime/xdgmime.c =================================================================== RCS file: /cvs/gnome/gtk+/gtk/xdgmime/xdgmime.c,v retrieving revision 1.11.2.2 diff -u -p -r1.11.2.2 xdgmime.c --- xdgmime/xdgmime.c 1 Mar 2005 17:40:57 -0000 1.11.2.2 +++ xdgmime/xdgmime.c 1 Apr 2005 06:42:42 -0000 @@ -35,6 +35,7 @@ #include "xdgmimemagic.h" #include "xdgmimealias.h" #include "xdgmimeparent.h" +#include "xdgmimecache.h" #include #include #include @@ -55,6 +56,9 @@ static XdgAliasList *alias_list = NULL; static XdgParentList *parent_list = NULL; static XdgDirTimeList *dir_time_list = NULL; static XdgCallbackList *callback_list = NULL; +XdgMimeCache **caches = NULL; +int n_caches = 0; + const char *xdg_mime_type_unknown = "application/octet-stream"; @@ -122,6 +126,28 @@ xdg_mime_init_from_directory (const char assert (directory != NULL); + file_name = malloc (strlen (directory) + strlen ("/mime/mime.cache") + 1); + strcpy (file_name, directory); strcat (file_name, "/mime/mime.cache"); + if (stat (file_name, &st) == 0) + { + XdgMimeCache *cache = _xdg_mime_cache_new_from_file (file_name); + + if (cache != NULL) + { + list = xdg_dir_time_list_new (); + list->directory_name = file_name; + list->mtime = st.st_mtime; + list->next = dir_time_list; + dir_time_list = list; + + caches = realloc (caches, n_caches + 1); + caches[n_caches] = cache; + n_caches++; + + return FALSE; + } + } + file_name = malloc (strlen (directory) + strlen ("/mime/globs") + 1); strcpy (file_name, directory); strcat (file_name, "/mime/globs"); if (stat (file_name, &st) == 0) @@ -311,6 +337,17 @@ xdg_check_dir (const char *directory, return TRUE; } + /* Check the mime.cache file */ + file_name = malloc (strlen (directory) + strlen ("/mime/mime.cache") + 1); + strcpy (file_name, directory); strcat (file_name, "/mime/mime.cache"); + invalid = xdg_check_file (file_name); + free (file_name); + if (invalid) + { + *invalid_dir_list = TRUE; + return TRUE; + } + return FALSE; /* Keep processing */ } @@ -395,6 +432,9 @@ xdg_mime_get_mime_type_for_data (const v xdg_mime_init (); + if (caches) + return _xdg_mime_cache_get_mime_type_for_data (data, len); + mime_type = _xdg_mime_magic_lookup_data (global_magic, data, len); if (mime_type) @@ -421,6 +461,9 @@ xdg_mime_get_mime_type_for_file (const c xdg_mime_init (); + if (caches) + return _xdg_mime_cache_get_mime_type_for_file (file_name); + base_name = _xdg_get_base_name (file_name); mime_type = xdg_mime_get_mime_type_from_file_name (base_name); @@ -474,6 +517,9 @@ xdg_mime_get_mime_type_from_file_name (c xdg_mime_init (); + if (caches) + return _xdg_mime_cache_get_mime_type_from_file_name (file_name); + mime_type = _xdg_glob_hash_lookup_file_name (global_hash, file_name); if (mime_type) return mime_type; @@ -529,6 +575,9 @@ xdg_mime_get_max_buffer_extents (void) { xdg_mime_init (); + if (caches) + return _xdg_mime_cache_get_max_buffer_extents (); + return _xdg_mime_magic_get_buffer_extents (global_magic); } @@ -539,6 +588,9 @@ xdg_mime_unalias_mime_type (const char * xdg_mime_init (); + if (caches) + return _xdg_mime_cache_unalias_mime_type (mime_type); + if ((lookup = _xdg_mime_alias_list_lookup (alias_list, mime_type)) != NULL) return lookup; @@ -604,6 +656,9 @@ xdg_mime_mime_type_subclass (const char xdg_mime_init (); + if (caches) + return _xdg_mime_cache_mime_type_subclass (mime, base); + umime = xdg_mime_unalias_mime_type (mime); ubase = xdg_mime_unalias_mime_type (base); @@ -636,6 +691,26 @@ xdg_mime_mime_type_subclass (const char } return 0; +} + +char ** +xdg_mime_list_mime_parents (const char *mime) +{ + const char **parents; + char **result; + int i, n; + + if (caches) + return _xdg_mime_cache_list_mime_parents (mime); + + parents = xdg_mime_get_mime_parents (mime); + for (i = 0; parents[i]; i++) ; + + n = (i + 1) * sizeof (char *); + result = (char **) malloc (n); + memcpy (result, parents, n); + + return result; } const char ** Index: xdgmime/xdgmime.h =================================================================== RCS file: /cvs/gnome/gtk+/gtk/xdgmime/xdgmime.h,v retrieving revision 1.9.2.2 diff -u -p -r1.9.2.2 xdgmime.h --- xdgmime/xdgmime.h 1 Mar 2005 17:40:57 -0000 1.9.2.2 +++ xdgmime/xdgmime.h 1 Apr 2005 06:42:42 -0000 @@ -54,6 +54,7 @@ typedef void (*XdgMimeDestroy) (void *u #define xdg_mime_media_type_equal XDG_ENTRY(media_type_equal) #define xdg_mime_mime_type_subclass XDG_ENTRY(mime_type_subclass) #define xdg_mime_get_mime_parents XDG_ENTRY(get_mime_parents) +#define xdg_mime_list_mime_parents XDG_ENTRY(list_mime_parents) #define xdg_mime_unalias_mime_type XDG_ENTRY(unalias_mime_type) #define xdg_mime_get_max_buffer_extents XDG_ENTRY(get_max_buffer_extents) #define xdg_mime_shutdown XDG_ENTRY(shutdown) @@ -77,7 +78,13 @@ int xdg_mime_media_type_equal const char *mime_b); int xdg_mime_mime_type_subclass (const char *mime_a, const char *mime_b); + /* xdg_mime_get_mime_parents() is deprecated since it does + * not work correctly with caches. Use xdg_mime_list_parents() + * instead, but notice that that function expects you to free + * the array it returns. + */ const char **xdg_mime_get_mime_parents (const char *mime); +char ** xdg_mime_list_mime_parents (const char *mime); const char *xdg_mime_unalias_mime_type (const char *mime); int xdg_mime_get_max_buffer_extents (void); void xdg_mime_shutdown (void);