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
This commit is contained in:
Alexander Larsson committed 2017-05-03 13:53:39 +02:00
1 parent 5013601c41
commit f228577377
3 files changed
+29 -22

No files matched your search

+3 -2
View File
@@ -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);
}
+24 -19
View File
@@ -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
+2 -1
View File
@@ -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.
</para></listitem>
</varlistentry>