Issues regarding xdg-mime

Having gone through the Arch Wiki and the XDG specification in order to learn how to create my own mime types, I conducted the following experiment:

  1. Create a mimetype file application-newtype.xml in the current working directory.
  2. Add the following contents to application-newtype.xml:
<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
    <mime-type type="application/newtype">
        <comment>New Type</comment>
        <glob pattern="*.newtype"/>
    </mime-type>
</mime-info>
  1. Install the mimetype locally
$ xdg-mime install application-newtype.xml
  1. Update mime database
$ update-mime-database ~/.local/share/mime
  1. Create a file with .newtype extension and then query the file’s mime type with xdg-mime
$ echo "Hello world" > test.newtype
$ xdg-mime query filetype test.newtype
text/plain

The result was surprising. According to xdg-mime query filetype, test.newtype’s mimetype is text/plain. On the other hand, file managers such as Thunar does report the correct mimetype.

What could possibly lead to this discrepancy? Don’t thunar and xdg-utils read from the same database? I though that perhaps xdg-mime is flawed, so I tried to install other mimetype-querying tools such as the tools provided by the perl-file-mimeinfo package.

To my surprise, after installing perl-file-meminfo, xdg-mime query filetype suddenly worked again.

$ sudo pacman -Syu perl-file-mimeinfo
---
---
$ xdg-mime query filetype test.newtype
application/newtype

Removing theperl-file-meminfo altogether once again caused xdg-mime query filetype test.newtype to yield text/plain.

I’d really like to understand what’s going on here. Any insight is much appreciated.

Figured out the problem.

According to xdg-utils’s Arch Wiki page, xdg-utils does require perl-file-mimeinfo to work.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.