Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mime type determination #77

Closed
tri1976 opened this issue May 15, 2012 · 3 comments
Closed

mime type determination #77

tri1976 opened this issue May 15, 2012 · 3 comments

Comments

@tri1976
Copy link

tri1976 commented May 15, 2012

I have a cd image file named cd.iso and spacefm shows its file type to be application/x-cd-image. I change its filename to cd.img and spacefm shows its file type as application/x-executable. I change its filename to cd.iso~ and spacefm shows its file type as application/x-trash. I checked all 3 filenames with "file" and "xdg-mime" commands, and all show file type to be application/x-iso9660-image. I thought mime file type is supposed to be independent of file extension but it seems like spacefm is using file extension to determine mime type. Is this the intended behavior?

@IgnorantGuru
Copy link
Owner

spacefm gets its mime info from the mime database in freedesktop.org's shared-mime-info package. If you run this:

grep -r "x-cd-image" /usr/share/mime

/usr/share/mime/globs:application/x-cd-image:*.iso
/usr/share/mime/globs:application/x-cd-image:*.iso9660
/usr/share/mime/types:application/x-cd-image
/usr/share/mime/application/x-cd-image.xml:<mime-type xmlns="http://www.freedesktop.org/standards/shared-mime-info" type="application/x-cd-image">
/usr/share/mime/globs2:50:application/x-cd-image:*.iso
/usr/share/mime/globs2:50:application/x-cd-image:*.iso9660
Binary file /usr/share/mime/mime.cache matches
/usr/share/mime/packages/freedesktop.org.xml:  <mime-type type="application/x-cd-image">

As you can see, globs are used to define *.iso as x-cd-image, so that's where that's coming from in spacefm. So no, mime types are not necessarily independent of file extension.

If you run:

grep -r "x-iso9660-image" /usr/share/mime

There is no output, meaning that type is not defined in freedesktop's database.

Likewise:

grep -r "x-trash" /usr/share/mime

/usr/share/mime/globs:application/x-trash:*.bak
/usr/share/mime/globs:application/x-trash:*.old
/usr/share/mime/globs:application/x-trash:*.sik
/usr/share/mime/globs:application/x-trash:*%
/usr/share/mime/globs:application/x-trash:*~
/usr/share/mime/types:application/x-trash
/usr/share/mime/application/x-trash.xml:<mime-type xmlns="http://www.freedesktop.org/standards/shared-mime-info" type="application/x-trash">
/usr/share/mime/globs2:50:application/x-trash:*.bak
/usr/share/mime/globs2:50:application/x-trash:*.old
/usr/share/mime/globs2:50:application/x-trash:*.sik
/usr/share/mime/globs2:50:application/x-trash:*%
/usr/share/mime/globs2:50:application/x-trash:*~
Binary file /usr/share/mime/mime.cache matches
/usr/share/mime/packages/freedesktop.org.xml:  <mime-type type="application/x-trash">

Other programs don't necessarily use freedesktop's database. For example, 'file' uses it's own database stored in /usr/share/file. xdg-mime is merely a wrapper that runs whatever mime typing program it can find, eg file, kfile, mimetype, gnomevfs-info, etc. spacefm doesn't run an external program (it would be far too slow for the number of files it needs to identify when opening a directory).

If for some reason you want *.iso to be identified as x-iso9660-image, you can create this type yourself and add it to your mime database, either as a user or system-wide.

http://www.freedesktop.org/wiki/Specifications/AddingMIMETutor
http://library.gnome.org/admin/system-admin-guide/stable/mimetypes-source-xml.html.en

The current spacefm next branch, which will become the release following 0.7.7, can create such xml files automatically. Right-click on a file, enter the Open submenu, right-click on one of the applications listed, then select the xml file. It will create the file, which you can then edit and rename to create your x-iso9660-image filetype. Then run

update-mime-database ~/.local/share/mime

which spacefm can also do (in the same app menu). That will be for your user only, but you can always install it to /usr/share/mime/packages to make it system-wide.

If you think freedesktop should identify *.iso as x-iso9660-image, you should file a request with them on that change - I don't know what the reason is for the difference.

spacefm also installs /usr/share/mime/packages/spacefm-mime.xml, which defines a few missing types (this file's contents predates spacefm). x-iso9660-image could be added there, but I'm not sure what the purpose would be or if it's worth deviating from the freedesktop database.

@tri1976
Copy link
Author

tri1976 commented May 30, 2012

Thank you for a comprehensive explanation. So, I guess spacefm uses file
extension to determine mime type. I do not need the mime type of a file to
be anything specific....I was just wondering how spacefm determines mime
type. Somehow, I have a notion that mime type should be independent of
file extension but when I change the file extension of file, spacefm mime
type changes (whereas "file" program consistently identifies it to be the
same mime type)

On Wed, May 30, 2012 at 1:30 PM, IgnorantGuru <
reply@reply.github.com

wrote:

spacefm gets its mime info from the mime database in freedesktop.org's shared-mime-info
package. If you run this:

grep -r "x-cd-image" /usr/share/mime

/usr/share/mime/globs:application/x-cd-image:.iso
/usr/share/mime/globs:application/x-cd-image:
.iso9660
/usr/share/mime/types:application/x-cd-image
/usr/share/mime/application/x-cd-image.xml:
/usr/share/mime/globs2:50:application/x-cd-image:.iso
/usr/share/mime/globs2:50:application/x-cd-image:
.iso9660
Binary file /usr/share/mime/mime.cache matches
/usr/share/mime/packages/freedesktop.org.xml:

As you can see, globs are used to define *.iso as x-cd-image, so that's
where that's coming from in spacefm. So no, mime types are not necessarily
independent of file extension.

If you run:

grep -r "x-iso9660-image" /usr/share/mime

There is no output, meaning that type is not defined in freedesktop's
database.

Likewise:

grep -r "x-trash" /usr/share/mime

/usr/share/mime/globs:application/x-trash:.bak
/usr/share/mime/globs:application/x-trash:
.old
/usr/share/mime/globs:application/x-trash:.sik
/usr/share/mime/globs:application/x-trash:
%
/usr/share/mime/globs:application/x-trash:_~
/usr/share/mime/types:application/x-trash
/usr/share/mime/application/x-trash.xml:
/usr/share/mime/globs2:50:application/x-trash:.bak
/usr/share/mime/globs2:50:application/x-trash:
.old
/usr/share/mime/globs2:50:application/x-trash:.sik
/usr/share/mime/globs2:50:application/x-trash:
%
/usr/share/mime/globs2:50:application/x-trash:_~
Binary file /usr/share/mime/mime.cache matches
/usr/share/mime/packages/freedesktop.org.xml:

Other programs don't necessarily use freedesktop's database. For example,
'file' uses it's own database stored in /usr/share/file. xdg-mime is
merely a wrapper that runs whatever mime typing program it can find, eg
file, kfile, mimetype, gnomevfs-info, etc. spacefm doesn't run an external
program (it would be far too slow for the number of files it needs to
identify when opening a directory).

If for some reason you want *.iso to be identified as x-iso9660-image, you
can create this type yourself and add it to your mime database, either as a
user or system-wide.

http://www.freedesktop.org/wiki/Specifications/AddingMIMETutor

http://library.gnome.org/admin/system-admin-guide/stable/mimetypes-source-xml.html.en

The current spacefm next branch, which will become the release following
0.7.7, can create such xml files automatically. Right-click on a file,
enter the Open submenu, right-click on one of the applications listed, then
select the xml file. It will create the file, which you can then edit and
rename to create your x-iso9660-image filetype. Then run

update-mime-database ~/.local/share/mime

which spacefm can also do (in the same app menu). That will be for your
user only, but you can always install it to /usr/share/mime/packages to
make it system-wide.

If you think freedesktop should identify *.iso as x-iso9660-image, you
should file a request with them on that change - I don't know what the
reason is for the difference.

spacefm also installs /usr/share/mime/packages/spacefm-mime.xml, which
defines a few missing types (this file's contents predates spacefm).
x-iso9660-image could be added there, but I'm not sure what the purpose
would be or if it's worth deviating from the freedesktop database.


Reply to this email directly or view it on GitHub:
#77 (comment)

@IgnorantGuru
Copy link
Owner

So, I guess spacefm uses file extension to determine mime type.

Not necessarily. spacefm uses the mime database on your system. Some mime types use globs in their definition (eg *.iso). Others use magic detection (examine the file contents to determine type). And some use a combination. This is defined in the mime database and the behavior for a given type can be customized how you like on your system. If you want it done automagically you can do so.

You can see this with files that have no extension - spacefm still knows the file type (depending on what the mime database has for magic on that file type).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants