diff options
author | Руслан Ижбулатов <lrn1986@gmail.com> | 2015-05-02 23:27:31 +0000 |
---|---|---|
committer | Philip Withnall <pwithnall@endlessos.org> | 2022-06-17 16:56:26 +0100 |
commit | 0122cb54677ed02234b29af513204b16069ed6dd (patch) | |
tree | 2ae95ff4b834bcf4aab6c77dff830be1adb15520 | |
parent | c50118863f81bb039d19f60c9d844051e1442cda (diff) |
xdgmime: Finer handling for cases where mmap() is not available
`mmap()` is not reliable/available on Windows.
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
-rw-r--r-- | src/xdgmimecache.c | 91 |
1 files changed, 74 insertions, 17 deletions
diff --git a/src/xdgmimecache.c b/src/xdgmimecache.c index 213027d..a50c8dc 100644 --- a/src/xdgmimecache.c +++ b/src/xdgmimecache.c @@ -161,6 +161,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; @@ -306,10 +312,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) @@ -352,10 +364,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) @@ -408,8 +426,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++) { @@ -532,9 +556,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, @@ -641,6 +672,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)); } @@ -667,6 +701,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) { @@ -868,11 +905,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) @@ -934,9 +976,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++) { @@ -986,10 +1033,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) @@ -1066,6 +1119,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); |