Commit 796599a7 authored by Ondrej Holy's avatar Ondrej Holy

gio-tool: Do not alter uris before use

Uris may be altered by the following code, which breaks xdg-open:
file = g_file_new_for_commandline_arg (arg[i])
uri = g_file_get_uri (file);

Examples of possible uri changes:
mailto:email -> mailto:///email
magnet:?xt=urn:hash -> magnet:///?xt=urn:hash
ssh://user@host -> sftp://user@host

This patch causes that uris aren't preprocessed for locations with
scheme, however absolute and relative paths are still preprocessed.
parent fac219ad
......@@ -146,16 +146,28 @@ handle_open (int argc, char *argv[], gboolean do_help)
success = TRUE;
for (i = 1; i < argc; i++)
GFile *file;
char *uri;
char *uri = NULL;
char *uri_scheme;
/* Workaround to handle non-URI locations. We still use the original
* location for other cases, because GFile might modify the URI in ways
* we don't want. See:
* */
uri_scheme = g_uri_parse_scheme (argv[i]);
if (!uri_scheme || uri_scheme[0] == '\0')
GFile *file;
file = g_file_new_for_commandline_arg (argv[i]);
uri = g_file_get_uri (file);
res = g_app_info_launch_default_for_uri (uri, NULL, &error);
file = g_file_new_for_commandline_arg (argv[i]);
uri = g_file_get_uri (file);
g_object_unref (file);
g_free (uri_scheme);
res = g_app_info_launch_default_for_uri (uri ? uri : argv[i], NULL, &error);
if (!res)
print_file_error (file, error->message);
print_error ("%s: %s", uri ? uri : argv[i], error->message);
g_clear_error (&error);
success = FALSE;
......@@ -169,7 +181,7 @@ handle_open (int argc, char *argv[], gboolean do_help)
char *bus_name = NULL;
char *object_path = NULL;
if (get_bus_name_and_path_from_uri (uri, &bus_name, &object_path))
if (get_bus_name_and_path_from_uri (uri ? uri : argv[i], &bus_name, &object_path))
GDBusConnection *connection;
connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
......@@ -189,7 +201,6 @@ handle_open (int argc, char *argv[], gboolean do_help)
g_object_unref (file);
g_free (uri);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment