6

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>
2
  • My destop system is neither GNOME or KDE. The debug info "Running file -i..." and I found it run to info_generic(): { DEBUG 1 "Running file -i \"$1\"" /usr/bin/file -i "$1" 2> /dev/null | cut -d ":" -f 2 | sed s/"^ "// if [ $? -eq 0 ]; then exit_success else exit_failure_operation_failed fi }
    – Amanda
    Commented Mar 22, 2011 at 3:33
  • If you dont have any desktop enviroment, you should not use xdg-mime (or any other xdg tool). xdg is meant to provide interoperability between different desktop enviroments, but not when there is none. Think of xdg as desktop-agnostic, but not "desktop-atheist"
    – MestreLion
    Commented Jul 4, 2011 at 4:05

2 Answers 2

3

I think I find the answer. On my system xdg-mime query filetype ... uses the 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 /usr/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.

2
  • There are two different MIME databases. file uses the unix traditional /etc/magic (and other …/magic). xdg-mime uses the Freedesktop database (when it's available). Commented Mar 23, 2011 at 0:22
  • 1
    @Giles: xdg-mime uses Freedesktop database when it is avaliable and and there is a DE (like Gnome or KDE) installed to actually read the database. Since OP has no DE, xdg-mime has no tools to query its own database, and falls back to file
    – MestreLion
    Commented Jul 1, 2011 at 18:35
2

Try installing http://search.cpan.org/dist/File-MimeInfo/ (or your distro's package for this) which contains the mimetype utility.

After installing this package, xdg-mime (tested version 1.1.0 rc1 on Arch Linux) should now detect that mimetype (which does use the XDG shared mime info database) is available, and use that instead of falling back on file -i.

3
  • The command seems to be mimetype in ubuntu 14.04 and 16.04. apt-get install libfile-mimeinfo-perl if it's not there.
    – GnP
    Commented Aug 10, 2017 at 16:52
  • @GnP Same here, thanks for mentioning. I'll update my answer.
    – ack
    Commented Feb 17, 2018 at 18:58
  • This solution won't work if kde, gnome, cinnamon, lxde, mate or xfce is installed as a Desktop Environment.
    – Marc.2377
    Commented Apr 16, 2018 at 21:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .