summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhaedrus Leeds <mwleeds@protonmail.com>2021-11-22 16:15:34 -0800
committerPhaedrus Leeds <mwleeds@protonmail.com>2021-11-22 16:15:36 -0800
commit0ede94cff026db2a622bc3841173c8440e4e9391 (patch)
tree1b91ebdc1d48d29103278725141040341d327a2f
parentfb04c1b0ef3cd2cfde5dbc57bd9ad8b47cfc52f2 (diff)
downloadflatpak-docid-unexport-revived.tar.gz
document-unexport: Finish implementing --doc-iddocid-unexport-revived
Picking up Matthias' commit from a few years ago to get it mergeable.
-rw-r--r--app/flatpak-builtins-document-unexport.c45
-rw-r--r--doc/flatpak-document-unexport.xml10
2 files changed, 51 insertions, 4 deletions
diff --git a/app/flatpak-builtins-document-unexport.c b/app/flatpak-builtins-document-unexport.c
index 402544ab..66e0933e 100644
--- a/app/flatpak-builtins-document-unexport.c
+++ b/app/flatpak-builtins-document-unexport.c
@@ -37,10 +37,10 @@
#include "flatpak-utils-private.h"
#include "flatpak-run-private.h"
-static gboolean opt_docid;
+static gboolean opt_doc_id;
static GOptionEntry options[] = {
- { "docid", 0, 0, G_OPTION_ARG_NONE, &opt_docid, N_("Specify the document ID"), NULL },
+ { "doc-id", 0, 0, G_OPTION_ARG_NONE, &opt_doc_id, N_("Specify the document ID"), NULL },
{ NULL }
};
@@ -82,7 +82,7 @@ flatpak_builtin_document_unexport (int argc, char **argv,
if (documents == NULL)
return FALSE;
- if (opt_docid)
+ if (opt_doc_id)
doc_id = g_strdup (file);
else if (!xdp_dbus_documents_call_lookup_sync (documents, file, &doc_id, NULL, error))
return FALSE;
@@ -99,10 +99,43 @@ flatpak_builtin_document_unexport (int argc, char **argv,
return TRUE;
}
+static gboolean
+_complete_document_ids (FlatpakCompletion *completion,
+ GError **error)
+{
+ g_autoptr(GDBusConnection) session_bus = NULL;
+ XdpDbusDocuments *documents;
+ g_autoptr(GVariant) apps = NULL;
+ g_autoptr(GVariantIter) iter = NULL;
+ const char *id;
+ const char *origin;
+
+ 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, "", &apps, NULL, error))
+ return FALSE;
+
+ iter = g_variant_iter_new (apps);
+ while (g_variant_iter_next (iter, "{&s^&ay}", &id, &origin))
+ flatpak_complete_word (completion, "%s ", id);
+
+ return TRUE;
+}
+
gboolean
flatpak_complete_document_unexport (FlatpakCompletion *completion)
{
g_autoptr(GOptionContext) context = NULL;
+ g_autoptr(GError) error = NULL;
context = g_option_context_new ("");
@@ -117,7 +150,11 @@ flatpak_complete_document_unexport (FlatpakCompletion *completion)
flatpak_complete_options (completion, global_entries);
flatpak_complete_options (completion, options);
- flatpak_complete_file (completion, "__FLATPAK_FILE");
+ if (!opt_doc_id)
+ flatpak_complete_file (completion, "__FLATPAK_FILE");
+ else if (!_complete_document_ids (completion, &error))
+ flatpak_completion_debug ("complete document ids error: %s", error->message);
+
break;
}
diff --git a/doc/flatpak-document-unexport.xml b/doc/flatpak-document-unexport.xml
index d2be2079..fe7e9fed 100644
--- a/doc/flatpak-document-unexport.xml
+++ b/doc/flatpak-document-unexport.xml
@@ -54,6 +54,16 @@
<variablelist>
<varlistentry>
+ <term><option>--doc-id</option></term>
+
+ <listitem><para>
+ Interpret <arg choice="plain">FILE</arg> as a document ID
+ rather than a file path. This is useful for example when
+ the file has been deleted.
+ </para></listitem>
+ </varlistentry>
+
+ <varlistentry>
<term><option>-h</option></term>
<term><option>--help</option></term>