After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 760997 - Incorrect mime type detection for file
Incorrect mime type detection for file
Status: RESOLVED NOTABUG
Product: glib
Classification: Platform
Component: gio
2.46.x
Other Linux
: Normal normal
: ---
Assigned To: gvfs-maint
gvfs-maint
Depends on:
Blocks:
 
 
Reported: 2016-01-22 17:26 UTC by Jonathan Underwood
Modified: 2016-01-24 15:07 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Example mime type spec (398 bytes, text/xml)
2016-01-22 17:26 UTC, Jonathan Underwood
Details

Description Jonathan Underwood 2016-01-22 17:26:04 UTC
Created attachment 319565 [details]
Example mime type spec

1. Install the attached mime type xml file under /usr/share/mime/packages

2. Change the mathematica section of /usr/share/mime/packages/freedesktop.org.xml to have a lower weight and priority ie.:

<glob weight="30" pattern="*.nb"/>

and 

<magic priority="30">

3. Run update-mime-database /usr/share/mime

4. At this point, the definition in application-vnd.wolfram.nb.xml should be having priority over the one in freedesktop.org.xml for files with the extension .nb, and so the mimetype should be detected as application/vnd.wolfram.nb rather than application/mathematica

5. However:

$ xdg-mime query filetype junk.nb 
application/mathematica

$ gvfs-info junk.nb
display name: junk.nb
edit name: junk.nb
name: junk.nb
type: regular
size:  4
uri: file:///home/jgu/tmp/junk.nb
attributes:
  standard::type: 1
  standard::name: junk.nb
  standard::display-name: junk.nb
  standard::edit-name: junk.nb
  standard::copy-name: junk.nb
  standard::icon: application-mathematica, x-office-document
  standard::content-type: application/mathematica
  standard::fast-content-type: application/vnd.wolfram.nb


$ mimetype junk.nb
junk.nb: application/vnd.wolfram.nb

$ kmimetypefinder junk.nb
application/vnd.wolfram.nb
(accuracy 100)


So, gvfs is getting it wrong. mimetype and kmimetypefinder are getting it right.
Comment 1 Jonathan Underwood 2016-01-22 19:27:49 UTC
Reassigning to glib, as I think this must be a bug in the weight handling in xdgmimecache.c
Comment 2 Matthias Clasen 2016-01-24 15:07:29 UTC
here is what I am seeing after steps 1 - 3 (note that I added an explicit weight="80" to the <glob> in your example:

update-mime-database gives me an error:

Wrong namespace on document element in '/usr/share/mime/packages/test.xml' (should be http://www.freedesktop.org/standards/shared-mime-info)

and the weight 80 glob for *.nb does not make it into /usr/share/mime/glob2

Adding the xmlns attribute on <mime-info> makes the warning go away, and the glob entry appears in /usr/share/mime/glob2


So, I don't know how mimetype and kmimetypefinder manage to use your file even though it is ignored by update-mime-database - are they processing the raw xml ? gio only uses the cache files.

And after fixing the xml namespace, gvfs-info yields the expected mimetype.