flatpak: Add a document-info command

This uses the newly introduced non-portal interface to the
documents portal to obtain and show information about an
exported file.
tingping/wmclass
Matthias Clasen 2016-06-10 15:01:01 -04:00
parent 89a10ad9b2
commit 52d32da215
6 changed files with 270 additions and 1 deletions

View File

@ -26,7 +26,8 @@ flatpak_SOURCES = \
app/flatpak-builtins-build-import-bundle.c \
app/flatpak-builtins-build-sign.c \
app/flatpak-builtins-repo-update.c \
app/flatpak-builtins-document.c \
app/flatpak-builtins-document-export.c \
app/flatpak-builtins-document-info.c \
$(xdp_dbus_built_sources) \
$(NULL)

View File

@ -0,0 +1,151 @@
/*
* 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 <gio/gunixfdlist.h>
#include "flatpak-builtins.h"
#include "flatpak-utils.h"
#include "flatpak-run.h"
static GOptionEntry options[] = {
{ NULL }
};
gboolean
flatpak_builtin_document_info (int argc, char **argv,
GCancellable *cancellable,
GError **error)
{
g_autoptr(GOptionContext) context = NULL;
g_autoptr(GDBusConnection) session_bus = NULL;
const char *file;
XdpDbusDocuments *documents;
g_autofree char *mountpoint = NULL;
g_autofree char *basename = NULL;
g_autofree char *doc_id = NULL;
g_autofree char *doc_path = NULL;
g_autofree char *origin = NULL;
const char *app_id;
const char **perms;
g_autoptr(GVariant) apps = NULL;
g_autoptr(GVariantIter) iter = NULL;
context = g_option_context_new ("FILE - Get information about an exported file");
if (!flatpak_option_context_parse (context, options, &argc, &argv,
FLATPAK_BUILTIN_FLAG_NO_DIR,
NULL, cancellable, error))
return FALSE;
if (argc < 2)
return usage_error (context, "FILE must be specified", error);
file = argv[1];
basename = g_path_get_basename (file);
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_get_mount_point_sync (documents, &mountpoint,
NULL, error))
return FALSE;
if (!xdp_dbus_documents_call_lookup_sync (documents, file, &doc_id, NULL, error))
return FALSE;
if (strcmp (doc_id, "") == 0)
{
g_print ("Not exported\n");
return TRUE;
}
doc_path = g_build_filename (mountpoint, doc_id, basename, NULL);
if (!xdp_dbus_documents_call_info_sync (documents, doc_id, &origin, &apps,
NULL, error))
return FALSE;
iter = g_variant_iter_new (apps);
g_print ("id: %s\n", doc_id);
g_print ("path: %s\n", doc_path);
g_print ("origin: %s\n", origin);
if (g_variant_iter_n_children (iter) > 0)
g_print ("permissions:\n");
while (g_variant_iter_next (iter, "{&s^a&s}", &app_id, &perms))
{
int i;
g_print ("\t%s\t", app_id);
for (i = 0; perms[i]; i++)
{
if (i > 0)
g_print (", ");
g_print ("%s", perms[i]);
}
g_print ("\n");
}
return TRUE;
}
gboolean
flatpak_complete_document_info (FlatpakCompletion *completion)
{
g_autoptr(GOptionContext) context = NULL;
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: /* FILE */
flatpak_complete_options (completion, global_entries);
flatpak_complete_options (completion, options);
flatpak_complete_file (completion);
break;
}
return TRUE;
}

View File

@ -78,6 +78,7 @@ BUILTINPROTO (build_bundle)
BUILTINPROTO (build_import)
BUILTINPROTO (build_update_repo)
BUILTINPROTO (document_export)
BUILTINPROTO (document_info)
BUILTINPROTO (override)
#undef BUILTINPROTO

View File

@ -62,6 +62,7 @@ static FlatpakCommand commands[] = {
{ "run", "Run an application", flatpak_builtin_run, flatpak_complete_run },
{ "override", "Override permissions for an application", flatpak_builtin_override, flatpak_complete_override },
{ "document-export", "Grant an application access to a specific file", flatpak_builtin_document_export, flatpak_complete_document_export },
{ "document-info", "Show information about a specific file", flatpak_builtin_document_info, flatpak_complete_document_info },
{ "make-current", "Specify default version to run", flatpak_builtin_make_current_app, flatpak_complete_make_current_app },
{ "enter", "Enter the namespace of a running application", flatpak_builtin_enter, flatpak_complete_enter },

View File

@ -31,6 +31,7 @@ man_MANS = \
flatpak-override.1 \
flatpak-enter.1 \
flatpak-document-export.1 \
flatpak-document-info.1 \
flatpak-build-init.1 \
flatpak-build.1 \
flatpak-build-bundle.1 \

View File

@ -0,0 +1,114 @@
<?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-info">
<refentryinfo>
<title>flatpak document-info</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-info</refentrytitle>
<manvolnum>1</manvolnum>
</refmeta>
<refnamediv>
<refname>flatpak-document-info</refname>
<refpurpose>Show information about exported files</refpurpose>
</refnamediv>
<refsynopsisdiv>
<cmdsynopsis>
<command>flatpak document-info</command>
<arg choice="opt" rep="repeat">OPTION</arg>
<arg choice="plain">FILE</arg>
</cmdsynopsis>
</refsynopsisdiv>
<refsect1>
<title>Description</title>
<para>
Shows information about an exported file, such as the
document id, the fuse path, the original location in the
filesystem, and the per-application permissions.
</para>
<para>
FILE can either be a file in the fuse filesystem at /run/user/$UID/doc/,
or a file anywhere else.
</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>Examples</title>
<para>
<command>$ flatpak document-info ~/Sources/gtk/gail-3.0.pc</command>
</para>
<programlisting>
id: dd32c34a
path: /run/user/1000/doc/dd32c34a/gail-3.0.pc
origin: /home/mclasen/Sources/gtk/gail-3.0.pc
permissions:
org.gnome.gedit read, write
</programlisting>
</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>