[dconf] writer: avoid spurious rewrites on Init
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dconf] writer: avoid spurious rewrites on Init
- Date: Fri, 11 Jan 2013 20:27:30 +0000 (UTC)
commit dab1eaf9af416a2b32a4ba9a0b23cd787bf7eb0e
Author: Ryan Lortie <desrt desrt ca>
Date: Fri Jan 11 14:17:22 2013 -0500
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).
service/dconf-gvdb-utils.c | 4 ++++
service/dconf-gvdb-utils.h | 1 +
service/dconf-writer.c | 23 ++++++++++++++++++++++-
3 files changed, 27 insertions(+), 1 deletions(-)
---
diff --git a/service/dconf-gvdb-utils.c b/service/dconf-gvdb-utils.c
index 0fc3478..3052edc 100644
--- a/service/dconf-gvdb-utils.c
+++ b/service/dconf-gvdb-utils.c
@@ -30,6 +30,7 @@
DConfChangeset *
dconf_gvdb_utils_read_file (const gchar *filename,
+ gboolean *file_missing,
GError **error)
{
DConfChangeset *database;
@@ -95,6 +96,9 @@ dconf_gvdb_utils_read_file (const gchar *filename,
g_free (names);
}
+ if (file_missing)
+ *file_missing = (table == NULL);
+
return database;
}
diff --git a/service/dconf-gvdb-utils.h b/service/dconf-gvdb-utils.h
index ff5d9fe..7c3259b 100644
--- a/service/dconf-gvdb-utils.h
+++ b/service/dconf-gvdb-utils.h
@@ -26,6 +26,7 @@
#include "../common/dconf-changeset.h"
DConfChangeset * dconf_gvdb_utils_read_file (const gchar *filename,
+ gboolean *file_missing,
GError **error);
gboolean dconf_gvdb_utils_write_file (const gchar *filename,
DConfChangeset *database,
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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]