mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-04-17 12:58:48 +02:00
gio: do not cache document portal D-Bus proxy
By removing the cached global proxy in gdocumentportal.c, we can re-enable the checks for proper shutdown of the session bus connection in the dbus-appinfo.c test.
This commit is contained in:
parent
926ff8c6a7
commit
e24db62363
@ -37,56 +37,47 @@
|
|||||||
#define HAVE_O_CLOEXEC 1
|
#define HAVE_O_CLOEXEC 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static GXdpDocuments *documents;
|
|
||||||
static char *documents_mountpoint;
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
init_document_portal (void)
|
get_document_portal (GXdpDocuments **documents,
|
||||||
|
char **documents_mountpoint,
|
||||||
|
GError **error)
|
||||||
{
|
{
|
||||||
static gsize documents_inited = 0;
|
GDBusConnection *connection = NULL;
|
||||||
|
|
||||||
if (g_once_init_enter (&documents_inited))
|
*documents = NULL;
|
||||||
|
*documents_mountpoint = NULL;
|
||||||
|
|
||||||
|
connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, error);
|
||||||
|
if (connection == NULL)
|
||||||
{
|
{
|
||||||
GError *error = NULL;
|
g_prefix_error (error, "Cannot connect to session bus when initializing document portal: ");
|
||||||
GDBusConnection *connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
|
goto out;
|
||||||
|
|
||||||
if (connection != NULL)
|
|
||||||
{
|
|
||||||
documents = gxdp_documents_proxy_new_sync (connection, 0,
|
|
||||||
"org.freedesktop.portal.Documents",
|
|
||||||
"/org/freedesktop/portal/documents",
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
g_warning ("Cannot connect to session bus when initializing document portal: %s",
|
|
||||||
error->message);
|
|
||||||
g_error_free (error);
|
|
||||||
}
|
|
||||||
|
|
||||||
g_once_init_leave (&documents_inited, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (documents != NULL && documents_mountpoint != NULL);
|
*documents = gxdp_documents_proxy_new_sync (connection,
|
||||||
|
G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
|
||||||
|
G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
|
||||||
|
"org.freedesktop.portal.Documents",
|
||||||
|
"/org/freedesktop/portal/documents",
|
||||||
|
NULL, error);
|
||||||
|
if (*documents == NULL)
|
||||||
|
{
|
||||||
|
g_prefix_error (error, "Cannot create document portal proxy: ");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!gxdp_documents_call_get_mount_point_sync (*documents,
|
||||||
|
documents_mountpoint,
|
||||||
|
NULL, error))
|
||||||
|
{
|
||||||
|
g_clear_object (documents);
|
||||||
|
g_prefix_error (error, "Cannot get document portal mount point: ");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
out:
|
||||||
|
g_clear_object (&connection);
|
||||||
|
return *documents != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Flags accepted by org.freedesktop.portal.Documents.AddFull */
|
/* Flags accepted by org.freedesktop.portal.Documents.AddFull */
|
||||||
@ -102,6 +93,8 @@ g_document_portal_add_documents (GList *uris,
|
|||||||
const char *app_id,
|
const char *app_id,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
|
GXdpDocuments *documents = NULL;
|
||||||
|
char *documents_mountpoint = NULL;
|
||||||
int length;
|
int length;
|
||||||
GList *ruris = NULL;
|
GList *ruris = NULL;
|
||||||
gboolean *as_is;
|
gboolean *as_is;
|
||||||
@ -113,10 +106,8 @@ g_document_portal_add_documents (GList *uris,
|
|||||||
char **doc_ids = NULL;
|
char **doc_ids = NULL;
|
||||||
GVariant *extra_out = NULL;
|
GVariant *extra_out = NULL;
|
||||||
|
|
||||||
if (!init_document_portal ())
|
if (!get_document_portal (&documents, &documents_mountpoint, error))
|
||||||
{
|
{
|
||||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_INITIALIZED,
|
|
||||||
"Document portal is not available");
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,6 +204,8 @@ g_document_portal_add_documents (GList *uris,
|
|||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
g_clear_object (&documents);
|
||||||
|
g_clear_pointer (&documents_mountpoint, g_free);
|
||||||
g_clear_object (&fd_list);
|
g_clear_object (&fd_list);
|
||||||
g_clear_pointer (&extra_out, g_variant_unref);
|
g_clear_pointer (&extra_out, g_variant_unref);
|
||||||
g_clear_pointer (&doc_ids, g_strfreev);
|
g_clear_pointer (&doc_ids, g_strfreev);
|
||||||
|
@ -361,18 +361,10 @@ test_flatpak_doc_export (void)
|
|||||||
int
|
int
|
||||||
main (int argc, char **argv)
|
main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
int ret;
|
|
||||||
|
|
||||||
g_test_init (&argc, &argv, NULL);
|
g_test_init (&argc, &argv, NULL);
|
||||||
|
|
||||||
g_test_add_func ("/appinfo/dbusappinfo", test_dbus_appinfo);
|
g_test_add_func ("/appinfo/dbusappinfo", test_dbus_appinfo);
|
||||||
g_test_add_func ("/appinfo/flatpak-doc-export", test_flatpak_doc_export);
|
g_test_add_func ("/appinfo/flatpak-doc-export", test_flatpak_doc_export);
|
||||||
|
|
||||||
session_bus_up ();
|
return session_bus_run ();
|
||||||
ret = g_test_run ();
|
|
||||||
/* gdocumentportal.c holds a reference to the session bus
|
|
||||||
* connection, which prevents session_bus_down from completing
|
|
||||||
* successfully. */
|
|
||||||
session_bus_stop ();
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user