Medias with "all" architecture are used as a fallback when guessing an OS from a media. Knowing that, any entry with "all" architecture should not be considered when first comparing the medias, thus those are skipped and, later on, if no match has been found, those are used. https://gitlab.com/libosinfo/libosinfo/issues/20 Signed-off-by: Fabiano Fidêncio <fidencio@xxxxxxxxxx> --- osinfo/osinfo_db.c | 57 +++++++++++++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 16 deletions(-) diff --git a/osinfo/osinfo_db.c b/osinfo/osinfo_db.c index c7963ec..438d81b 100644 --- a/osinfo/osinfo_db.c +++ b/osinfo/osinfo_db.c @@ -537,13 +537,12 @@ static gint media_volume_compare(gconstpointer a, gconstpointer b) return 1; } -static OsinfoOs * -osinfo_db_guess_os_from_media_internal(OsinfoDb *db, - OsinfoMedia *media, - OsinfoMedia **matched_media) +static gboolean compare_media(OsinfoMedia *media, + GList *oss, + OsinfoOs **ret_os, + OsinfoMedia **matched, + GList **fallback_oss) { - OsinfoOs *ret = NULL; - GList *oss = NULL; GList *os_iter; const gchar *media_arch; const gchar *media_volume; @@ -552,9 +551,6 @@ osinfo_db_guess_os_from_media_internal(OsinfoDb *db, const gchar *media_application; gint64 media_vol_size; - g_return_val_if_fail(OSINFO_IS_DB(db), NULL); - g_return_val_if_fail(media != NULL, NULL); - media_arch = osinfo_media_get_architecture(media); media_volume = osinfo_media_get_volume_id(media); media_system = osinfo_media_get_system_id(media); @@ -562,7 +558,6 @@ osinfo_db_guess_os_from_media_internal(OsinfoDb *db, media_application = osinfo_media_get_application_id(media); media_vol_size = osinfo_media_get_volume_size(media); - oss = osinfo_list_get_elements(OSINFO_LIST(db->priv->oses)); for (os_iter = oss; os_iter; os_iter = os_iter->next) { OsinfoOs *os = OSINFO_OS(os_iter->data); OsinfoMediaList *media_list = osinfo_os_get_media_list(os); @@ -587,18 +582,25 @@ osinfo_db_guess_os_from_media_internal(OsinfoDb *db, os_vol_size <= 0) continue; + if (fallback_oss != NULL) { + if (g_str_equal(os_arch, "all")) { + *fallback_oss = g_list_prepend(*fallback_oss, os); + continue; + } + } + if (os_vol_size <= 0) os_vol_size = media_vol_size; - if (match_regex(os_arch, media_arch) && + if ((g_str_equal(os_arch, "all") || match_regex(os_arch, media_arch)) && match_regex(os_volume, media_volume) && match_regex(os_application, media_application) && match_regex(os_system, media_system) && match_regex(os_publisher, media_publisher) && os_vol_size == media_vol_size) { - ret = os; - if (matched_media != NULL) - *matched_media = os_media; + *ret_os = os; + if (matched != NULL) + *matched = os_media; break; } } @@ -606,11 +608,34 @@ osinfo_db_guess_os_from_media_internal(OsinfoDb *db, g_list_free(medias); g_object_unref(media_list); - if (ret) - break; + if (*ret_os) + return TRUE; } + return FALSE; +} + +static OsinfoOs * +osinfo_db_guess_os_from_media_internal(OsinfoDb *db, + OsinfoMedia *media, + OsinfoMedia **matched_media) +{ + OsinfoOs *ret = NULL; + GList *oss = NULL; + GList *fallback_oss = NULL; + + g_return_val_if_fail(OSINFO_IS_DB(db), NULL); + g_return_val_if_fail(media != NULL, NULL); + + oss = osinfo_list_get_elements(OSINFO_LIST(db->priv->oses)); + if (compare_media(media, oss, &ret, matched_media, &fallback_oss)) + goto end; + + compare_media(media, fallback_oss, &ret, matched_media, NULL); + + end: g_list_free(oss); + g_list_free(fallback_oss); return ret; } -- 2.20.1 _______________________________________________ Libosinfo mailing list Libosinfo@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libosinfo