GSettings: keep resets on loss of writability
authorRyan Lortie <desrt@desrt.ca>
Sat, 7 May 2011 09:42:46 +0000 (11:42 +0200)
committerRyan Lortie <desrt@desrt.ca>
Sat, 7 May 2011 09:45:44 +0000 (11:45 +0200)
Don't drop resets from a GDelayedSettingsBackend when the writability
changes.  Resets will always succeed, even against non-writable keys and
some people (gnome-screensaver) are using them in a way that they would
want them not to be forgotten.

gio/gdelayedsettingsbackend.c

index dce1d7d..f7ea38b 100644 (file)
@@ -315,11 +315,16 @@ delayed_backend_writable_changed (GObject          *target,
 
   g_static_mutex_lock (&delayed->priv->lock);
 
-  if (g_tree_lookup (delayed->priv->delayed, key) &&
+  if (g_tree_lookup (delayed->priv->delayed, key) != NULL &&
       !g_settings_backend_get_writable (delayed->priv->backend, key))
     {
       /* drop the key from our changeset if it just became read-only.
        * no need to signal since the writable change below implies it.
+       *
+       * note that the item in the tree may very well be set to NULL in
+       * the case that the user stored a reset.  we intentionally don't
+       * drop the key in this case since a reset will always succeed
+       * (even against a non-writable key).
        */
       g_tree_remove (delayed->priv->delayed, key);
 
@@ -378,9 +383,12 @@ delayed_backend_path_writable_changed (GObject          *target,
       /* collect a list of possibly-affected keys (ie: matching the path) */
       g_tree_foreach (delayed->priv->delayed, check_prefix, &state);
 
-      /* drop the keys that have been affected */
+      /* drop the keys that have been affected.
+       *
+       * don't drop 'reset' keys (see above) */
       for (i = 0; i < state.index; i++)
-        if (!g_settings_backend_get_writable (delayed->priv->backend,
+        if (g_tree_lookup (delayed->priv->delayed, state.keys[i]) != NULL &&
+            !g_settings_backend_get_writable (delayed->priv->backend,
                                               state.keys[i]))
           g_tree_remove (delayed->priv->delayed, state.keys[i]);