diff options
author | Руслан Ижбулатов <lrn1986@gmail.com> | 2015-05-02 23:27:31 +0000 |
---|---|---|
committer | Emmanuel Fleury <emmanuel.fleury@gmail.com> | 2021-09-23 19:23:33 +0200 |
commit | e4d181336817c5fba8a176146b5589f07b0f0a80 (patch) | |
tree | 3f58eac7e9607f73c8bcf1b96c3a6287c981758b /gio/xdgmime | |
parent | e7822bd3033453ef789de454a5a70e38d77c8c12 (diff) | |
download | glib-e4d181336817c5fba8a176146b5589f07b0f0a80.tar.gz |
xdgmime: Finer handling for cases where mmap() is not available
Allocate an empty cache object, check cache objects for being empty
before using them.
Otherwise the code will re-read cache every 5 seconds, as NULL cache
does not trigger the code that stores mtime, which makes the cache
file appear modified/unloaded permanently.
https://bugzilla.gnome.org/show_bug.cgi?id=735696
Diffstat (limited to 'gio/xdgmime')
-rw-r--r-- | gio/xdgmime/xdgmimecache.c | 91 |
1 files changed, 74 insertions, 17 deletions
diff --git a/gio/xdgmime/xdgmimecache.c b/gio/xdgmime/xdgmimecache.c index a6975a107..6a936d163 100644 --- a/gio/xdgmime/xdgmimecache.c +++ b/gio/xdgmime/xdgmimecache.c @@ -157,6 +157,12 @@ _xdg_mime_cache_new_from_file (const char *file_name) if (fd != -1) close (fd); +#else /* HAVE_MMAP */ + cache = (XdgMimeCache *) malloc (sizeof (XdgMimeCache)); + cache->minor = 0; + cache->ref_count = 1; + cache->buffer = NULL; + cache->size = 0; #endif /* HAVE_MMAP */ return cache; @@ -302,10 +308,16 @@ cache_alias_lookup (const char *alias) for (i = 0; _caches[i]; i++) { XdgMimeCache *cache = _caches[i]; - xdg_uint32_t list_offset = GET_UINT32 (cache->buffer, 4); - xdg_uint32_t n_entries = GET_UINT32 (cache->buffer, list_offset); + xdg_uint32_t list_offset; + xdg_uint32_t n_entries; xdg_uint32_t offset; + if (cache->buffer == NULL) + continue; + + list_offset = GET_UINT32 (cache->buffer, 4); + n_entries = GET_UINT32 (cache->buffer, list_offset); + min = 0; max = n_entries - 1; while (max >= min) @@ -348,10 +360,16 @@ cache_glob_lookup_literal (const char *file_name, for (i = 0; _caches[i]; i++) { XdgMimeCache *cache = _caches[i]; - xdg_uint32_t list_offset = GET_UINT32 (cache->buffer, 12); - xdg_uint32_t n_entries = GET_UINT32 (cache->buffer, list_offset); + xdg_uint32_t list_offset; + xdg_uint32_t n_entries; xdg_uint32_t offset; + if (cache->buffer == NULL) + continue; + + list_offset = GET_UINT32 (cache->buffer, 12); + n_entries = GET_UINT32 (cache->buffer, list_offset); + min = 0; max = n_entries - 1; while (max >= min) @@ -404,8 +422,14 @@ cache_glob_lookup_fnmatch (const char *file_name, { XdgMimeCache *cache = _caches[i]; - xdg_uint32_t list_offset = GET_UINT32 (cache->buffer, 20); - xdg_uint32_t n_entries = GET_UINT32 (cache->buffer, list_offset); + xdg_uint32_t list_offset; + xdg_uint32_t n_entries; + + if (cache->buffer == NULL) + continue; + + list_offset = GET_UINT32 (cache->buffer, 20); + n_entries = GET_UINT32 (cache->buffer, list_offset); for (j = 0; j < n_entries && n < n_mime_types; j++) { @@ -529,9 +553,16 @@ cache_glob_lookup_suffix (const char *file_name, { XdgMimeCache *cache = _caches[i]; - xdg_uint32_t list_offset = GET_UINT32 (cache->buffer, 16); - xdg_uint32_t n_entries = GET_UINT32 (cache->buffer, list_offset); - xdg_uint32_t offset = GET_UINT32 (cache->buffer, list_offset + 4); + xdg_uint32_t list_offset; + xdg_uint32_t n_entries; + xdg_uint32_t offset; + + if (cache->buffer == NULL) + continue; + + list_offset = GET_UINT32 (cache->buffer, 16); + n_entries = GET_UINT32 (cache->buffer, list_offset); + offset = GET_UINT32 (cache->buffer, list_offset + 4); n = cache_glob_node_lookup_suffix (cache, n_entries, offset, @@ -668,6 +699,9 @@ _xdg_mime_cache_get_max_buffer_extents (void) { XdgMimeCache *cache = _caches[i]; + if (cache->buffer == NULL) + continue; + offset = GET_UINT32 (cache->buffer, 24); max_extent = MAX (max_extent, GET_UINT32 (cache->buffer, offset + 4)); } @@ -694,6 +728,9 @@ cache_get_mime_type_for_data (const void *data, int prio; const char *match; + if (cache->buffer == NULL) + continue; + match = cache_magic_lookup_data (cache, data, len, &prio); if (prio > priority) { @@ -899,11 +936,16 @@ _xdg_mime_cache_mime_type_subclass (const char *mime, for (i = 0; _caches[i]; i++) { XdgMimeCache *cache = _caches[i]; - - xdg_uint32_t list_offset = GET_UINT32 (cache->buffer, 8); - xdg_uint32_t n_entries = GET_UINT32 (cache->buffer, list_offset); + xdg_uint32_t list_offset; + xdg_uint32_t n_entries; xdg_uint32_t offset, n_parents, parent_offset; + if (cache->buffer == NULL) + continue; + + list_offset = GET_UINT32 (cache->buffer, 8); + n_entries = GET_UINT32 (cache->buffer, list_offset); + min = 0; max = n_entries - 1; while (max >= min) @@ -963,9 +1005,14 @@ _xdg_mime_cache_list_mime_parents (const char *mime) for (i = 0; _caches[i]; i++) { XdgMimeCache *cache = _caches[i]; - - xdg_uint32_t list_offset = GET_UINT32 (cache->buffer, 8); - xdg_uint32_t n_entries = GET_UINT32 (cache->buffer, list_offset); + xdg_uint32_t list_offset; + xdg_uint32_t n_entries; + + if (cache->buffer == NULL) + continue; + + list_offset = GET_UINT32 (cache->buffer, 8); + n_entries = GET_UINT32 (cache->buffer, list_offset); for (j = 0; j < n_entries; j++) { @@ -1015,10 +1062,16 @@ cache_lookup_icon (const char *mime, int header) for (i = 0; _caches[i]; i++) { XdgMimeCache *cache = _caches[i]; - xdg_uint32_t list_offset = GET_UINT32 (cache->buffer, header); - xdg_uint32_t n_entries = GET_UINT32 (cache->buffer, list_offset); + xdg_uint32_t list_offset; + xdg_uint32_t n_entries; xdg_uint32_t offset; + if (cache->buffer == NULL) + continue; + + list_offset = GET_UINT32 (cache->buffer, header); + n_entries = GET_UINT32 (cache->buffer, list_offset); + min = 0; max = n_entries - 1; while (max >= min) @@ -1097,6 +1150,10 @@ _xdg_mime_cache_glob_dump (void) xdg_uint32_t list_offset; xdg_uint32_t n_entries; xdg_uint32_t offset; + + if (cache->buffer == NULL) + continue; + list_offset = GET_UINT32 (cache->buffer, 16); n_entries = GET_UINT32 (cache->buffer, list_offset); offset = GET_UINT32 (cache->buffer, list_offset + 4); |