[dconf/patch/engine-check: 2/4] common: factor out dconf_changeset_new_from_gvdb_table
- From: Daniel Playfair Cal <danielplayfaircal src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dconf/patch/engine-check: 2/4] common: factor out dconf_changeset_new_from_gvdb_table
- Date: Mon, 6 Jan 2020 03:31:22 +0000 (UTC)
commit d116150a0eb506d5382343ef15640b4c3c2489ca
Author: Daniel Playfair Cal <daniel playfair cal gmail com>
Date: Mon Jan 6 12:10:58 2020 +1100
common: factor out dconf_changeset_new_from_gvdb_table
common/dconf-changeset.h | 2 ++
common/dconf-gvdb-utils.c | 64 +++++++++++++++++++++++++----------------------
common/dconf-gvdb-utils.h | 1 +
3 files changed, 37 insertions(+), 30 deletions(-)
---
diff --git a/common/dconf-changeset.h b/common/dconf-changeset.h
index 6fe60f2..e2e7e7a 100644
--- a/common/dconf-changeset.h
+++ b/common/dconf-changeset.h
@@ -22,6 +22,8 @@
#include <glib.h>
+#include "../gvdb/gvdb-reader.h"
+
typedef struct _DConfChangeset DConfChangeset;
typedef gboolean (* DConfChangesetPredicate) (const gchar *path,
diff --git a/common/dconf-gvdb-utils.c b/common/dconf-gvdb-utils.c
index e70e2dc..738ff22 100644
--- a/common/dconf-gvdb-utils.c
+++ b/common/dconf-gvdb-utils.c
@@ -31,6 +31,37 @@
#include <glib/gstdio.h>
#include <string.h>
+DConfChangeset *
+dconf_changeset_new_from_gvdb_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,11 @@ 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]);
- }
-
- gvdb_table_free (table);
- g_free (names);
- }
+ database = dconf_changeset_new_from_gvdb_table (table);
+ 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..31daa43 100644
--- a/common/dconf-gvdb-utils.h
+++ b/common/dconf-gvdb-utils.h
@@ -23,6 +23,7 @@
#include "./dconf-changeset.h"
+DConfChangeset * dconf_changeset_new_from_gvdb_table (GvdbTable *table);
DConfChangeset * dconf_gvdb_utils_read_and_back_up_file (const gchar *filename,
gboolean *file_missing,
GError **error);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]