[dconf/wip/reorg] DConfEngineSource: return FALSE from NULL refresh



commit 8b08defe6463ad1f2e74d3e8708dd2af7d597d04
Author: Ryan Lortie <desrt desrt ca>
Date:   Thu Jul 12 22:57:04 2012 -0400

    DConfEngineSource: return FALSE from NULL refresh
    
    In the case that we call dconf_engine_source_refresh() on a source that
    had a NULL database and the result is that we still have a NULL
    database, return FALSE.
    
    This will prevent the unnecessary bumping of the state counter when
    there was really no change.  This happens in the case of a missing
    system database file.

 engine/dconf-engine-source.c |   15 ++++++++++++++-
 tests/engine.c               |    7 +++++++
 2 files changed, 21 insertions(+), 1 deletions(-)
---
diff --git a/engine/dconf-engine-source.c b/engine/dconf-engine-source.c
index 3c1f330..834644c 100644
--- a/engine/dconf-engine-source.c
+++ b/engine/dconf-engine-source.c
@@ -45,6 +45,12 @@ dconf_engine_source_refresh (DConfEngineSource *source)
 {
   if (source->vtable->needs_reopen (source))
     {
+      gboolean was_open;
+      gboolean is_open;
+
+      /* Record if we had a gvdb before or not. */
+      was_open = source->values != NULL;
+
       g_clear_pointer (&source->values, gvdb_table_unref);
       g_clear_pointer (&source->locks, gvdb_table_unref);
 
@@ -52,7 +58,14 @@ dconf_engine_source_refresh (DConfEngineSource *source)
       if (source->values)
         source->locks = gvdb_table_get_table (source->values, ".locks");
 
-      return TRUE;
+      /* Check if we ended up with a gvdb. */
+      is_open = source->values != NULL;
+
+      /* Only return TRUE in the case that we either had a database
+       * before or ended up with one after.  In the case that we just go
+       * from NULL to NULL, return FALSE.
+       */
+      return was_open || is_open;
     }
 
   return FALSE;
diff --git a/tests/engine.c b/tests/engine.c
index 31eaab6..6018cd1 100644
--- a/tests/engine.c
+++ b/tests/engine.c
@@ -237,6 +237,13 @@ test_user_source (void)
   g_assert (source != NULL);
   g_assert (source->values == NULL);
   g_assert (source->locks == NULL);
+
+  /* Refresh it the first time.
+   * This should cause it to open the shm.
+   * FALSE should be returned because there is no database file.
+   */
+  reopened = dconf_engine_source_refresh (source);
+  g_assert (!reopened);
   dconf_mock_shm_assert_log ("open user;");
 
   /* Try to refresh it.  There must be no IO at this point. */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]