Shared-mime checking order

Daniel Leidert daniel.leidert.spam at gmx.net
Thu Sep 20 08:20:52 PDT 2007


Am Mittwoch, den 19.09.2007, 22:15 +0200 schrieb David Faure:
> On Tuesday 18 September 2007, Daniel Leidert wrote:
> > But I would like to raise a different issue: Let's take the above
> > example and let's say, that I define a very specific MIME type 
> > 
> >   <mime-type type="text/x-mytest-one">
> >     <comment>My test case one</comment>
> >     <glob pattern="README.txt"/>
> >     <sub-class-of type="text/plain"/>
> >     <magic priority="100">
> >       <match value="mystring" type="string" offset="0"/>
> >     </magic>
> >   </mime-type>
> > 
> > which MUST have the string "mystring" at offset 0.
> "MUST" is wrong. magic is about having "hints" about what the file might be,
> there is never a strong rule that the file MUST have this magic.

The libmagic implementation is based on the fact, that something MUST be
found, to be of a special type. I know several file-types, that MUST
have a special string/pattern. I don't understand your point.

> > Now I create a 
> > README.txt file with the content "blah" - definitely not of type
> > text/x-mytest-one then. But gnomefs-info reports in both modes, that the
> > file is of type text/x-mytest-one (because I don't have a KDE4
> > installed, I cannot test your solution David). So: Is it possible to
> > assign an extra mode, if the priority is 100 or very high, so only if
> > the magic pattern matches (too), the MIME type can be of this type -
> > maybe only do this in slow mode - or change the checking order in slow
> > mode to follow the spec, which IMHO would fix this problem too.
> It sounds like you're asking again for the "high priority sniffing" which we
> just decided against for performance reasons.

I understand the perfomance issues when doing a fast check, like when
opening a directory in nautilus.

> We don't want to open up
> all the files when the glob gives us enough information anyway.

But that's the point. glob doesn't give you enough information. I will
create a avery simple example at the end of this mail to demonstrate the
problem.

> OK in your case only README.txt files would be opened, but as soon as
> there is such a mechanism people will obviously abuse it, so we better
> make sure there is really a need for it first.
> Is there a real world use case for this? README.txt and "mystring" is hardly one :-)

Yes, I found several mis-detections caused by this issue. I just used
the above example to simply show the problem. Here one you should eb
able to reproduce (at leats I can with gnome-vfs 2.20.0:

$ touch example.nb
$ gnomevfs-info -s example.nb 
Name              : example.nb
Type              : Regular
MIME type         : application/mathematica
[snip]

This is never-ever a Mathemica file. It's simply an empty text/plain
file. I can prepare much more examples - you also can. I originally
discovered this issue when I added support for a file-type, that was
using the .ent extension. Unfortunately .ent extensions are also often
used for entity collections (instead of .dtd). Nautilus/gnome-vfs
thought, that the entity collections files were of the chemical file
type that used the .ent extension too. The problem always appears for
file-types not found in the database, but using an extension found in
the database (and of course being of the same generic type).

Regards, Daniel



More information about the xdg mailing list