From bd082adaca9a7e95207341af8e7e1e832896f0fc Mon Sep 17 00:00:00 2001 From: Robert Fairley Date: Fri, 15 Feb 2019 18:04:37 -0500 Subject: [PATCH] libotutil: Allow missing groups when getting key values with default Prep commit as part of #1814, where a new `sysroot` group is added to the repo config. This allows falling back to a default key value if the specified group does not exist in the config file. --- src/libotutil/ot-keyfile-utils.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libotutil/ot-keyfile-utils.c b/src/libotutil/ot-keyfile-utils.c index 86a06a9e16..9bba2270b6 100644 --- a/src/libotutil/ot-keyfile-utils.c +++ b/src/libotutil/ot-keyfile-utils.c @@ -46,7 +46,8 @@ ot_keyfile_get_boolean_with_default (GKeyFile *keyfile, ret_bool = g_key_file_get_boolean (keyfile, section, value, &temp_error); if (temp_error) { - if (g_error_matches (temp_error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND)) + if (g_error_matches (temp_error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND) + || g_error_matches (temp_error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_GROUP_NOT_FOUND)) { g_clear_error (&temp_error); ret_bool = default_value; @@ -83,7 +84,8 @@ ot_keyfile_get_value_with_default (GKeyFile *keyfile, ret_value = g_key_file_get_value (keyfile, section, value, &temp_error); if (temp_error) { - if (g_error_matches (temp_error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND)) + if (g_error_matches (temp_error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND) + || g_error_matches (temp_error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_GROUP_NOT_FOUND)) { g_clear_error (&temp_error); ret_value = g_strdup (default_value);