[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [Libosinfo] [libosinfo PATCH 4/8] db: Deal with "unknown" tree architectures



On 3/27/19 7:24 AM, Fabiano Fidêncio wrote:
> https://gitlab.com/libosinfo/libosinfo/issues/20
> 
> Signed-off-by: Fabiano Fidêncio <fidencio redhat com>
> ---
>  osinfo/osinfo_db.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 44 insertions(+)
> 
> diff --git a/osinfo/osinfo_db.c b/osinfo/osinfo_db.c
> index b6d9282..1038142 100644
> --- a/osinfo/osinfo_db.c
> +++ b/osinfo/osinfo_db.c
> @@ -761,6 +761,7 @@ OsinfoOs *osinfo_db_guess_os_from_tree(OsinfoDb *db,
>      OsinfoOs *ret = NULL;
>      GList *oss = NULL;
>      GList *os_iter;
> +    GList *unknown_oss = NULL;
>      const gchar *tree_arch;
>      const gchar *treeinfo_family;
>      const gchar *treeinfo_variant;
> @@ -797,6 +798,11 @@ OsinfoOs *osinfo_db_guess_os_from_tree(OsinfoDb *db,
>                  continue;
>  
>              os_tree_arch = osinfo_tree_get_architecture(os_tree);
> +            if (g_str_equal(os_tree_arch, "unknown")) {
> +                unknown_oss = g_list_prepend(unknown_oss, os);
> +                continue;
> +            }
> +
>              os_treeinfo_family = osinfo_tree_get_treeinfo_family(os_tree);
>              os_treeinfo_variant = osinfo_tree_get_treeinfo_variant(os_tree);
>              os_treeinfo_version = osinfo_tree_get_treeinfo_version(os_tree);
> @@ -817,11 +823,49 @@ OsinfoOs *osinfo_db_guess_os_from_tree(OsinfoDb *db,
>          g_list_free(trees);
>          g_object_unref(tree_list);
>  
> +        if (ret)
> +            goto end;
> +    }
> +
> +    for (os_iter = unknown_oss; os_iter; os_iter = os_iter->next) {
> +        OsinfoOs *os = OSINFO_OS(os_iter->data);
> +        OsinfoTreeList *tree_list = osinfo_os_get_tree_list(os);
> +        GList *trees = osinfo_list_get_elements(OSINFO_LIST(tree_list));
> +        GList *tree_iter;
> +
> +        for (tree_iter = trees; tree_iter; tree_iter = tree_iter->next) {
> +            OsinfoTree *os_tree = OSINFO_TREE(tree_iter->data);
> +            const gchar *os_treeinfo_family;
> +            const gchar *os_treeinfo_variant;
> +            const gchar *os_treeinfo_version;
> +            const gchar *os_treeinfo_arch;
> +
> +            os_treeinfo_family = osinfo_tree_get_treeinfo_family(os_tree);
> +            os_treeinfo_variant = osinfo_tree_get_treeinfo_variant(os_tree);
> +            os_treeinfo_version = osinfo_tree_get_treeinfo_version(os_tree);
> +            os_treeinfo_arch = osinfo_tree_get_treeinfo_arch(os_tree);
> +
> +            if (match_regex(os_treeinfo_family, treeinfo_family) &&
> +                match_regex(os_treeinfo_variant, treeinfo_variant) &&
> +                match_regex(os_treeinfo_version, treeinfo_version) &&
> +                match_regex(os_treeinfo_arch, treeinfo_arch)) {
> +                ret = os;
> +                if (matched_tree != NULL)
> +                    *matched_tree = os_tree;
> +                break;
> +            }
> +        }
> +
> +        g_list_free(trees);
> +        g_object_unref(tree_list);
> +

This is a lot of duplication, I realize the code paths aren't completely
identical but I suggest moving this to something like compare_tree or
compare_treelist or similar

- Cole


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]