xdg-open should use xdg-mime instead of run-mailcap when no DE detected

Bug #220765 reported by John Carlyle-Clarke
44
This bug affects 8 people
Affects Status Importance Assigned to Milestone
Xdg-utils
Fix Released
Medium
xdg-utils (Ubuntu)
Fix Released
Low
Unassigned

Bug Description

Binary package hint: xdg-utils

xdg-utils 1.0.1-2 on Ubuntu Gutsy

When no desktop environment is detected, xdg-open falls back to a generic mechanism based on run-mailcap. This is rather limited as it depends on file extensions. It would seem better to use file or probably xdg-mime to choose how to open the file.

The mime type could be fetched with:

file --mime "$1"

and extracted from the output and prepended to the filename before passing to run-mailcap.

However, it looks to me like a better option would be to use xdg-mime, since xdg-mime query default "$1" will give you the default application to open the file.

Revision history for this message
auquicu (agsimo) wrote :

xdg-open is broken on Ubuntu, and the suggested change would not improve it.
The whole idea of having xdg-utils is to have a uniform utility that works the same on all distributions.
Now xdg-open honors the BROWSER environment variable, but Ubuntu patches it to use run-mailcap instead, thus introducing two important differences between distributions.
If a utility needs a browser and asks vanilla xdg-open it will get one. But on Ubuntu the patched xdg-open may give some random utility such as
html2text. This means that Ubuntu breaks all such utilities.

Revision history for this message
Lei Zhang (thestig-google) wrote :

Indeed. As an example, run-mailcap doesn't know how to handle directories. So on non-KDE/Gnome desktops, xdg-open /home fail.

The fix is simple - do what upstream xdg-open does. Rather than bailing out when run-mailcap fails, fallback to sensible-browser. Attached are *trivial* patches for Hardy and Jaunty/Karmic.

Revision history for this message
In , Lei Zhang (thestig-google) wrote :

Upstreaming https://bugs.launchpad.net/ubuntu/+source/xdg-utils/+bug/220765

Original report:
----
When no desktop environment is detected, xdg-open falls back to a generic mechanism based on run-mailcap. This is rather limited as it depends on file extensions. It would seem better to use file or probably xdg-mime to choose how to open the file.

The mime type could be fetched with:

file --mime "$1"

and extracted from the output and prepended to the filename before passing to run-mailcap.

However, it looks to me like a better option would be to use xdg-mime, since xdg-mime query default "$1" will give you the default application to open the file.
----

IMO, xdg-mime does a better job of figuring out what program to open a given file with. xdg-mime also uses defaults.list, which might be part of a fd.o spec? OTOH, run-mailcap is a Debian-ism that doesn't exist on all distros. Thus in open_generic(), we should try to use xdg-mime first before falling back to run-mailcap.

Revision history for this message
Lei Zhang (thestig-google) wrote :
Revision history for this message
In , Tuxdev103 (tuxdev103) wrote :

Created an attachment (id=30974)
look up mime type and association and run associated app if possible

The original comes from Slackware's xdg-utils-1.0.2. Not sure where run-mailcap fits in here exactly..

Changed in xdg-utils:
status: Unknown → In Progress
Revision history for this message
In , Lei Zhang (thestig-google) wrote :

Ping. The patch posted in comment 1 looks decent. Can you review?

Revision history for this message
In , Fathi Boudra (fboudra) wrote :

The proposed patch couldn't be commited as-is.
I commited another fix based on the proposal:
http://webcvs.freedesktop.org/portland/portland/xdg-utils/scripts/xdg-open.in?r1=1.25&r2=1.26

Let me know if you have a regression or if I missed something ;)

Changed in xdg-utils:
status: In Progress → Fix Released
Changed in xdg-utils:
importance: Unknown → Medium
Revision history for this message
danmb (danmbox) wrote :

Why hasn't the patch been incorporated? It's absolutely ridiculous that xdg-mime and xdg-open do entirely different things. I'm using Lucid and still this is a problem (Google Chrome uses xdg-open and I have no desktop env)

Revision history for this message
Pavlo Bohmat (bohm) wrote :
Download full text (5.5 KiB)

I have only fluxbox, not DE. Ubuntu 10.10
Still this is a problem Chromium 10.0.608.0 (68926) uses xdg-open and enters into a stupor at the "Open" the saved file, or "Always open files of this type" !!! Vicious cycle of downloads: browser -> xdg, xdg-> browser and so again 50-60 download!!! a distribution for people, what place?
I have the same problem with chromium and transmission-gtk, to add torrent to my transmission-gtk. Browser itself opens a file with xdg...

 ~$ chromium-browser
Gtk-Message: (for origin information, set GTK_DEBUG): failed to retrieve property `gtk-enable-event-sounds' of type `gboolean' from rc file value "((GString*) 0x7f8ba5484900)" of type `gboolean'
Gtk-Message: (for origin information, set GTK_DEBUG): failed to retrieve property `gtk-enable-input-feedback-sounds' of type `gboolean' from rc file value "((GString*) 0x7f8ba5484760)" of type `gboolean'
Gtk-Message: (for origin information, set GTK_DEBUG): failed to retrieve property `gtk-button-images' of type `gboolean' from rc file value "((GString*) 0x7f8ba54846e0)" of type `gboolean'
Gtk-Message: (for origin information, set GTK_DEBUG): failed to retrieve property `gtk-menu-images' of type `gboolean' from rc file value "((GString*) 0x7f8ba5484860)" of type `gboolean'
[4653:4667:23525915482:ERROR:chrome/browser/extensions/extension_protocols.cc(135)] Denying load of chrome-extension://hcamnijgggppihioleoenjmlnakejdph/sounds/boing.mp3 from about:blank because the extension does not have access to the requesting page.
[4653:4667:23525988469:ERROR:chrome/browser/extensions/extension_protocols.cc(135)] Denying load of chrome-extension://gffjhibehnempbkeheiccaincokdjbfe/notify.mp3 from about:blank because the extension does not have access to the requesting page.
[4653:4667:23526167546:ERROR:chrome/browser/extensions/extension_protocols.cc(135)] Denying load of chrome-extension://hcamnijgggppihioleoenjmlnakejdph/sounds/boing.mp3 from about:blank because the extension does not have access to the requesting page.
sh: transmission: not found
Warning: program returned non-zero exit code #127
Gtk-Message: (for origin information, set GTK_DEBUG): failed to retrieve property `gtk-enable-event-sounds' of type `gboolean' from rc file value "((GString*) 0x7febbc8ad900)" of type `gboolean'
Gtk-Message: (for origin information, set GTK_DEBUG): failed to retrieve property `gtk-enable-input-feedback-sounds' of type `gboolean' from rc file value "((GString*) 0x7febbc8ad760)" of type `gboolean'
Gtk-Message: (for origin information, set GTK_DEBUG): failed to retrieve property `gtk-button-images' of type `gboolean' from rc file value "((GString*) 0x7febbc8ad6e0)" of type `gboolean'
In the current browser session creates a new window.
sh: transmission: not found
Warning: program returned non-zero exit code #127
Gtk-Message: (for origin information, set GTK_DEBUG): failed to retrieve property `gtk-enable-event-sounds' of type `gboolean' from rc file value "((GString*) 0x7f99ce115900)" of type `gboolean'
Gtk-Message: (for origin information, set GTK_DEBUG): failed to retrieve property `gtk-enable-input-feedback-sounds' of type `gboolean' from rc file value "((GString*) 0x7f99ce115760)" of...

Read more...

Revision history for this message
danmb (danmbox) wrote :

Workaround available in my PPA,

https://launchpad.net/~danmbox/+archive/ppa

With a backported xdg-utils from Maverick plus two pathes picked up from upstream (freedesktop.org) the problem is solved. Let's hope for a new release in natty, followed by a Lucid backport. This is not an acceptable state of affairs for an LTS release.

Changed in xdg-utils:
importance: Medium → Unknown
Revision history for this message
Pavlo Bohmat (bohm) wrote :

Chromium 11.0.654.0 (73098) Ubuntu "Natty" and xdg-utils_1.1.0~rc1-1_all.deb :OK

Changed in xdg-utils:
importance: Unknown → Medium
Revision history for this message
Sebastien Bacher (seb128) wrote :

the fix is in the current version of Ubuntu

Changed in xdg-utils (Ubuntu):
importance: Undecided → Low
status: New → Fix Released
Revision history for this message
Ben (ben2talk) wrote :

Is this bug responsible for my files opening (via Chromium/Miro) with Nautilus instead of the correct mime assocated in Nautilus?

i.e. If I open files in Nautilus, behaviour is normal (torrent > Deluge etc) but if I download a .torrent in Chromium, it opens with Nautilus - and from there it opens normally with Deluge.

Why does everything open with Nautilus from applications?

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Related questions

Remote bug watches

Bug watches keep track of this bug in other bug trackers.