Linux – Why does `xdg-mime query filetype …` fail to find a new added file type

freedesktoplinuxmime-types

I installed a new file type to share MIME database. But xdg-mime query filetype cannot tell the new type. This problem only happens on my own Linux OS which does not use GNOME or KDE as its desktop. On Ubuntu, the same process works well.

I found that xdg-mime query filetype uses "file -i filename" under the hood on my OS but uses gnomevfs on Ubuntu.

Here are my steps:

  1. wrote a xml file for my new file type my_file.xml
  2. xdg-mime install my_file.xml
  3. xdg-mime query filetype <name of file to query> …. no output 🙁

I checked /usr/share/mime/applications and found the xml entry generated by update-mime-database there. And the C API g_file_info_get_content_type() can get the proper mime type.

So it seems the shared-mime-info has been updated successfully. But the "file" command still fails, why?

Here is my xml file:

<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
    <mime-type type="application/vnd.xxx.xxx.xxx">
        <comment>xxxx</comment>
        <glob pattern="*.dcf"/>
    </mime-type>
</mime-info>

Best Answer

I think I find the answer. On my system "xdg-mime query filetype ..." uses"file" command to get the file type, while on ubuntu it uses "gnomevfs".

It seems the "file" command does not check xml entries of shared-mime-info, but looks into the file "/user/share/file/magic" to get the file MIME type.

If I use "file" command on Ubuntu, it can not tell me the right MIME type, either.

I'll study how to edit this magic file.

Related Question