Shared-mime checking order
dfaure at trolltech.com
Fri Aug 24 07:11:04 PDT 2007
After discussion with Alexander Larsson on IRC, I would like to suggest a
change to the shared-mime specification, more precisely to the algorithm for
determining the mimetype of a file, when the extension isn't enough
After matching high-priority rules, and assuming none matched, we look at the
extension. If more than one mimetype match that extension, we should still
apply the (low-priority) magic rules, and if the result of that matching is a
subclass of the mimetype found from the extension, then we should use that
as the final mimetype -- but that's unlikely -- or more likely, if only one of
the mimetypes found from the extension is a subclass of the mimetype found by
magic then that's the one.
For instance after matching *.doc we get text/plain and application/msword,
because there are *.doc files in /usr/share/doc on unix systems which are
plain text. Then we can use magic to determine if the file is text/plain or
application/x-ole-storage. And that allows us to select text/plain or
application/msword (i.e. picking the right one of the mimetypes that matched
the *.doc extension).
We could do the same with *.pdf which could be application/pdf or
application/pdf+gz : sniffing would tell us if it's pdf or gzip...
Hmm and what I described as "unlikely" above is what happens for *.ogg files,
if we make their magic low-prio again. The above spec addition would allow to
do ogg-related magic only on *.ogg files, not on every file.
More information about the xdg