[glib] documentportal: print warnings when document portal fails to initialize
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] documentportal: print warnings when document portal fails to initialize
- Date: Tue, 12 Jul 2016 22:12:47 +0000 (UTC)
commit bc7c030480ee9d9edbdacc91fd3d61a3e5092592
Author: Cosimo Cecchi <cosimo endlessm com>
Date: Tue Jul 12 15:11:12 2016 -0700
documentportal: print warnings when document portal fails to initialize
Instead of siletly failing or calling a method on a NULL instance.
gio/gdocumentportal.c | 36 +++++++++++++++++++++++++++++-------
1 files changed, 29 insertions(+), 7 deletions(-)
---
diff --git a/gio/gdocumentportal.c b/gio/gdocumentportal.c
index 91c7ea2..de71cf7 100644
--- a/gio/gdocumentportal.c
+++ b/gio/gdocumentportal.c
@@ -33,7 +33,7 @@
static GXdpDocuments *documents;
static char *documents_mountpoint;
-static void
+static gboolean
init_document_portal (void)
{
static gsize documents_inited = 0;
@@ -48,10 +48,24 @@ init_document_portal (void)
documents = gxdp_documents_proxy_new_sync (connection, 0,
"org.freedesktop.portal.Documents",
"/org/freedesktop/portal/documents",
- NULL, NULL);
- gxdp_documents_call_get_mount_point_sync (documents,
- &documents_mountpoint,
- NULL, NULL);
+ NULL, &error);
+ if (documents != NULL)
+ {
+ gxdp_documents_call_get_mount_point_sync (documents,
+ &documents_mountpoint,
+ NULL, &error);
+
+ if (error != NULL)
+ {
+ g_warning ("Cannot get document portal mount point: %s", error->message);
+ g_error_free (error);
+ }
+ }
+ else
+ {
+ g_warning ("Cannot create document portal proxy: %s", error->message);
+ g_error_free (error);
+ }
g_object_unref (connection);
}
@@ -64,20 +78,28 @@ init_document_portal (void)
g_once_init_leave (&documents_inited, 1);
}
+
+ return (documents != NULL && documents_mountpoint != NULL);
}
char *
g_document_portal_add_document (GFile *file,
GError **error)
{
- char *doc_path, *path, *basename;
+ char *doc_path, *basename;
char *doc_id = NULL;
char *doc_uri = NULL;
+ char *path = NULL;
GUnixFDList *fd_list = NULL;
int fd, fd_in;
gboolean ret;
- init_document_portal ();
+ if (!init_document_portal ())
+ {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "Document portal is not available");
+ goto out;
+ }
path = g_file_get_path (file);
fd = g_open (path, O_PATH | O_CLOEXEC);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]