1

After read shared-mime-info spec and add my own types in /usr/share/mime/packages. I have refreshed the database:

$ update-mime-database /usr/share/mime

I have try with gvfs-info, it return the right mime. So unix command file use libmagic and libmagic use his own database /usr/share/misc/magic . I would like to know if they are a way to convert xml file to magic file for libmagic ?

Makoto
  • 104,088
  • 27
  • 192
  • 230
bioinfornatics
  • 1,749
  • 3
  • 17
  • 36
  • I created an ticket to merge those two DB https://gitlab.freedesktop.org/xdg/shared-mime-info/issues/119 so please join the discussion – Sergey Ponomarev Sep 21 '19 at 12:44

1 Answers1

3

You can't. Your mime-database and libmagic do two different things and are made to be used in conjunction. Libmagic reads the "magic number" in a files header in order to determine what kind of file it is and your mime-database map's file extensions to its mime-type.

Try determining a file by its extension first and use libmagic as a backup in case you come across a file with no extension.

You don't want to just use libmagic because no file is guaranteed to actually have that "magic number" in its header. Getting good support for determining every files mimetype correctly every-time can be tricky.

If you want to read .desktop files use an ini parser.

fitojb
  • 279
  • 2
  • 10
zester
  • 49
  • 3