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
This commit is contained in:
Руслан Ижбулатов 2015-05-02 23:27:31 +00:00 committed by Matthias Clasen
parent 1513efc904
commit b86e46e8e7

View File

@ -155,6 +155,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;
@ -324,10 +330,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)
@ -370,10 +382,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)
@ -424,8 +442,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++)
{
@ -545,9 +569,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,
@ -682,6 +713,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));
}
@ -708,6 +742,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,
mime_types, n_mime_types);
if (prio > priority)
@ -894,11 +931,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)
@ -957,9 +999,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++)
{
@ -1009,10 +1056,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)
@ -1090,6 +1143,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);