summaryrefslogtreecommitdiff
path: root/src/libotutil
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2019-11-07 16:06:39 +0000
committerColin Walters <walters@verbum.org>2019-11-07 21:15:41 +0000
commit58980a717a7854b27f48a0753dfbe5b8b94c8164 (patch)
treecc79ff90da84950b80bb247fdecedfce796bfb65 /src/libotutil
parentcb3eff6cfa0c0fba9e7e5d74eb7aac2a88666463 (diff)
downloadostree-58980a717a7854b27f48a0753dfbe5b8b94c8164.tar.gz
lib/keyfile: Treat "group not found" the same as "key not found"
Prep for fsverity, where I want to create a new group `[fsverity]` in the keyfile that has default values. We should treat the absence of a group the same as absence of a key in these "with defaults" APIs.
Diffstat (limited to 'src/libotutil')
-rw-r--r--src/libotutil/ot-keyfile-utils.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/libotutil/ot-keyfile-utils.c b/src/libotutil/ot-keyfile-utils.c
index 2050e969..3e028b20 100644
--- a/src/libotutil/ot-keyfile-utils.c
+++ b/src/libotutil/ot-keyfile-utils.c
@@ -27,6 +27,13 @@
#include <string.h>
+static gboolean
+is_notfound (GError *error)
+{
+ return g_error_matches (error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND)
+ || g_error_matches (error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_GROUP_NOT_FOUND);
+}
+
gboolean
ot_keyfile_get_boolean_with_default (GKeyFile *keyfile,
const char *section,
@@ -43,7 +50,7 @@ ot_keyfile_get_boolean_with_default (GKeyFile *keyfile,
gboolean 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 (is_notfound (temp_error))
{
g_clear_error (&temp_error);
ret_bool = default_value;
@@ -75,7 +82,7 @@ ot_keyfile_get_value_with_default (GKeyFile *keyfile,
g_autofree char *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 (is_notfound (temp_error))
{
g_clear_error (&temp_error);
g_assert (ret_value == NULL);
@@ -206,8 +213,7 @@ ot_keyfile_get_string_list_with_default (GKeyFile *keyfile,
if (temp_error)
{
- if (g_error_matches (temp_error, G_KEY_FILE_ERROR,
- G_KEY_FILE_ERROR_KEY_NOT_FOUND))
+ if (is_notfound (temp_error))
{
g_clear_error (&temp_error);
ret_value = g_strdupv (default_value);