Tuesday, December 16, 2008

GNOME vfs mime-type problem

Every once in a while, I seem to suffer a problem where GNOME does not properly recognize mime-type of my files anymore. For example, the PDF file on my desktop is treated as a text file by default, to be opened by "Text Editor" while it's supposed to be opened by "Document Viewer" (left figure depicts the problematic one, while the right figure depicts how it's supposed to look like).

Even if I tried to open the PDF directly with Evince, it tells me that it is unable to open a document of the text/plain type, as seen in the figure below.
Application launchers on my desktop (here shown for ies4linux) are also not recognized. The files are shown as *.desktop files, and when I double click on it, Text Editor comes up and shows me the metadata for the application launcher as opposed to starting the application.
It turns out the problem is that file permissions under /usr/share/mime is messed up. Only root can read and write the files, and nobody else can read them. These files are part of the shared mime-info database generated by /usr/bin/update-mime-database (typically run by package manager as root), and this is how GNOME vfs (or any freedesktop.org compliant desktop environment such as KDE) determines the mime-type of a file.
The reason these files are generated with root-only access is that I set my umask to a pretty strict 0077 (own user full access, group and others no access), and sometimes the update-mime-database program runs under that umask. Not sure whose fault it is because I've never seen package manager suffer that problem. But here is how to fix it.
umask 0022
sudo /usr/bin/update-mime-database /usr/share/mime
And that fixes the problem.
Post a Comment