From 6edda52ed45feaaec203e51a23f4b50cc7d4b147 Mon Sep 17 00:00:00 2001 From: Daniel Playfair Cal Date: Mon, 6 Jan 2020 12:10:58 +1100 Subject: common: factor out dconf_gvdb_utils_changeset_from_table --- common/dconf-gvdb-utils.c | 61 ++++++++++++++++++++++++++--------------------- common/dconf-gvdb-utils.h | 2 ++ 2 files changed, 36 insertions(+), 27 deletions(-) diff --git a/common/dconf-gvdb-utils.c b/common/dconf-gvdb-utils.c index e70e2dc..56609cc 100644 --- a/common/dconf-gvdb-utils.c +++ b/common/dconf-gvdb-utils.c @@ -31,6 +31,37 @@ #include #include +DConfChangeset * +dconf_gvdb_utils_changeset_from_table (GvdbTable *table) +{ + DConfChangeset *database = dconf_changeset_new_database (NULL); + gchar **names; + gsize n_names; + gsize i; + + names = gvdb_table_get_names (table, &n_names); + for (i = 0; i < n_names; i++) + { + if (dconf_is_key (names[i], NULL)) + { + GVariant *value; + + value = gvdb_table_get_value (table, names[i]); + + if (value != NULL) + { + dconf_changeset_set (database, names[i], value); + g_variant_unref (value); + } + } + + g_free (names[i]); + } + + g_free (names); + return database; +} + DConfChangeset * dconf_gvdb_utils_read_and_back_up_file (const gchar *filename, gboolean *file_missing, @@ -95,38 +126,14 @@ dconf_gvdb_utils_read_and_back_up_file (const gchar *filename, return NULL; } - /* Only allocate once we know we are in a non-error situation */ - database = dconf_changeset_new_database (NULL); - /* Fill the table up with the initial state */ if (table != NULL) { - gchar **names; - gsize n_names; - gsize i; - - names = gvdb_table_get_names (table, &n_names); - for (i = 0; i < n_names; i++) - { - if (dconf_is_key (names[i], NULL)) - { - GVariant *value; - - value = gvdb_table_get_value (table, names[i]); - - if (value != NULL) - { - dconf_changeset_set (database, names[i], value); - g_variant_unref (value); - } - } - - g_free (names[i]); - } - + database = dconf_gvdb_utils_changeset_from_table (table); gvdb_table_free (table); - g_free (names); } + else + database = dconf_changeset_new_database (NULL); if (file_missing) *file_missing = (table == NULL); diff --git a/common/dconf-gvdb-utils.h b/common/dconf-gvdb-utils.h index 8d73133..4bd4cd9 100644 --- a/common/dconf-gvdb-utils.h +++ b/common/dconf-gvdb-utils.h @@ -21,8 +21,10 @@ #ifndef __dconf_gvdb_utils_h__ #define __dconf_gvdb_utils_h__ +#include "../gvdb/gvdb-reader.h" #include "./dconf-changeset.h" +DConfChangeset * dconf_gvdb_utils_changeset_from_table (GvdbTable *table); DConfChangeset * dconf_gvdb_utils_read_and_back_up_file (const gchar *filename, gboolean *file_missing, GError **error); -- cgit v1.2.1