From df78f0734e59a9140d1126917d825f9f8fcd3514 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Date: Thu, 25 Nov 2021 12:29:29 +0000 Subject: osinfo: honour media architecture when matching MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The media matching code currently ignores the media architecture which is generally ok, since osinfo_media_create_from_location will leave it set to NULL. None the less, if an architecture is provided for the unknown media, we should only return results that match this architecture. Signed-off-by: Daniel P. Berrangé --- osinfo/osinfo_media.c | 14 ++++++++++---- tests/test-db.c | 22 ++++++++++++++++++++++ tests/test-media.c | 9 +++++++++ 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/osinfo/osinfo_media.c b/osinfo/osinfo_media.c index 87c91a4..4e3c02c 100644 --- a/osinfo/osinfo_media.c +++ b/osinfo/osinfo_media.c @@ -705,9 +705,10 @@ OsinfoMedia *osinfo_media_new(const gchar *id, "id", id, NULL); - osinfo_entity_set_param(OSINFO_ENTITY(media), - OSINFO_MEDIA_PROP_ARCHITECTURE, - architecture); + if (architecture) + osinfo_entity_set_param(OSINFO_ENTITY(media), + OSINFO_MEDIA_PROP_ARCHITECTURE, + architecture); return media; } @@ -1880,12 +1881,14 @@ gboolean osinfo_media_is_bootable(OsinfoMedia *media) */ gboolean osinfo_media_matches(OsinfoMedia *media, OsinfoMedia *reference) { + const gchar *media_arch = osinfo_media_get_architecture(media); const gchar *media_volume = osinfo_media_get_volume_id(media); const gchar *media_system = osinfo_media_get_system_id(media); const gchar *media_publisher = osinfo_media_get_publisher_id(media); const gchar *media_application = osinfo_media_get_application_id(media); gint64 media_vol_size = osinfo_media_get_volume_size(media); + const gchar *reference_arch = osinfo_media_get_architecture(reference); const gchar *reference_volume = osinfo_media_get_volume_id(reference); const gchar *reference_system = osinfo_media_get_system_id(reference); const gchar *reference_publisher = osinfo_media_get_publisher_id(reference); @@ -1902,7 +1905,10 @@ gboolean osinfo_media_matches(OsinfoMedia *media, OsinfoMedia *reference) if (reference_vol_size <= 0) reference_vol_size = media_vol_size; - if (match_regex(reference_volume, media_volume) && + if ((!media_arch || + g_str_equal(reference_arch, media_arch) || + g_str_equal(reference_arch, "all")) && + match_regex(reference_volume, media_volume) && match_regex(reference_application, media_application) && match_regex(reference_system, media_system) && match_regex(reference_publisher, media_publisher) && diff --git a/tests/test-db.c b/tests/test-db.c index 79fe53e..ff645c7 100644 --- a/tests/test-db.c +++ b/tests/test-db.c @@ -472,6 +472,28 @@ test_identify_media(void) g_assert_false(osinfo_db_identify_media(db, media)); g_object_unref(media); + media = osinfo_media_new("foo", "x86_64"); + osinfo_entity_set_param(OSINFO_ENTITY(media), + OSINFO_MEDIA_PROP_VOLUME_ID, + "DB Media"); + osinfo_entity_set_param(OSINFO_ENTITY(media), + OSINFO_MEDIA_PROP_SYSTEM_ID, + "LINUX"); + + g_assert_false(osinfo_db_identify_media(db, media)); + g_object_unref(media); + + media = osinfo_media_new("foo", NULL); + osinfo_entity_set_param(OSINFO_ENTITY(media), + OSINFO_MEDIA_PROP_VOLUME_ID, + "DB Media"); + osinfo_entity_set_param(OSINFO_ENTITY(media), + OSINFO_MEDIA_PROP_SYSTEM_ID, + "LINUX"); + + g_assert_true(osinfo_db_identify_media(db, media)); + g_object_unref(media); + /* Matching against an "all" architecture */ media = osinfo_media_new("foo", "x86_64"); osinfo_entity_set_param(OSINFO_ENTITY(media), diff --git a/tests/test-media.c b/tests/test-media.c index 53a6124..81c8d0a 100644 --- a/tests/test-media.c +++ b/tests/test-media.c @@ -224,11 +224,20 @@ test_matching(void) NULL, NULL, 1234568); + /* Mis-match on arch */ + OsinfoMedia *reference6 = test_create_media("https://fedoraproject.org/fedora/35/media1", + "i686", + "Fedora 35", + NULL, + NULL, + NULL, + 0); g_assert(osinfo_media_matches(unknown, reference1)); g_assert(!osinfo_media_matches(unknown, reference2)); g_assert(osinfo_media_matches(unknown, reference3)); g_assert(osinfo_media_matches(unknown, reference4)); g_assert(!osinfo_media_matches(unknown, reference5)); + g_assert(!osinfo_media_matches(unknown, reference6)); } int -- cgit v1.2.1