2 * Copyright © 2010 Codethink Limited
3 * Copyright © 2010 Novell, Inc.
5 * SPDX-License-Identifier: LGPL-2.1-or-later
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
20 * Authors: Vincent Untz <vuntz@gnome.org>
21 * Ryan Lortie <desrt@desrt.ca>
33 #include "gfileinfo.h"
34 #include "gfileenumerator.h"
35 #include "gfilemonitor.h"
36 #include "gsimplepermission.h"
37 #include "gsettingsbackendinternal.h"
38 #include "giomodule-priv.h"
39 #include "gportalsupport.h"
42 #define G_TYPE_KEYFILE_SETTINGS_BACKEND (g_keyfile_settings_backend_get_type ())
43 #define G_KEYFILE_SETTINGS_BACKEND(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), \
44 G_TYPE_KEYFILE_SETTINGS_BACKEND, \
45 GKeyfileSettingsBackend))
46 #define G_IS_KEYFILE_SETTINGS_BACKEND(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), \
47 G_TYPE_KEYFILE_SETTINGS_BACKEND))
50 typedef GSettingsBackendClass GKeyfileSettingsBackendClass;
57 } GKeyfileSettingsBackendProperty;
61 GSettingsBackend parent_instance;
64 GPermission *permission;
67 GKeyFile *system_keyfile;
68 GHashTable *system_locks; /* Used as a set, owning the strings it contains */
76 GFileMonitor *file_monitor;
79 GFileMonitor *dir_monitor;
80 } GKeyfileSettingsBackend;
83 #define EXTENSION_PRIORITY 10
85 #define EXTENSION_PRIORITY (glib_should_use_portal () && !glib_has_dconf_access_in_sandbox () ? 110 : 10)
88 G_DEFINE_TYPE_WITH_CODE (GKeyfileSettingsBackend,
89 g_keyfile_settings_backend,
90 G_TYPE_SETTINGS_BACKEND,
91 _g_io_modules_ensure_extension_points_registered ();
92 g_io_extension_point_implement (G_SETTINGS_BACKEND_EXTENSION_POINT_NAME,
93 g_define_type_id, "keyfile", EXTENSION_PRIORITY))
96 compute_checksum (guint8 *digest,
97 gconstpointer contents,
103 checksum = g_checksum_new (G_CHECKSUM_SHA256);
104 g_checksum_update (checksum, contents, length);
105 g_checksum_get_digest (checksum, digest, &len);
106 g_checksum_free (checksum);
107 g_assert (len == 32);
111 g_keyfile_settings_backend_keyfile_write (GKeyfileSettingsBackend *kfsb,
118 contents = g_key_file_to_data (kfsb->keyfile, &length, NULL);
119 success = g_file_replace_contents (kfsb->file, contents, length, NULL, FALSE,
120 G_FILE_CREATE_REPLACE_DESTINATION |
121 G_FILE_CREATE_PRIVATE,
124 compute_checksum (kfsb->digest, contents, length);
131 group_name_matches (const gchar *group_name,
134 /* sort of like g_str_has_prefix() except that it must be an exact
135 * match or the prefix followed by '/'.
137 * for example 'a' is a prefix of 'a' and 'a/b' but not 'ab'.
141 for (i = 0; prefix[i]; i++)
142 if (prefix[i] != group_name[i])
145 return group_name[i] == '\0' || group_name[i] == '/';
149 convert_path (GKeyfileSettingsBackend *kfsb,
154 gsize key_len = strlen (key);
155 const gchar *last_slash;
157 if (key_len < kfsb->prefix_len ||
158 memcmp (key, kfsb->prefix, kfsb->prefix_len) != 0)
161 key_len -= kfsb->prefix_len;
162 key += kfsb->prefix_len;
164 last_slash = strrchr (key, '/');
166 /* Disallow empty group names or key names */
168 (last_slash != NULL &&
169 (*(last_slash + 1) == '\0' ||
173 if (kfsb->root_group)
175 /* if a root_group was specified, make sure the user hasn't given
176 * a path that ghosts that group name
178 if (last_slash != NULL && last_slash - key >= 0 &&
179 (gsize) (last_slash - key) == kfsb->root_group_len &&
180 memcmp (key, kfsb->root_group, last_slash - key) == 0)
185 /* if no root_group was given, ensure that the user gave a path */
186 if (last_slash == NULL)
192 if (last_slash != NULL)
194 *group = g_memdup2 (key, (last_slash - key) + 1);
195 (*group)[(last_slash - key)] = '\0';
198 *group = g_strdup (kfsb->root_group);
203 if (last_slash != NULL)
204 *basename = g_memdup2 (last_slash + 1, key_len - (last_slash - key));
206 *basename = g_strdup (key);
213 path_is_valid (GKeyfileSettingsBackend *kfsb,
216 return convert_path (kfsb, path, NULL, NULL);
220 get_from_keyfile (GKeyfileSettingsBackend *kfsb,
221 const GVariantType *type,
224 GVariant *return_value = NULL;
227 if (convert_path (kfsb, key, &group, &name))
234 sysstr = g_key_file_get_value (kfsb->system_keyfile, group, name, NULL);
235 str = g_key_file_get_value (kfsb->keyfile, group, name, NULL);
237 (g_hash_table_contains (kfsb->system_locks, key) ||
241 str = g_steal_pointer (&sysstr);
246 return_value = g_variant_parse (type, str, NULL, NULL, NULL);
248 /* As a special case, support values of type %G_VARIANT_TYPE_STRING
249 * not being quoted, since users keep forgetting to do it and then
250 * getting confused. */
251 if (return_value == NULL &&
252 g_variant_type_equal (type, G_VARIANT_TYPE_STRING) &&
255 GString *s = g_string_sized_new (strlen (str) + 2);
258 g_string_append_c (s, '\"');
262 g_string_append_c (s, '\\');
263 g_string_append_c (s, *p);
266 g_string_append_c (s, '\"');
267 return_value = g_variant_parse (type, s->str, NULL, NULL, NULL);
268 g_string_free (s, TRUE);
283 set_to_keyfile (GKeyfileSettingsBackend *kfsb,
289 if (g_hash_table_contains (kfsb->system_locks, key))
292 if (convert_path (kfsb, key, &group, &name))
296 gchar *str = g_variant_print (value, FALSE);
297 g_key_file_set_value (kfsb->keyfile, group, name, str);
298 g_variant_unref (g_variant_ref_sink (value));
308 groups = g_key_file_get_groups (kfsb->keyfile, NULL);
310 for (i = 0; groups[i]; i++)
311 if (group_name_matches (groups[i], group))
312 g_key_file_remove_group (kfsb->keyfile, groups[i], NULL);
317 g_key_file_remove_key (kfsb->keyfile, group, name, NULL);
330 g_keyfile_settings_backend_read (GSettingsBackend *backend,
332 const GVariantType *expected_type,
333 gboolean default_value)
335 GKeyfileSettingsBackend *kfsb = G_KEYFILE_SETTINGS_BACKEND (backend);
340 return get_from_keyfile (kfsb, expected_type, key);
345 GKeyfileSettingsBackend *kfsb;
350 g_keyfile_settings_backend_write_one (gpointer key,
354 WriteManyData *data = user_data;
355 gboolean success G_GNUC_UNUSED /* when compiling with G_DISABLE_ASSERT */;
357 success = set_to_keyfile (data->kfsb, key, value);
364 g_keyfile_settings_backend_check_one (gpointer key,
368 WriteManyData *data = user_data;
370 return data->failed = g_hash_table_contains (data->kfsb->system_locks, key) ||
371 !path_is_valid (data->kfsb, key);
375 g_keyfile_settings_backend_write_tree (GSettingsBackend *backend,
379 WriteManyData data = { G_KEYFILE_SETTINGS_BACKEND (backend), 0 };
381 GError *error = NULL;
383 if (!data.kfsb->writable)
386 g_tree_foreach (tree, g_keyfile_settings_backend_check_one, &data);
391 g_tree_foreach (tree, g_keyfile_settings_backend_write_one, &data);
392 success = g_keyfile_settings_backend_keyfile_write (data.kfsb, &error);
395 g_warning ("Failed to write keyfile to %s: %s", g_file_peek_path (data.kfsb->file), error->message);
396 g_error_free (error);
399 g_settings_backend_changed_tree (backend, tree, origin_tag);
405 g_keyfile_settings_backend_write (GSettingsBackend *backend,
410 GKeyfileSettingsBackend *kfsb = G_KEYFILE_SETTINGS_BACKEND (backend);
412 GError *error = NULL;
417 success = set_to_keyfile (kfsb, key, value);
421 g_settings_backend_changed (backend, key, origin_tag);
422 success = g_keyfile_settings_backend_keyfile_write (kfsb, &error);
425 g_warning ("Failed to write keyfile to %s: %s", g_file_peek_path (kfsb->file), error->message);
426 g_error_free (error);
434 g_keyfile_settings_backend_reset (GSettingsBackend *backend,
438 GKeyfileSettingsBackend *kfsb = G_KEYFILE_SETTINGS_BACKEND (backend);
439 GError *error = NULL;
441 if (set_to_keyfile (kfsb, key, NULL))
443 g_keyfile_settings_backend_keyfile_write (kfsb, &error);
446 g_warning ("Failed to write keyfile to %s: %s", g_file_peek_path (kfsb->file), error->message);
447 g_error_free (error);
451 g_settings_backend_changed (backend, key, origin_tag);
455 g_keyfile_settings_backend_get_writable (GSettingsBackend *backend,
458 GKeyfileSettingsBackend *kfsb = G_KEYFILE_SETTINGS_BACKEND (backend);
460 return kfsb->writable &&
461 !g_hash_table_contains (kfsb->system_locks, name) &&
462 path_is_valid (kfsb, name);
466 g_keyfile_settings_backend_get_permission (GSettingsBackend *backend,
469 GKeyfileSettingsBackend *kfsb = G_KEYFILE_SETTINGS_BACKEND (backend);
471 return g_object_ref (kfsb->permission);
475 keyfile_to_tree (GKeyfileSettingsBackend *kfsb,
483 groups = g_key_file_get_groups (keyfile, NULL);
484 for (i = 0; groups[i]; i++)
486 gboolean is_root_group;
490 is_root_group = g_strcmp0 (kfsb->root_group, groups[i]) == 0;
492 /* reject group names that will form invalid key names */
493 if (!is_root_group &&
494 (g_str_has_prefix (groups[i], "/") ||
495 g_str_has_suffix (groups[i], "/") || strstr (groups[i], "//")))
498 keys = g_key_file_get_keys (keyfile, groups[i], NULL, NULL);
499 g_assert (keys != NULL);
501 for (j = 0; keys[j]; j++)
505 /* reject key names with slashes in them */
506 if (strchr (keys[j], '/'))
510 path = g_strdup_printf ("%s%s", kfsb->prefix, keys[j]);
512 path = g_strdup_printf ("%s%s/%s", kfsb->prefix, groups[i], keys[j]);
514 value = g_key_file_get_value (keyfile, groups[i], keys[j], NULL);
516 if (dup_check && g_strcmp0 (g_tree_lookup (tree, path), value) == 0)
518 g_tree_remove (tree, path);
523 g_tree_insert (tree, path, value);
532 g_keyfile_settings_backend_keyfile_reload (GKeyfileSettingsBackend *kfsb)
541 g_file_load_contents (kfsb->file, NULL, &contents, &length, NULL, NULL);
542 compute_checksum (digest, contents, length);
544 if (memcmp (kfsb->digest, digest, sizeof digest) != 0)
546 GKeyFile *keyfiles[2];
549 tree = g_tree_new_full ((GCompareDataFunc) strcmp, NULL,
552 keyfiles[0] = kfsb->keyfile;
553 keyfiles[1] = g_key_file_new ();
556 g_key_file_load_from_data (keyfiles[1], contents, length,
557 G_KEY_FILE_KEEP_COMMENTS |
558 G_KEY_FILE_KEEP_TRANSLATIONS, NULL);
560 keyfile_to_tree (kfsb, tree, keyfiles[0], FALSE);
561 keyfile_to_tree (kfsb, tree, keyfiles[1], TRUE);
562 g_key_file_free (keyfiles[0]);
563 kfsb->keyfile = keyfiles[1];
565 if (g_tree_nnodes (tree) > 0)
566 g_settings_backend_changed_tree (&kfsb->parent_instance, tree, NULL);
570 memcpy (kfsb->digest, digest, sizeof digest);
577 g_keyfile_settings_backend_keyfile_writable (GKeyfileSettingsBackend *kfsb)
582 fileinfo = g_file_query_info (kfsb->dir, "access::*", 0, NULL, NULL);
587 g_file_info_get_attribute_boolean (fileinfo, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE) &&
588 g_file_info_get_attribute_boolean (fileinfo, G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE);
589 g_object_unref (fileinfo);
594 if (writable != kfsb->writable)
596 kfsb->writable = writable;
597 g_settings_backend_path_writable_changed (&kfsb->parent_instance, "/");
602 g_keyfile_settings_backend_finalize (GObject *object)
604 GKeyfileSettingsBackend *kfsb = G_KEYFILE_SETTINGS_BACKEND (object);
606 g_key_file_free (kfsb->keyfile);
607 g_object_unref (kfsb->permission);
608 g_key_file_unref (kfsb->system_keyfile);
609 g_hash_table_unref (kfsb->system_locks);
610 g_free (kfsb->defaults_dir);
612 if (kfsb->file_monitor)
614 g_file_monitor_cancel (kfsb->file_monitor);
615 g_object_unref (kfsb->file_monitor);
617 g_object_unref (kfsb->file);
619 if (kfsb->dir_monitor)
621 g_file_monitor_cancel (kfsb->dir_monitor);
622 g_object_unref (kfsb->dir_monitor);
624 g_object_unref (kfsb->dir);
626 g_free (kfsb->root_group);
627 g_free (kfsb->prefix);
629 G_OBJECT_CLASS (g_keyfile_settings_backend_parent_class)->finalize (object);
633 g_keyfile_settings_backend_init (GKeyfileSettingsBackend *kfsb)
638 file_changed (GFileMonitor *monitor,
641 GFileMonitorEvent event_type,
644 GKeyfileSettingsBackend *kfsb = user_data;
646 /* Ignore file deletions, let the GKeyFile content remain in tact. */
647 if (event_type != G_FILE_MONITOR_EVENT_DELETED)
648 g_keyfile_settings_backend_keyfile_reload (kfsb);
652 dir_changed (GFileMonitor *monitor,
655 GFileMonitorEvent event_type,
658 GKeyfileSettingsBackend *kfsb = user_data;
660 g_keyfile_settings_backend_keyfile_writable (kfsb);
664 load_system_settings (GKeyfileSettingsBackend *kfsb)
666 GError *error = NULL;
667 const char *dir = "/etc/glib-2.0/settings";
671 kfsb->system_keyfile = g_key_file_new ();
672 kfsb->system_locks = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
674 if (kfsb->defaults_dir)
675 dir = kfsb->defaults_dir;
677 path = g_build_filename (dir, "defaults", NULL);
679 /* The defaults are in the same keyfile format that we use for the settings.
680 * It can be produced from a dconf database using: dconf dump
682 if (!g_key_file_load_from_file (kfsb->system_keyfile, path, G_KEY_FILE_NONE, &error))
684 if (!g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
685 g_warning ("Failed to read %s: %s", path, error->message);
686 g_clear_error (&error);
689 g_debug ("Loading default settings from %s", path);
693 path = g_build_filename (dir, "locks", NULL);
695 /* The locks file is a text file containing a list paths to lock, one per line.
696 * It can be produced from a dconf database using: dconf list-locks
698 if (!g_file_get_contents (path, &contents, NULL, &error))
700 if (!g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
701 g_warning ("Failed to read %s: %s", path, error->message);
702 g_clear_error (&error);
709 g_debug ("Loading locks from %s", path);
711 lines = g_strsplit (contents, "\n", 0);
712 for (i = 0; lines[i]; i++)
714 char *line = lines[i];
715 if (line[0] == '#' || line[0] == '\0')
721 g_debug ("Locking key %s", line);
722 g_hash_table_add (kfsb->system_locks, g_steal_pointer (&line));
733 g_keyfile_settings_backend_constructed (GObject *object)
735 GKeyfileSettingsBackend *kfsb = G_KEYFILE_SETTINGS_BACKEND (object);
736 GError *error = NULL;
739 if (kfsb->file == NULL)
741 char *filename = g_build_filename (g_get_user_config_dir (),
742 "glib-2.0", "settings", "keyfile",
744 kfsb->file = g_file_new_for_path (filename);
748 if (kfsb->prefix == NULL)
750 kfsb->prefix = g_strdup ("/");
751 kfsb->prefix_len = 1;
754 kfsb->keyfile = g_key_file_new ();
755 kfsb->permission = g_simple_permission_new (TRUE);
757 kfsb->dir = g_file_get_parent (kfsb->file);
758 path = g_file_peek_path (kfsb->dir);
759 if (g_mkdir_with_parents (path, 0700) == -1)
760 g_warning ("Failed to create %s: %s", path, g_strerror (errno));
762 kfsb->file_monitor = g_file_monitor (kfsb->file, G_FILE_MONITOR_NONE, NULL, &error);
763 if (!kfsb->file_monitor)
765 g_warning ("Failed to create file monitor for %s: %s", g_file_peek_path (kfsb->file), error->message);
766 g_clear_error (&error);
770 g_signal_connect (kfsb->file_monitor, "changed",
771 G_CALLBACK (file_changed), kfsb);
774 kfsb->dir_monitor = g_file_monitor (kfsb->dir, G_FILE_MONITOR_NONE, NULL, &error);
775 if (!kfsb->dir_monitor)
777 g_warning ("Failed to create file monitor for %s: %s", g_file_peek_path (kfsb->file), error->message);
778 g_clear_error (&error);
782 g_signal_connect (kfsb->dir_monitor, "changed",
783 G_CALLBACK (dir_changed), kfsb);
786 compute_checksum (kfsb->digest, NULL, 0);
788 g_keyfile_settings_backend_keyfile_writable (kfsb);
789 g_keyfile_settings_backend_keyfile_reload (kfsb);
791 load_system_settings (kfsb);
795 g_keyfile_settings_backend_set_property (GObject *object,
800 GKeyfileSettingsBackend *kfsb = G_KEYFILE_SETTINGS_BACKEND (object);
802 switch ((GKeyfileSettingsBackendProperty)prop_id)
805 /* Construct only. */
806 g_assert (kfsb->file == NULL);
807 if (g_value_get_string (value))
808 kfsb->file = g_file_new_for_path (g_value_get_string (value));
812 /* Construct only. */
813 g_assert (kfsb->prefix == NULL);
814 kfsb->prefix = g_value_dup_string (value);
816 kfsb->prefix_len = strlen (kfsb->prefix);
819 case PROP_ROOT_GROUP:
820 /* Construct only. */
821 g_assert (kfsb->root_group == NULL);
822 kfsb->root_group = g_value_dup_string (value);
823 if (kfsb->root_group)
824 kfsb->root_group_len = strlen (kfsb->root_group);
827 case PROP_DEFAULTS_DIR:
828 /* Construct only. */
829 g_assert (kfsb->defaults_dir == NULL);
830 kfsb->defaults_dir = g_value_dup_string (value);
834 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
840 g_keyfile_settings_backend_get_property (GObject *object,
845 GKeyfileSettingsBackend *kfsb = G_KEYFILE_SETTINGS_BACKEND (object);
847 switch ((GKeyfileSettingsBackendProperty)prop_id)
850 g_value_set_string (value, g_file_peek_path (kfsb->file));
854 g_value_set_string (value, kfsb->prefix);
857 case PROP_ROOT_GROUP:
858 g_value_set_string (value, kfsb->root_group);
861 case PROP_DEFAULTS_DIR:
862 g_value_set_string (value, kfsb->defaults_dir);
866 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
872 g_keyfile_settings_backend_class_init (GKeyfileSettingsBackendClass *class)
874 GObjectClass *object_class = G_OBJECT_CLASS (class);
876 object_class->finalize = g_keyfile_settings_backend_finalize;
877 object_class->constructed = g_keyfile_settings_backend_constructed;
878 object_class->get_property = g_keyfile_settings_backend_get_property;
879 object_class->set_property = g_keyfile_settings_backend_set_property;
881 class->read = g_keyfile_settings_backend_read;
882 class->write = g_keyfile_settings_backend_write;
883 class->write_tree = g_keyfile_settings_backend_write_tree;
884 class->reset = g_keyfile_settings_backend_reset;
885 class->get_writable = g_keyfile_settings_backend_get_writable;
886 class->get_permission = g_keyfile_settings_backend_get_permission;
887 /* No need to implement subscribed/unsubscribe: the only point would be to
888 * stop monitoring the file when there's no GSettings anymore, which is no
893 * GKeyfileSettingsBackend:filename:
895 * The location where the settings are stored on disk.
897 * Defaults to `$XDG_CONFIG_HOME/glib-2.0/settings/keyfile`.
899 g_object_class_install_property (object_class,
901 g_param_spec_string ("filename", NULL, NULL,
903 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
904 G_PARAM_STATIC_STRINGS));
907 * GKeyfileSettingsBackend:root-path:
909 * All settings read to or written from the backend must fall under the
910 * path given in @root_path (which must start and end with a slash and
911 * not contain two consecutive slashes). @root_path may be "/".
915 g_object_class_install_property (object_class,
917 g_param_spec_string ("root-path", NULL, NULL,
919 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
920 G_PARAM_STATIC_STRINGS));
923 * GKeyfileSettingsBackend:root-group:
925 * If @root_group is non-%NULL then it specifies the name of the keyfile
926 * group used for keys that are written directly below the root path.
930 g_object_class_install_property (object_class,
932 g_param_spec_string ("root-group", NULL, NULL,
934 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
935 G_PARAM_STATIC_STRINGS));
938 * GKeyfileSettingsBackend:default-dir:
940 * The directory where the system defaults and locks are located.
942 * Defaults to `/etc/glib-2.0/settings`.
944 g_object_class_install_property (object_class,
946 g_param_spec_string ("defaults-dir", NULL, NULL,
948 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
949 G_PARAM_STATIC_STRINGS));
953 * g_keyfile_settings_backend_new:
954 * @filename: the filename of the keyfile
955 * @root_path: the path under which all settings keys appear
956 * @root_group: (nullable): the group name corresponding to
957 * @root_path, or %NULL
959 * Creates a keyfile-backed #GSettingsBackend.
961 * The filename of the keyfile to use is given by @filename.
963 * All settings read to or written from the backend must fall under the
964 * path given in @root_path (which must start and end with a slash and
965 * not contain two consecutive slashes). @root_path may be "/".
967 * If @root_group is non-%NULL then it specifies the name of the keyfile
968 * group used for keys that are written directly below @root_path. For
969 * example, if @root_path is "/apps/example/" and @root_group is
970 * "toplevel", then settings the key "/apps/example/enabled" to a value
971 * of %TRUE will cause the following to appear in the keyfile:
978 * If @root_group is %NULL then it is not permitted to store keys
979 * directly below the @root_path.
981 * For keys not stored directly below @root_path (ie: in a sub-path),
982 * the name of the subpath (with the final slash stripped) is used as
983 * the name of the keyfile group. To continue the example, if
984 * "/apps/example/profiles/default/font-size" were set to
985 * 12 then the following would appear in the keyfile:
992 * The backend will refuse writes (and return writability as being
993 * %FALSE) for keys outside of @root_path and, in the event that
994 * @root_group is %NULL, also for keys directly under @root_path.
995 * Writes will also be refused if the backend detects that it has the
996 * inability to rewrite the keyfile (ie: the containing directory is not
999 * There is no checking done for your key namespace clashing with the
1000 * syntax of the key file format. For example, if you have '[' or ']'
1001 * characters in your path names or '=' in your key names you may be in
1004 * The backend reads default values from a keyfile called `defaults` in
1005 * the directory specified by the #GKeyfileSettingsBackend:defaults-dir property,
1006 * and a list of locked keys from a text file with the name `locks` in
1007 * the same location.
1009 * Returns: (transfer full): a keyfile-backed #GSettingsBackend
1012 g_keyfile_settings_backend_new (const gchar *filename,
1013 const gchar *root_path,
1014 const gchar *root_group)
1016 g_return_val_if_fail (filename != NULL, NULL);
1017 g_return_val_if_fail (root_path != NULL, NULL);
1018 g_return_val_if_fail (g_str_has_prefix (root_path, "/"), NULL);
1019 g_return_val_if_fail (g_str_has_suffix (root_path, "/"), NULL);
1020 g_return_val_if_fail (strstr (root_path, "//") == NULL, NULL);
1022 return G_SETTINGS_BACKEND (g_object_new (G_TYPE_KEYFILE_SETTINGS_BACKEND,
1023 "filename", filename,
1024 "root-path", root_path,
1025 "root-group", root_group,