summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorРуслан Ижбулатов <lrn1986@gmail.com>2015-05-02 23:27:31 +0000
committerMatthias Clasen <mclasen@redhat.com>2015-12-16 07:47:54 -0500
commitb86e46e8e7f89f6866cb2fbb917ae00ea9431185 (patch)
treeb2680979c1f537477c9fab40892d48734dce106e
parent1513efc904cfb42ed5305fd77b40e1c399380d40 (diff)
downloadglib-b86e46e8e7f89f6866cb2fbb917ae00ea9431185.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
-rw-r--r--gio/xdgmime/xdgmimecache.c91
1 files changed, 74 insertions, 17 deletions
diff --git a/gio/xdgmime/xdgmimecache.c b/gio/xdgmime/xdgmimecache.c
index 7998f2987..9ea32c834 100644
--- a/gio/xdgmime/xdgmimecache.c
+++ b/gio/xdgmime/xdgmimecache.c
@@ -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);