|
|
0a59fa |
From c90388dda9f8f694e4458ca315430b0d37336530 Mon Sep 17 00:00:00 2001
|
|
|
0a59fa |
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@redhat.com>
|
|
|
0a59fa |
Date: Mon, 10 Dec 2018 15:42:21 +0100
|
|
|
0a59fa |
Subject: [PATCH] tree: cleanup load_key_info()
|
|
|
0a59fa |
MIME-Version: 1.0
|
|
|
0a59fa |
Content-Type: text/plain; charset=UTF-8
|
|
|
0a59fa |
Content-Transfer-Encoding: 8bit
|
|
|
0a59fa |
|
|
|
0a59fa |
Instead of doing the same checks for key or group not found all over the
|
|
|
0a59fa |
place, let's just add a new function that does that and replace the old
|
|
|
0a59fa |
check for the new function.
|
|
|
0a59fa |
|
|
|
0a59fa |
Signed-off-by: Fabiano FidĂȘncio <fidencio@redhat.com>
|
|
|
0a59fa |
Reviewed-by: Christophe Fergeau <cfergeau@redhat.com>
|
|
|
0a59fa |
(cherry picked from commit 6eab80bac760dc44dbefe403ef67a3a80dca2392)
|
|
|
0a59fa |
---
|
|
|
0a59fa |
osinfo/osinfo_tree.c | 63 ++++++++++++++++++++++++--------------------
|
|
|
0a59fa |
1 file changed, 35 insertions(+), 28 deletions(-)
|
|
|
0a59fa |
|
|
|
0a59fa |
diff --git a/osinfo/osinfo_tree.c b/osinfo/osinfo_tree.c
|
|
|
0a59fa |
index 565ccfe..f256f8a 100644
|
|
|
0a59fa |
--- a/osinfo/osinfo_tree.c
|
|
|
0a59fa |
+++ b/osinfo/osinfo_tree.c
|
|
|
0a59fa |
@@ -472,6 +472,13 @@ static gboolean is_str_empty(const gchar *str) {
|
|
|
0a59fa |
return ret;
|
|
|
0a59fa |
}
|
|
|
0a59fa |
|
|
|
0a59fa |
+static gboolean is_unknown_group_or_key_error(const GError *error)
|
|
|
0a59fa |
+{
|
|
|
0a59fa |
+ return (g_error_matches(error, G_KEY_FILE_ERROR,
|
|
|
0a59fa |
+ G_KEY_FILE_ERROR_KEY_NOT_FOUND) ||
|
|
|
0a59fa |
+ g_error_matches(error, G_KEY_FILE_ERROR,
|
|
|
0a59fa |
+ G_KEY_FILE_ERROR_GROUP_NOT_FOUND));
|
|
|
0a59fa |
+}
|
|
|
0a59fa |
|
|
|
0a59fa |
static OsinfoTree *load_keyinfo(const gchar *location,
|
|
|
0a59fa |
const gchar *content,
|
|
|
0a59fa |
@@ -493,44 +500,44 @@ static OsinfoTree *load_keyinfo(const gchar *location,
|
|
|
0a59fa |
G_KEY_FILE_NONE, error))
|
|
|
0a59fa |
goto cleanup;
|
|
|
0a59fa |
|
|
|
0a59fa |
- if (!(family = g_key_file_get_string(file, "general", "family", error)) &&
|
|
|
0a59fa |
- (*error && (*error)->code != G_KEY_FILE_ERROR_KEY_NOT_FOUND &&
|
|
|
0a59fa |
- (*error)->code != G_KEY_FILE_ERROR_GROUP_NOT_FOUND))
|
|
|
0a59fa |
- goto cleanup;
|
|
|
0a59fa |
+ if (!(family = g_key_file_get_string(file, "general", "family", error))) {
|
|
|
0a59fa |
+ if (!is_unknown_group_or_key_error(*error))
|
|
|
0a59fa |
+ goto cleanup;
|
|
|
0a59fa |
+ }
|
|
|
0a59fa |
|
|
|
0a59fa |
- if (!(variant = g_key_file_get_string(file, "general", "variant", error)) &&
|
|
|
0a59fa |
- (*error && (*error)->code != G_KEY_FILE_ERROR_KEY_NOT_FOUND &&
|
|
|
0a59fa |
- (*error)->code != G_KEY_FILE_ERROR_GROUP_NOT_FOUND))
|
|
|
0a59fa |
- goto cleanup;
|
|
|
0a59fa |
+ if (!(variant = g_key_file_get_string(file, "general", "variant", error))) {
|
|
|
0a59fa |
+ if (!is_unknown_group_or_key_error(*error))
|
|
|
0a59fa |
+ goto cleanup;
|
|
|
0a59fa |
+ }
|
|
|
0a59fa |
|
|
|
0a59fa |
- if (!(version = g_key_file_get_string(file, "general", "version", error)) &&
|
|
|
0a59fa |
- (*error && (*error)->code != G_KEY_FILE_ERROR_KEY_NOT_FOUND &&
|
|
|
0a59fa |
- (*error)->code != G_KEY_FILE_ERROR_GROUP_NOT_FOUND))
|
|
|
0a59fa |
- goto cleanup;
|
|
|
0a59fa |
+ if (!(version = g_key_file_get_string(file, "general", "version", error))) {
|
|
|
0a59fa |
+ if (!is_unknown_group_or_key_error(*error))
|
|
|
0a59fa |
+ goto cleanup;
|
|
|
0a59fa |
+ }
|
|
|
0a59fa |
|
|
|
0a59fa |
- if (!(arch = g_key_file_get_string(file, "general", "arch", error)) &&
|
|
|
0a59fa |
- (*error && (*error)->code != G_KEY_FILE_ERROR_KEY_NOT_FOUND &&
|
|
|
0a59fa |
- (*error)->code != G_KEY_FILE_ERROR_GROUP_NOT_FOUND))
|
|
|
0a59fa |
- goto cleanup;
|
|
|
0a59fa |
+ if (!(arch = g_key_file_get_string(file, "general", "arch", error))) {
|
|
|
0a59fa |
+ if (!is_unknown_group_or_key_error(*error))
|
|
|
0a59fa |
+ goto cleanup;
|
|
|
0a59fa |
+ }
|
|
|
0a59fa |
|
|
|
0a59fa |
|
|
|
0a59fa |
if (arch) {
|
|
|
0a59fa |
group = g_strdup_printf("images-%s", arch);
|
|
|
0a59fa |
|
|
|
0a59fa |
- if (!(kernel = g_key_file_get_string(file, group, "kernel", error)) &&
|
|
|
0a59fa |
- (*error && (*error)->code != G_KEY_FILE_ERROR_KEY_NOT_FOUND &&
|
|
|
0a59fa |
- (*error)->code != G_KEY_FILE_ERROR_GROUP_NOT_FOUND))
|
|
|
0a59fa |
- goto cleanup;
|
|
|
0a59fa |
+ if (!(kernel = g_key_file_get_string(file, group, "kernel", error))) {
|
|
|
0a59fa |
+ if (!is_unknown_group_or_key_error(*error))
|
|
|
0a59fa |
+ goto cleanup;
|
|
|
0a59fa |
+ }
|
|
|
0a59fa |
|
|
|
0a59fa |
- if (!(initrd = g_key_file_get_string(file, group, "initrd", error)) &&
|
|
|
0a59fa |
- (*error && (*error)->code != G_KEY_FILE_ERROR_KEY_NOT_FOUND &&
|
|
|
0a59fa |
- (*error)->code != G_KEY_FILE_ERROR_GROUP_NOT_FOUND))
|
|
|
0a59fa |
- goto cleanup;
|
|
|
0a59fa |
+ if (!(initrd = g_key_file_get_string(file, group, "initrd", error))) {
|
|
|
0a59fa |
+ if (!is_unknown_group_or_key_error(*error))
|
|
|
0a59fa |
+ goto cleanup;
|
|
|
0a59fa |
+ }
|
|
|
0a59fa |
|
|
|
0a59fa |
- if (!(bootiso = g_key_file_get_string(file, group, "boot.iso", error)) &&
|
|
|
0a59fa |
- (*error && (*error)->code != G_KEY_FILE_ERROR_KEY_NOT_FOUND &&
|
|
|
0a59fa |
- (*error)->code != G_KEY_FILE_ERROR_GROUP_NOT_FOUND))
|
|
|
0a59fa |
- goto cleanup;
|
|
|
0a59fa |
+ if (!(bootiso = g_key_file_get_string(file, group, "boot.iso", error))) {
|
|
|
0a59fa |
+ if (!is_unknown_group_or_key_error(*error))
|
|
|
0a59fa |
+ goto cleanup;
|
|
|
0a59fa |
+ }
|
|
|
0a59fa |
}
|
|
|
0a59fa |
|
|
|
0a59fa |
tree = osinfo_tree_new(location, arch ? arch : "i386");
|
|
|
0a59fa |
--
|
|
|
0a59fa |
2.21.0
|
|
|
0a59fa |
|