[glib/wip/nacho/registry-writable: 6/6] registrybackend: handle readability of the keys



commit c5e7ae90f36fcfdce7ee167bff07e83fac006149
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Tue Feb 2 13:12:22 2016 +0100

    registrybackend: handle readability of the keys
    
    If a key is removed or it cannot be read anymore we should
    notify the backend about it so it fallbacks to the default
    value.

 gio/gregistrysettingsbackend.c |   63 ++++++++++++++++++++++++++--------------
 1 files changed, 41 insertions(+), 22 deletions(-)
---
diff --git a/gio/gregistrysettingsbackend.c b/gio/gregistrysettingsbackend.c
index bbc1686..9dbc762 100644
--- a/gio/gregistrysettingsbackend.c
+++ b/gio/gregistrysettingsbackend.c
@@ -1224,6 +1224,30 @@ registry_cache_destroy_tree (GNode            *node,
   g_node_destroy (node);
 }
 
+/* One of these is sent down the pipe when something happens in the registry. */
+typedef struct
+{
+  GRegistryBackend *self;
+  gchar *prefix;          /* prefix is a gsettings path, all items are subkeys of this. */
+  GPtrArray *items;       /* each item is a subkey below prefix that has changed. */
+  gboolean writability_changed; /* whether the writability of any of the items from prefix changed */
+} RegistryEvent;
+
+static void
+mark_item_keys_as_changed (GNode    *node,
+                           gpointer  data)
+{
+  RegistryCacheItem *item = node->data;
+  RegistryEvent *event = data;
+
+  /* Iterate until we find an item that is a value */
+  if (item->value.type == REG_NONE)
+    g_node_children_foreach (node, G_TRAVERSE_ALL,
+                             mark_item_keys_as_changed, data);
+  else
+    g_ptr_array_add (event->items, g_strdup (item->name));
+}
+
 static void
 registry_cache_remove_deleted (GNode    *node,
                                gpointer  data)
@@ -1231,7 +1255,10 @@ registry_cache_remove_deleted (GNode    *node,
   RegistryCacheItem *item = node->data;
 
   if (!item->readable)
-    registry_cache_destroy_tree (node, data);
+    {
+      mark_item_keys_as_changed (node, data);
+      registry_cache_destroy_tree (node, data);
+    }
 }
 
 /* Update cache from registry, and optionally report on the changes.
@@ -1254,16 +1281,16 @@ registry_cache_update (GRegistryBackend *self,
                        const gchar      *prefix,
                        const gchar      *partial_key_name,
                        GNode            *cache_node,
-                       int               n_watches, 
-                       GPtrArray        *changes,
-                       gboolean         *writability_changed)
+                       int               n_watches,
+                       RegistryEvent    *event)
 {
   gchar buffer[MAX_KEY_NAME_LENGTH + 1];
   gchar *key_name;
   gint i;
   LONG result;
+  RegistryCacheItem *item;
 
-  RegistryCacheItem *item = cache_node->data;
+  item = cache_node->data;
 
   if (item->subscription_count > 0)
     n_watches++;
@@ -1318,14 +1345,15 @@ registry_cache_update (GRegistryBackend *self,
             }
 
           registry_cache_update (self, hsubpath, prefix, buffer, subkey_node,
-                                 n_watches, changes, writability_changed);
+                                 n_watches, event);
 
           child_item = subkey_node->data;
           child_item->readable = TRUE;
           child_item->writable = writable;
 
-          if (writability_changed)
-            *writability_changed = *writability_changed || child_item->writable != writable;
+          if (event != NULL)
+            event->writability_changed = event->writability_changed ||
+                                         child_item->writable != writable;
 
           RegCloseKey (hsubpath);
         }
@@ -1381,7 +1409,7 @@ registry_cache_update (GRegistryBackend *self,
 
       child_item = cache_child_node->data;
       child_item->readable = TRUE;
-      if (changed && changes != NULL)
+      if (changed && event != NULL)
         {
           gchar *item;
 
@@ -1390,7 +1418,7 @@ registry_cache_update (GRegistryBackend *self,
           else
             item = g_build_path ("/", partial_key_name, buffer, NULL);
 
-          g_ptr_array_add (changes, item);
+          g_ptr_array_add (event->items, item);
         }
     }
 
@@ -1399,7 +1427,7 @@ registry_cache_update (GRegistryBackend *self,
 
   /* Any nodes now left unreadable must have been deleted, remove them from cache */
   g_node_children_foreach (cache_node, G_TRAVERSE_ALL,
-                           registry_cache_remove_deleted, self->watch);
+                           registry_cache_remove_deleted, event);
 
   trace ("registry cache update complete.\n");
 
@@ -1422,15 +1450,6 @@ registry_watch_key (HKEY   hpath,
                                   event, TRUE);
 }
 
-/* One of these is sent down the pipe when something happens in the registry. */
-typedef struct
-{
-  GRegistryBackend *self;
-  gchar *prefix;          /* prefix is a gsettings path, all items are subkeys of this. */
-  GPtrArray *items;       /* each item is a subkey below prefix that has changed. */
-  gboolean writability_changed; /* whether the writability of any of the items from prefix changed */
-} RegistryEvent;
-
 /* This handler runs in the main thread to emit the changed signals */
 static gboolean
 watch_handler (RegistryEvent *event)
@@ -1713,7 +1732,7 @@ watch_thread_function (LPVOID parameter)
           EnterCriticalSection (G_REGISTRY_BACKEND (self->owner)->cache_lock);
           registry_cache_update (G_REGISTRY_BACKEND (self->owner), hpath,
                                  prefix, NULL, cache_node, 0,
-                                 event->items, &event->writability_changed);
+                                 event);
           LeaveCriticalSection (G_REGISTRY_BACKEND (self->owner)->cache_lock);
 
           if (event->items->len > 0)
@@ -1860,7 +1879,7 @@ watch_add_notify (GRegistryBackend *self,
     }
 
   registry_cache_ref_tree (cache_node);
-  registry_cache_update (self, hpath, gsettings_prefix, NULL, cache_node, 0, NULL, NULL);
+  registry_cache_update (self, hpath, gsettings_prefix, NULL, cache_node, 0, NULL);
   //registry_cache_dump (self->cache_root, NULL);
   LeaveCriticalSection (self->cache_lock);
 


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