diff --git a/app/Makefile.am.inc b/app/Makefile.am.inc
index fa678ce0..b080df62 100644
--- a/app/Makefile.am.inc
+++ b/app/Makefile.am.inc
@@ -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)
diff --git a/app/flatpak-builtins-document-info.c b/app/flatpak-builtins-document-info.c
new file mode 100644
index 00000000..1985ae5a
--- /dev/null
+++ b/app/flatpak-builtins-document-info.c
@@ -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 .
+ *
+ * Authors:
+ * Matthias Clasen
+ */
+
+#include "config.h"
+
+#include
+#include
+#include
+#include
+#include
+
+#include "libgsystem.h"
+#include "libglnx/libglnx.h"
+#include "document-portal/xdp-dbus.h"
+
+#include
+
+#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;
+}
diff --git a/app/flatpak-builtins.h b/app/flatpak-builtins.h
index d5d181b7..ff870d21 100644
--- a/app/flatpak-builtins.h
+++ b/app/flatpak-builtins.h
@@ -78,6 +78,7 @@ BUILTINPROTO (build_bundle)
BUILTINPROTO (build_import)
BUILTINPROTO (build_update_repo)
BUILTINPROTO (document_export)
+BUILTINPROTO (document_info)
BUILTINPROTO (override)
#undef BUILTINPROTO
diff --git a/app/flatpak-main.c b/app/flatpak-main.c
index 1e67e39a..e6855af4 100644
--- a/app/flatpak-main.c
+++ b/app/flatpak-main.c
@@ -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 },
diff --git a/doc/Makefile.am b/doc/Makefile.am
index ce889e62..30f2a41e 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -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 \
diff --git a/doc/flatpak-document-info.xml b/doc/flatpak-document-info.xml
new file mode 100644
index 00000000..b833acca
--- /dev/null
+++ b/doc/flatpak-document-info.xml
@@ -0,0 +1,114 @@
+
+
+
+
+
+
+ flatpak document-info
+ flatpak
+
+
+
+ Developer
+ Alexander
+ Larsson
+ alexl@redhat.com
+
+
+
+
+
+ flatpak document-info
+ 1
+
+
+
+ flatpak-document-info
+ Show information about exported files
+
+
+
+
+ flatpak document-info
+ OPTION
+ FILE
+
+
+
+
+ Description
+
+
+ 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.
+
+
+ FILE can either be a file in the fuse filesystem at /run/user/$UID/doc/,
+ or a file anywhere else.
+
+
+
+
+
+ Options
+
+ The following options are understood:
+
+
+
+
+
+
+
+ Show help options and exit.
+
+
+
+
+
+
+
+
+ Print debug information during command processing.
+
+
+
+
+
+
+
+ Print version information and exit.
+
+
+
+
+
+
+ Examples
+
+
+ $ flatpak document-info ~/Sources/gtk/gail-3.0.pc
+
+
+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
+
+
+
+
+
+ See also
+
+
+ flatpak1,
+ flatpak-document-export1
+
+
+
+
+