From f2285773771c238299ff8c0f2d0be0df90714c4f Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Wed, 3 May 2017 13:53:39 +0200 Subject: [PATCH] run: Handle forwarding uris better We need to know if we're forwarding uris or files, because if we're doing uris we need to pass on non-file uris as-is. So, we enclose uris with "@@u @@" instead. This also properly (un)escapes the file uris --- common/flatpak-dir.c | 5 +++-- common/flatpak-run.c | 43 ++++++++++++++++++++++++------------------- doc/flatpak-run.xml | 3 ++- 3 files changed, 29 insertions(+), 22 deletions(-) diff --git a/common/flatpak-dir.c b/common/flatpak-dir.c index 473c2f0ef..bc112ec43 100644 --- a/common/flatpak-dir.c +++ b/common/flatpak-dir.c @@ -3426,9 +3426,10 @@ export_desktop_file (const char *app, { g_autofree char *arg = maybe_quote (old_argv[i]); - if (strcasecmp (arg, "%f") == 0 || - strcasecmp (arg, "%u") == 0) + if (strcasecmp (arg, "%f") == 0) g_string_append_printf (new_exec, " @@ %s @@", arg); + else if (strcasecmp (arg, "%u") == 0) + g_string_append_printf (new_exec, " @@u %s @@", arg); else g_string_append_printf (new_exec, " %s", arg); } diff --git a/common/flatpak-run.c b/common/flatpak-run.c index e87b327f8..23f4a0f6f 100644 --- a/common/flatpak-run.c +++ b/common/flatpak-run.c @@ -4236,6 +4236,7 @@ add_rest_args (const char *app_id, { g_autoptr(XdpDbusDocuments) documents = NULL; gboolean forwarding = FALSE; + gboolean forwarding_uri = FALSE; gboolean can_forward = TRUE; int i; @@ -4262,45 +4263,49 @@ add_rest_args (const char *app_id, for (i = 0; i < n_args; i++) { - if (file_forwarding && strcmp (args[i], "@@") == 0) + g_autoptr(GFile) file = NULL; + + if (file_forwarding && + (strcmp (args[i], "@@") == 0 || + strcmp (args[i], "@@u") == 0)) { + forwarding_uri = strcmp (args[i], "@@u") == 0; forwarding = !forwarding; continue; } if (can_forward && forwarding) { - g_autofree char *doc_id = NULL; - g_autofree char *basename = NULL; - gboolean file_uri; - const char *file; - char *doc_path; - - if (g_str_has_prefix (args[i], "file:")) + if (forwarding_uri) { - file_uri = TRUE; - file = args[i] + strlen ("file:"); + if (g_str_has_prefix (args[i], "file:")) + file = g_file_new_for_uri (args[i]); } else - { - file_uri = FALSE; - file = args[i]; - } + file = g_file_new_for_path (args[i]); + } - if (!forward_file (documents, app_id, file, &doc_id, error)) + if (file) + { + g_autofree char *doc_id = NULL; + g_autofree char *basename = NULL; + char *doc_path; + if (!forward_file (documents, app_id, flatpak_file_get_path_cached (file), + &doc_id, error)) return FALSE; - basename = g_path_get_basename (args[i]); + basename = g_file_get_basename (file); doc_path = g_build_filename (doc_mount_path, doc_id, basename, NULL); - if (file_uri) + if (forwarding_uri) { g_autofree char *path = doc_path; - doc_path = g_strconcat ("file:", path, NULL); + doc_path = g_filename_to_uri (path, NULL, NULL); + /* This should never fail */ + g_assert (doc_path != NULL); } g_debug ("Forwarding file '%s' as '%s' to %s", args[i], doc_path, app_id); - g_ptr_array_add (argv_array, doc_path); } else diff --git a/doc/flatpak-run.xml b/doc/flatpak-run.xml index 439f92350..0294a1508 100644 --- a/doc/flatpak-run.xml +++ b/doc/flatpak-run.xml @@ -386,7 +386,8 @@ key=v1;v2; If this option is specified, the remaining arguments are scanned, and all arguments that are enclosed between a pair of '@@' arguments are interpreted as file paths, exported in the document store, and passed to the command in the form of the - resulting document path. The exports are non-persistent and with read and write + resulting document path. Arguments between '@@u' and '@@' are considered uris, + and any file: uris are exported. The exports are non-persistent and with read and write permissions for the application.