diff options
author | Daniel P. Berrangé <berrange@redhat.com> | 2021-11-25 12:11:59 +0000 |
---|---|---|
committer | Daniel P. Berrangé <berrange@redhat.com> | 2022-02-04 14:14:49 +0000 |
commit | 6d5970a6245dcae02e00f38cbf30f6d3f889a126 (patch) | |
tree | 3b51334be880b8a11ee9f140f1e99bd13d59f9a9 | |
parent | 5d29aa6efb7f1880d3411d2c24c79d64472885b1 (diff) | |
download | libosinfo-6d5970a6245dcae02e00f38cbf30f6d3f889a126.tar.gz |
osinfo: refactor tree guessing internal helper
We want the return value from the tree guessing helper to indicate
whether any matches were used, and have the OsinfoOs as an output
parameter which can now be optional.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
-rw-r--r-- | osinfo/osinfo_db.c | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/osinfo/osinfo_db.c b/osinfo/osinfo_db.c index efe7ba5..fddebc4 100644 --- a/osinfo/osinfo_db.c +++ b/osinfo/osinfo_db.c @@ -813,29 +813,34 @@ static gboolean compare_tree(OsinfoTree *tree, return FALSE; } -static OsinfoOs * +static gboolean osinfo_db_guess_os_from_tree_internal(OsinfoDb *db, OsinfoTree *tree, + OsinfoOs **matched_os, OsinfoTree **matched_tree) { - OsinfoOs *ret = NULL; GList *oss = NULL; GList *fallback_oss = NULL; + gboolean matched = FALSE; - g_return_val_if_fail(OSINFO_IS_DB(db), NULL); - g_return_val_if_fail(tree != NULL, NULL); + if (matched_os) + *matched_os = NULL; + + g_return_val_if_fail(OSINFO_IS_DB(db), FALSE); + g_return_val_if_fail(tree != NULL, FALSE); oss = osinfo_list_get_elements(OSINFO_LIST(db->priv->oses)); - if (compare_tree(tree, oss, &ret, matched_tree, &fallback_oss)) - goto end; + if (compare_tree(tree, oss, matched_os, matched_tree, &fallback_oss)) + matched = TRUE; - compare_tree(tree, fallback_oss, &ret, matched_tree, NULL); + if (!matched && + compare_tree(tree, fallback_oss, matched_os, matched_tree, NULL)) + matched = TRUE; - end: g_list_free(oss); g_list_free(fallback_oss); - return ret; + return matched; } /** @@ -854,7 +859,12 @@ OsinfoOs *osinfo_db_guess_os_from_tree(OsinfoDb *db, OsinfoTree *tree, OsinfoTree **matched_tree) { - return osinfo_db_guess_os_from_tree_internal(db, tree, matched_tree); + OsinfoOs *ret; + + if (!osinfo_db_guess_os_from_tree_internal(db, tree, &ret, matched_tree)) + return NULL; + + return ret; } static void fill_tree(OsinfoDb *db, OsinfoTree *tree, @@ -953,9 +963,9 @@ gboolean osinfo_db_identify_tree(OsinfoDb *db, g_return_val_if_fail(OSINFO_IS_TREE(tree), FALSE); g_return_val_if_fail(OSINFO_IS_DB(db), FALSE); - matched_os = osinfo_db_guess_os_from_tree_internal(db, tree, - &matched_tree); - if (matched_os == NULL) { + if (!osinfo_db_guess_os_from_tree_internal(db, tree, + &matched_os, + &matched_tree)) { return FALSE; } |