flatpak: Add a command to list exported documents

This lists all the files that are exported, possibly limited
to a single app id.
tingping/wmclass
Matthias Clasen 2016-06-10 17:58:03 -04:00
parent 8281e614ce
commit 9c16751709
6 changed files with 243 additions and 0 deletions

View File

@ -29,6 +29,7 @@ flatpak_SOURCES = \
app/flatpak-builtins-document-export.c \
app/flatpak-builtins-document-unexport.c \
app/flatpak-builtins-document-info.c \
app/flatpak-builtins-document-list.c \
$(xdp_dbus_built_sources) \
$(NULL)

View File

@ -0,0 +1,145 @@
/*
* Copyright © 2016 Red Hat, Inc
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Authors:
* Matthias Clasen <mclasen@redhat.com>
*/
#include "config.h"
#include <locale.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include "libgsystem.h"
#include "libglnx/libglnx.h"
#include "document-portal/xdp-dbus.h"
#include "flatpak-builtins.h"
#include "flatpak-utils.h"
#include "flatpak-run.h"
static GOptionEntry options[] = {
{ NULL }
};
gboolean
flatpak_builtin_document_list (int argc, char **argv,
GCancellable *cancellable,
GError **error)
{
g_autoptr(GOptionContext) context = NULL;
g_autoptr(GDBusConnection) session_bus = NULL;
XdpDbusDocuments *documents;
g_autoptr(GVariant) apps = NULL;
g_autoptr(GVariantIter) iter = NULL;
const char *app_id;
const char *id;
const char *path;
context = g_option_context_new ("[APPID] - List exported files");
if (!flatpak_option_context_parse (context, options, &argc, &argv,
FLATPAK_BUILTIN_FLAG_NO_DIR,
NULL, cancellable, error))
return FALSE;
if (argc < 2)
app_id = "";
else
app_id = argv[1];
session_bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, error);
if (session_bus == NULL)
return FALSE;
documents = xdp_dbus_documents_proxy_new_sync (session_bus, 0,
"org.freedesktop.portal.Documents",
"/org/freedesktop/portal/documents",
NULL, error);
if (documents == NULL)
return FALSE;
if (!xdp_dbus_documents_call_list_sync (documents, app_id, &apps, NULL, error))
return FALSE;
iter = g_variant_iter_new (apps);
while (g_variant_iter_next (iter, "{&s^&ay}", &id, &path))
g_print ("%s\t%s\n", id, path);
return TRUE;
}
gboolean
flatpak_complete_document_list (FlatpakCompletion *completion)
{
g_autoptr(GOptionContext) context = NULL;
g_autoptr(FlatpakDir) user_dir = NULL;
g_autoptr(FlatpakDir) system_dir = NULL;
g_autoptr(GError) error = NULL;
int i;
context = g_option_context_new ("");
if (!flatpak_option_context_parse (context, options, &completion->argc, &completion->argv,
FLATPAK_BUILTIN_FLAG_NO_DIR, NULL, NULL, NULL))
return FALSE;
switch (completion->argc)
{
case 0:
case 1: /* APPID */
flatpak_complete_options (completion, global_entries);
flatpak_complete_options (completion, options);
user_dir = flatpak_dir_get_user ();
{
g_auto(GStrv) refs = flatpak_dir_find_installed_refs (user_dir, NULL, NULL, NULL,
TRUE, FALSE, &error);
if (refs == NULL)
flatpak_completion_debug ("find local refs error: %s", error->message);
for (i = 0; refs != NULL && refs[i] != NULL; i++)
{
g_auto(GStrv) parts = flatpak_decompose_ref (refs[i], NULL);
if (parts)
flatpak_complete_word (completion, "%s ", parts[1]);
}
}
system_dir = flatpak_dir_get_user ();
{
g_auto(GStrv) refs = flatpak_dir_find_installed_refs (system_dir, NULL, NULL, NULL,
TRUE, FALSE, &error);
if (refs == NULL)
flatpak_completion_debug ("find local refs error: %s", error->message);
for (i = 0; refs != NULL && refs[i] != NULL; i++)
{
g_auto(GStrv) parts = flatpak_decompose_ref (refs[i], NULL);
if (parts)
flatpak_complete_word (completion, "%s ", parts[1]);
}
}
break;
}
return TRUE;
}

View File

@ -80,6 +80,7 @@ BUILTINPROTO (build_update_repo)
BUILTINPROTO (document_export)
BUILTINPROTO (document_unexport)
BUILTINPROTO (document_info)
BUILTINPROTO (document_list)
BUILTINPROTO (override)
#undef BUILTINPROTO

View File

@ -68,6 +68,7 @@ static FlatpakCommand commands[] = {
{ "document-export", "Grant an application access to a specific file", flatpak_builtin_document_export, flatpak_complete_document_export },
{ "document-unexport", "Revoke access to a specific file", flatpak_builtin_document_unexport, flatpak_complete_document_unexport },
{ "document-info", "Show information about a specific file", flatpak_builtin_document_info, flatpak_complete_document_info },
{ "document-list", "List exported files", flatpak_builtin_document_list, flatpak_complete_document_list },
{ "\n Manage remote repositories" },
{ "remote-add", "Add a new remote repository (by URL)", flatpak_builtin_add_remote, flatpak_complete_add_remote },

View File

@ -33,6 +33,7 @@ man_MANS = \
flatpak-document-export.1 \
flatpak-document-unexport.1 \
flatpak-document-info.1 \
flatpak-document-list.1 \
flatpak-build-init.1 \
flatpak-build.1 \
flatpak-build-bundle.1 \

View File

@ -0,0 +1,94 @@
<?xml version='1.0'?> <!--*-nxml-*-->
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
<refentry id="flatpak-document-list">
<refentryinfo>
<title>flatpak document-list</title>
<productname>flatpak</productname>
<authorgroup>
<author>
<contrib>Developer</contrib>
<firstname>Alexander</firstname>
<surname>Larsson</surname>
<email>alexl@redhat.com</email>
</author>
</authorgroup>
</refentryinfo>
<refmeta>
<refentrytitle>flatpak document-list</refentrytitle>
<manvolnum>1</manvolnum>
</refmeta>
<refnamediv>
<refname>flatpak-document-list</refname>
<refpurpose>List exported files</refpurpose>
</refnamediv>
<refsynopsisdiv>
<cmdsynopsis>
<command>flatpak document-list</command>
<arg choice="opt" rep="repeat">OPTION</arg>
<arg choice="opt">APPID</arg>
</cmdsynopsis>
</refsynopsisdiv>
<refsect1>
<title>Description</title>
<para>
Lists exported files, with their document id and the
full path to their origin. If an APPID is specified,
only the files exported to this app are listed.
</para>
</refsect1>
<refsect1>
<title>Options</title>
<para>The following options are understood:</para>
<variablelist>
<varlistentry>
<term><option>-h</option></term>
<term><option>--help</option></term>
<listitem><para>
Show help options and exit.
</para></listitem>
</varlistentry>
<varlistentry>
<term><option>-v</option></term>
<term><option>--verbose</option></term>
<listitem><para>
Print debug information during command processing.
</para></listitem>
</varlistentry>
<varlistentry>
<term><option>--version</option></term>
<listitem><para>
Print version information and exit.
</para></listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
<title>See also</title>
<para>
<citerefentry><refentrytitle>flatpak</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
<citerefentry><refentrytitle>flatpak-document-export</refentrytitle><manvolnum>1</manvolnum></citerefentry>
</para>
</refsect1>
</refentry>