summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Faure <faure@kde.org>2020-12-27 19:10:41 +0100
committerDavid Faure <faure@kde.org>2020-12-30 10:24:55 +0100
commitde283fc430460b9b3a7e61432a6d273cd64cb102 (patch)
treeb020cd58d6d21ed197d503c6d5c7b9aec7f815db /src
parent2dd6af21e2b83710a1f400fc27e1b30b2b5efc2d (diff)
Fix fallback after multiple matching globs
If the result from magic sniffing doesn't correspond to any of the matching globs (even via inheritance), and there *were* matching globs, then don't return the result from magic sniffing. This is too unreliable, and contradicts the fact that if there was just one glob, the glob would win (not the magic). So in that case, fallback to one of the glob matches. This required removing the code in cache_magic_lookup_data which "cleans up" the mimetypes list (from glob matches) of any glob that doesn't have matching magic. This behaviour isn't in the spec [1], and prevents having anything to fall back to in the end, after noticing that the magic should be ignored after all. [1] https://specifications.freedesktop.org/shared-mime-info-spec/shared-mime-info-spec-0.21.html#idm45992893989040 Context: https://gitlab.freedesktop.org/xdg/shared-mime-info/-/issues/138
Diffstat (limited to 'src')
-rw-r--r--src/test-mime-data.c4
-rw-r--r--src/xdgmimecache.c32
2 files changed, 10 insertions, 26 deletions
diff --git a/src/test-mime-data.c b/src/test-mime-data.c
index f14e4dc..b4dffbb 100644
--- a/src/test-mime-data.c
+++ b/src/test-mime-data.c
@@ -73,8 +73,8 @@ check_mime_type (const char *mt,
if (xfail)
{
xmatch++;
-
- if (verbose > 1)
+
+ if (verbose > 0)
printf ("%s, '%s' test: got %s (unexpected match)\n",
filename, test, mt);
}
diff --git a/src/xdgmimecache.c b/src/xdgmimecache.c
index 8b21cef..9df4760 100644
--- a/src/xdgmimecache.c
+++ b/src/xdgmimecache.c
@@ -266,15 +266,13 @@ static const char *
cache_magic_lookup_data (XdgMimeCache *cache,
const void *data,
size_t len,
- int *prio,
- const char *mime_types[],
- int n_mime_types)
+ int *prio)
{
xdg_uint32_t list_offset;
xdg_uint32_t n_entries;
xdg_uint32_t offset;
- int j, n;
+ int j;
*prio = 0;
@@ -290,21 +288,6 @@ cache_magic_lookup_data (XdgMimeCache *cache,
data, len, prio);
if (match)
return match;
- else
- {
- xdg_uint32_t mimetype_offset;
- const char *non_match;
-
- mimetype_offset = GET_UINT32 (cache->buffer, offset + 16 * j + 4);
- non_match = cache->buffer + mimetype_offset;
-
- for (n = 0; n < n_mime_types; n++)
- {
- if (mime_types[n] &&
- _xdg_mime_mime_type_equal (mime_types[n], non_match))
- mime_types[n] = NULL;
- }
- }
}
return NULL;
@@ -678,8 +661,7 @@ cache_get_mime_type_for_data (const void *data,
int prio;
const char *match;
- match = cache_magic_lookup_data (cache, data, len, &prio,
- mime_types, n_mime_types);
+ match = cache_magic_lookup_data (cache, data, len, &prio);
if (prio > priority)
{
priority = prio;
@@ -698,9 +680,11 @@ cache_get_mime_type_for_data (const void *data,
if (mime_types[n] && _xdg_mime_cache_mime_type_subclass(mime_types[n], mime_type))
return mime_types[n];
}
-
- /* Return magic match */
- return mime_type;
+ if (n == 0)
+ {
+ /* No globs: return magic match */
+ return mime_type;
+ }
}
/* Pick first glob result, as fallback */