summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomasz Miąsko <tomasz.miasko@gmail.com>2018-11-15 00:00:00 +0000
committerTomasz Miąsko <tomasz.miasko@gmail.com>2018-12-06 20:06:34 +0100
commit82be1a9403defae17083154a5565ff0191cdffe5 (patch)
tree535243137aa8a3f1e9bff4f5dc53d49ee3ac2324
parente2dfc6864497fedab68df8dc53056fa3fadbb481 (diff)
downloaddconf-82be1a9403defae17083154a5565ff0191cdffe5.tar.gz
bin: Consistently handle invalid configuration in update
Consistently handle invalid database configuration by reporting the error and continuing with remaining databases. Functional changes from previous version: * When loading key-file fails: no change. * When group name is invalid: used to be ignored. * When key name is invalid: used to fail on an assertion. * When value is invalid: no change.
-rw-r--r--bin/dconf-update.vala63
1 files changed, 28 insertions, 35 deletions
diff --git a/bin/dconf-update.vala b/bin/dconf-update.vala
index 149e8fe..b4e0132 100644
--- a/bin/dconf-update.vala
+++ b/bin/dconf-update.vala
@@ -109,46 +109,39 @@ Gvdb.HashTable read_directory (string dirname) throws GLib.Error {
throw e;
}
- try {
- foreach (var group in kf.get_groups ()) {
- if (group.has_prefix ("/") || group.has_suffix ("/") || "//" in group) {
- stderr.printf ("%s: ignoring invalid group name: %s\n", filename, group);
+ foreach (var group in kf.get_groups ()) {
+ if (group.has_prefix ("/") || group.has_suffix ("/") || "//" in group) {
+ throw new KeyFileError.PARSE ("%s: invalid group name: %s".printf (filename, group));
+ }
+
+ foreach (var key in kf.get_keys (group)) {
+ if ("/" in key) {
+ throw new KeyFileError.INVALID_VALUE ("%s: [%s]: invalid key name: %s",
+ filename, group, key);
+ }
+
+ var path = "/" + group + "/" + key;
+
+ if (table.lookup (path) != null) {
+ /* We process the files in reverse alphabetical order. If the key is already set then
+ * it must have been set from a file with higher precedence so we should ignore this
+ * one.
+ */
continue;
}
- foreach (var key in kf.get_keys (group)) {
- if ("/" in key) {
- throw new KeyFileError.INVALID_VALUE ("%s: [%s]: invalid key name: %s",
- filename, group, key);
- }
-
- var path = "/" + group + "/" + key;
-
- if (table.lookup (path) != null) {
- /* We process the files in reverse alphabetical order. If the key is already set then
- * it must have been set from a file with higher precedence so we should ignore this
- * one.
- */
- continue;
- }
-
- var text = kf.get_value (group, key);
-
- try {
- var value = Variant.parse (null, text);
- unowned Gvdb.Item item = table.insert (path);
- item.set_parent (get_parent (table, path));
- item.set_value (value);
- } catch (VariantParseError e) {
- e.message = "%s: [%s]: %s: invalid value: %s (%s)".printf (filename, group, key, text, e.message);
- throw e;
- }
+ var text = kf.get_value (group, key);
+
+ try {
+ var value = Variant.parse (null, text);
+ unowned Gvdb.Item item = table.insert (path);
+ item.set_parent (get_parent (table, path));
+ item.set_value (value);
+ } catch (VariantParseError e) {
+ e.message = "%s: [%s]: %s: invalid value: %s (%s)".printf (filename, group, key, text, e.message);
+ throw e;
}
}
- } catch (KeyFileError e) {
- /* This should never happen... */
- warning ("unexpected keyfile error: %s. Please file a bug.", e.message);
- assert_not_reached ();
}
}