summaryrefslogtreecommitdiff
path: root/service/dconf-writer.c
diff options
context:
space:
mode:
authorRyan Lortie <desrt@desrt.ca>2013-01-11 14:17:22 -0500
committerRyan Lortie <desrt@desrt.ca>2013-01-11 14:17:22 -0500
commitdab1eaf9af416a2b32a4ba9a0b23cd787bf7eb0e (patch)
treec1f122d0dd62bbe0fc1df0b8bdd90be27c4aca7a /service/dconf-writer.c
parent554c431c95d4c6ad0de6871134b1952d08f11efd (diff)
downloaddconf-dab1eaf9af416a2b32a4ba9a0b23cd787bf7eb0e.tar.gz
writer: avoid spurious rewrites on Init
Don't rewrite the gvdb file unless an actual change has been applied to the database (unless creating a non-native database for the first time).
Diffstat (limited to 'service/dconf-writer.c')
-rw-r--r--service/dconf-writer.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/service/dconf-writer.c b/service/dconf-writer.c
index a907b55..7f9f2a5 100644
--- a/service/dconf-writer.c
+++ b/service/dconf-writer.c
@@ -41,6 +41,7 @@ struct _DConfWriterPrivate
gchar *basepath;
gchar *name;
guint64 tag;
+ gboolean need_write;
DConfChangeset *uncommited_values;
DConfChangeset *commited_values;
@@ -100,10 +101,18 @@ dconf_writer_real_begin (DConfWriter *writer,
*/
if (writer->priv->commited_values == NULL)
{
- writer->priv->commited_values = dconf_gvdb_utils_read_file (writer->priv->filename, error);
+ gboolean missing;
+
+ writer->priv->commited_values = dconf_gvdb_utils_read_file (writer->priv->filename, &missing, error);
if (!writer->priv->commited_values)
return FALSE;
+
+ /* If this is a non-native writer and the file doesn't exist, we
+ * will need to write it on commit so that the client can open it.
+ */
+ if (missing && !writer->priv->native)
+ writer->priv->need_write = TRUE;
}
writer->priv->uncommited_values = dconf_changeset_new_database (writer->priv->commited_values);
@@ -130,6 +139,8 @@ dconf_writer_real_change (DConfWriter *writer,
g_queue_push_tail (&writer->priv->uncommited_changes, change);
}
+
+ writer->priv->need_write = TRUE;
}
static gboolean
@@ -138,6 +149,16 @@ dconf_writer_real_commit (DConfWriter *writer,
{
gint invalidate_fd = -1;
+ if (!writer->priv->need_write)
+ {
+ g_assert (g_queue_is_empty (&writer->priv->uncommited_changes));
+ g_assert (g_queue_is_empty (&writer->priv->commited_changes));
+ dconf_changeset_unref (writer->priv->uncommited_values);
+ writer->priv->uncommited_values = NULL;
+
+ return TRUE;
+ }
+
if (!writer->priv->native)
/* If it fails, it doesn't matter... */
invalidate_fd = open (writer->priv->filename, O_WRONLY);