After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 678944 - gio returns the wrong default applications for some types
gio returns the wrong default applications for some types
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gio
2.32.x
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2012-06-27 08:35 UTC by Sebastien Bacher
Modified: 2012-06-28 13:40 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Fix default app lookup wrt parent types and defaults.list (1.54 KB, patch)
2012-06-28 12:54 UTC, Alexander Larsson
none Details | Review

Description Sebastien Bacher 2012-06-27 08:35:08 UTC
Using glib 2.32.3 on Ubuntu precise (the same issue happens on a fedora 17 liveCD though):

$ gvfs-mime --query application/x-gnome-saved-search

Default application for 'application/x-gnome-saved-search': firefox.desktop
Registered applications:
	firefox.desktop
	nautilus.desktop
	gedit.desktop
Recommended applications:
	nautilus.desktop

Only nautilus claims to handle "application/x-gnome-saved-search" in its desktop. The type is subclass of xml that's why the other choices are listed, but the "recommended" choice is nautilus.desktop and it should also be the default one since that's the only handle for the exact type...
Comment 1 Sebastien Bacher 2012-06-27 08:43:45 UTC
gvfs-mime simply calls "g_app_info_get_default_for_type (mimetype, FALSE);"

that simple command shows the bug as well:

$ python -c 'import gio; print gio.app_info_get_default_for_type("application/x-gnome-saved-search", False).get_name()'
Firefox Web Browser

There is a similar issue described on https://bugs.launchpad.net/ubuntu/+source/gvfs/+bug/949823 with "application/x-java-jnlp-file" files (which is also a subclass of xml)
Comment 2 Sebastien Bacher 2012-06-27 13:49:06 UTC
the issue is in gdesktopappinfo.c get_all_desktop_entries_for_mime_type()

...
  for (i = 0; mime_types[i] != NULL; i++)
...
          /* Pick the explicit default application if we got no result earlier
           * (ie, for more specific mime types)
           */
          if (desktop_entries == NULL)
            {
              entry = g_hash_table_lookup (dir->mimeapps_list_defaults_map, mime_type);
              if (entry != NULL)
                {
                  /* Save the default entry if it's the first one we encounter */
                  if (default_entry == NULL)
                    default_entry = g_strdup (entry);
                }
            }
...

so the code goes through the mimetype and it's subclasses:
application/x-gnome-saved-search -> not in defaults.list, do nothing
text/xml -> ubuntu has firefox.xml listed, it uses it

it doesn't look right to pick the preferred handler for a subclassed mimetype over an available handler for the exact mimetype
Comment 3 Sebastien Bacher 2012-06-27 14:55:16 UTC
would it be better to do something like

"              if (entry != NULL)
...
              else 
               {
                GList *entry_list;
                entry_list = g_hash_table_lookup (dir->mime_info_cache_map, mime_type);
                if (entry_list != NULL)
                  {
                    /* Just pick an handler for the type otherwise */
                    if (default_entry == NULL)
                      default_entry = g_strdup (entry_list->data);
                  }
               }"

i.e "try to get the default handler for the type and if there is none just pick the first handler in the list"?
Comment 4 Alexander Larsson 2012-06-28 12:54:12 UTC
Created attachment 217520 [details] [review]
Fix default app lookup wrt parent types and defaults.list

There was an issue when looking up the default handler
for a type where a supertype was listed in defaults.list.
We would pick the default for the parent type even if
there was a handler for the more specific type.

In the case of the new-style defaults marking (
"Default Applications" in mimeapps.list) we were already
checking for a more specific handler befor using a default,
but we also need to do a similar check for the defaults.list
case.
Comment 5 Sebastien Bacher 2012-06-28 13:02:47 UTC
the patch indeed fixes the issue!
Comment 6 Alexander Larsson 2012-06-28 13:39:52 UTC
There is a bug in this where it ignores the defaults.list contents wrongly in some cases, fixed in:

http://git.gnome.org/browse/glib/commit/?id=c35106fcc4a736a2cdd3566042da15216dea415b