From 69dcbc83d8bc8315b38b46609afef7c0e44105e8 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 12 Jul 2019 11:30:30 -0400 Subject: [PATCH 1/3] portal: Add a getter for dconf access Add method to find whether the sandbox provides access to dconf. This will be used to tweak the priorities for the keyfile settings backend. --- gio/gportalsupport.c | 18 ++++++++++++++++++ gio/gportalsupport.h | 1 + 2 files changed, 19 insertions(+) diff --git a/gio/gportalsupport.c b/gio/gportalsupport.c index 2f1e82517..b0a94b360 100644 --- a/gio/gportalsupport.c +++ b/gio/gportalsupport.c @@ -23,6 +23,7 @@ static gboolean flatpak_info_read; static gboolean use_portal; static gboolean network_available; +static gboolean dconf_access; static void read_flatpak_info (void) @@ -40,11 +41,13 @@ read_flatpak_info (void) use_portal = TRUE; network_available = FALSE; + dconf_access = FALSE; keyfile = g_key_file_new (); if (g_key_file_load_from_file (keyfile, path, G_KEY_FILE_NONE, NULL)) { char **shared = NULL; + char *dconf_policy = NULL; shared = g_key_file_get_string_list (keyfile, "Context", "shared", NULL, NULL); if (shared) @@ -52,6 +55,14 @@ read_flatpak_info (void) network_available = g_strv_contains ((const char * const *)shared, "network"); g_strfreev (shared); } + + dconf_policy = g_key_file_get_string (keyfile, "Session Bus Policy", "ca.desrt.dconf", NULL); + if (dconf_policy) + { + if (strcmp (dconf_policy, "talk") == 0) + dconf_access = TRUE; + g_free (dconf_policy); + } } g_key_file_unref (keyfile); @@ -64,6 +75,7 @@ read_flatpak_info (void) if (var && var[0] == '1') use_portal = TRUE; network_available = TRUE; + dconf_access = TRUE; } } @@ -81,3 +93,9 @@ glib_network_available_in_sandbox (void) return network_available; } +gboolean +glib_has_dconf_access_in_sandbox (void) +{ + read_flatpak_info (); + return dconf_access; +} diff --git a/gio/gportalsupport.h b/gio/gportalsupport.h index a331f45d3..746f1fd6b 100644 --- a/gio/gportalsupport.h +++ b/gio/gportalsupport.h @@ -24,6 +24,7 @@ G_BEGIN_DECLS gboolean glib_should_use_portal (void); gboolean glib_network_available_in_sandbox (void); +gboolean glib_has_dconf_access_in_sandbox (void); G_END_DECLS From 0ef6ccab351f64f9768ae2a69d9b62333cc610be Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 12 Jul 2019 11:31:37 -0400 Subject: [PATCH 2/3] settings: Tweak priorities for keyfile backend We want to use the keyfile backend in sandboxes, but we want to avoid people losing their existing settings that are stored in dconf. Flatpak does a migration from dconf to keyfile, but only if the app explictly requests it. From an app perspective, there are two steps to the dconf->keyfile migration: 1. Request that flatpak do the migration, by adding the migrate-path key to the metadata 2. Stop adding the 'dconf hole' to the sandbox To keep us from switching to the keyfile backend prematurely, look at whether the app has stopped requesting a 'dconf hole' in the sandbox. --- gio/gkeyfilesettingsbackend.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gio/gkeyfilesettingsbackend.c b/gio/gkeyfilesettingsbackend.c index 6ffb48217..3e80b1e48 100644 --- a/gio/gkeyfilesettingsbackend.c +++ b/gio/gkeyfilesettingsbackend.c @@ -80,7 +80,7 @@ typedef struct #ifdef G_OS_WIN32 #define EXTENSION_PRIORITY 10 #else -#define EXTENSION_PRIORITY (glib_should_use_portal () ? 110 : 10) +#define EXTENSION_PRIORITY (glib_should_use_portal () && !glib_has_dconf_access_in_sandbox () ? 110 : 10) #endif G_DEFINE_TYPE_WITH_CODE (GKeyfileSettingsBackend, From 715c8670ae5d6bcbba09369b9c60e2da9f5c1d83 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 10 Jul 2019 11:14:03 -0400 Subject: [PATCH 3/3] key file: Handle filename being NULL This happens when we are default-constructed without explicit arguments. Closes: https://gitlab.gnome.org/GNOME/glib/issues/1825 --- gio/gkeyfilesettingsbackend.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gio/gkeyfilesettingsbackend.c b/gio/gkeyfilesettingsbackend.c index 3e80b1e48..3d793f5a8 100644 --- a/gio/gkeyfilesettingsbackend.c +++ b/gio/gkeyfilesettingsbackend.c @@ -740,7 +740,8 @@ g_keyfile_settings_backend_set_property (GObject *object, case PROP_FILENAME: /* Construct only. */ g_assert (kfsb->file == NULL); - kfsb->file = g_file_new_for_path (g_value_get_string (value)); + if (g_value_get_string (value)) + kfsb->file = g_file_new_for_path (g_value_get_string (value)); break; case PROP_ROOT_PATH: