Skip to content

Commit

Permalink
document-portal: add snap support to app_has_file_access()
Browse files Browse the repository at this point in the history
This calls out to the "snap routine file-access" helper command, which
produces output compatible with "flatpak info --file-access".

While this command was only introduced in snapd 2.45, the failure mode
with old versions is consistent with the previous behaviour: assume the
snap does not have file access.
  • Loading branch information
jhenstridge authored and alexlarsson committed Dec 28, 2020
1 parent 5709648 commit 48a981e
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions document-portal/document-portal.c
Expand Up @@ -499,15 +499,16 @@ portal_add (GDBusMethodInvocation *invocation,
}

static char *
flatpak (GError **error,
...)
get_output (GError **error,
const char *argv0,
...)
{
gboolean res;
g_autofree char *output = NULL;
va_list ap;

va_start (ap, error);
res = xdp_spawn (NULL, &output, 0, error, "flatpak", ap);
va_start (ap, argv0);
res = xdp_spawn (NULL, &output, 0, error, argv0, ap);
va_end (ap);

if (res)
Expand Down Expand Up @@ -632,9 +633,17 @@ app_has_file_access (const char *target_app_id,
if (target_app_id == NULL || target_app_id[0] == '\0')
return FALSE;

/* First we try flatpak info --file-access=PATH APPID, which is supported on new versions */
arg = g_strdup_printf ("--file-access=%s", path);
res = flatpak (&error, "info", arg, target_app_id, NULL);
if (g_str_has_prefix (target_app_id, "snap."))
{
res = get_output (&error, "snap", "routine", "file-access",
target_app_id + strlen ("snap."), path, NULL);
}
else
{
/* First we try flatpak info --file-access=PATH APPID, which is supported on new versions */
arg = g_strdup_printf ("--file-access=%s", path);
res = get_output (&error, "flatpak", "info", arg, target_app_id, NULL);
}

if (res)
{
Expand Down

0 comments on commit 48a981e

Please sign in to comment.