diff options
author | Philip Withnall <philip@tecnocode.co.uk> | 2018-12-10 12:15:11 +0000 |
---|---|---|
committer | Philip Withnall <philip@tecnocode.co.uk> | 2018-12-10 12:15:11 +0000 |
commit | 04304e0213a6f631dc52b95c6e728fcca25f1c6e (patch) | |
tree | e7228db0ecb1c787325ec333807dc52e644ac517 | |
parent | e2dfc6864497fedab68df8dc53056fa3fadbb481 (diff) | |
parent | dfa40d895fa5ad44ce34c80ddc5d5eb87080890b (diff) | |
download | dconf-04304e0213a6f631dc52b95c6e728fcca25f1c6e.tar.gz |
Merge branch 'issue-42' into 'master'
Indicate update failure with non-zero exit code
Closes #42
See merge request GNOME/dconf!34
-rw-r--r-- | bin/dconf-update.vala | 70 | ||||
-rwxr-xr-x | tests/test-dconf.py | 1 |
2 files changed, 35 insertions, 36 deletions
diff --git a/bin/dconf-update.vala b/bin/dconf-update.vala index 149e8fe..9492adb 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 (); } } @@ -242,15 +235,22 @@ void maybe_update_from_directory (string dirname) throws GLib.Error { } void update_all (string dirname) throws GLib.Error { + var failed = false; + foreach (var name in list_directory (dirname, Posix.S_IFDIR)) { if (name.has_suffix (".d")) { try { maybe_update_from_directory (name); } catch (Error e) { + failed = true; printerr ("unable to compile %s: %s\n", name, e.message); } } } + + if (failed) { + Process.exit (2); + } } void dconf_compile (string[] args) throws GLib.Error { diff --git a/tests/test-dconf.py b/tests/test-dconf.py index 202dc9f..40a8737 100755 --- a/tests/test-dconf.py +++ b/tests/test-dconf.py @@ -599,7 +599,6 @@ class DBusTest(unittest.TestCase): # Now database should be marked as invalid. self.assertEqual(b'\0'*8, mm[:8]) - @unittest.expectedFailure def test_update_failure(self): """Update should skip invalid configuration directory and continue with others. Failure to update one of databases should be indicated with |