[Libosinfo] [PATCHv2 05/11] db: Use volume-size info for detection

Zeeshan Ali (Khattak) zeeshanak at gnome.org
Tue Mar 17 14:43:55 UTC 2015


If volume-size is known of a media, ensure that it's the same as media
being compared with, for detection. This will enable us to differentiate
ISOs with exactly same volume-id, system-id and application-id.

It's possible that we encounter two different ISOs that have the same
volume-size, not just the other IDs but chances of that happening are
extremely small. Even if that happens, this patch doesn't make things
worse for that scenario.
---
 osinfo/osinfo_db.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/osinfo/osinfo_db.c b/osinfo/osinfo_db.c
index 241ee47..9542d6e 100644
--- a/osinfo/osinfo_db.c
+++ b/osinfo/osinfo_db.c
@@ -548,6 +548,7 @@ osinfo_db_guess_os_from_media_internal(OsinfoDb *db,
     const gchar *media_system;
     const gchar *media_publisher;
     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);
@@ -556,6 +557,7 @@ osinfo_db_guess_os_from_media_internal(OsinfoDb *db,
     media_system = osinfo_media_get_system_id(media);
     media_publisher = osinfo_media_get_publisher_id(media);
     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) {
@@ -572,11 +574,16 @@ osinfo_db_guess_os_from_media_internal(OsinfoDb *db,
             const gchar *os_system = osinfo_media_get_system_id(os_media);
             const gchar *os_publisher = osinfo_media_get_publisher_id(os_media);
             const gchar *os_application = osinfo_media_get_application_id(os_media);
+            gint64 os_vol_size = osinfo_media_get_volume_size(os_media);
+
+            if (os_vol_size <= 0)
+                os_vol_size = media_vol_size;
 
             if (match_regex(os_volume, media_volume) &&
                 match_regex(os_application, media_application) &&
                 match_regex(os_system, media_system) &&
-                match_regex(os_publisher, media_publisher)) {
+                match_regex(os_publisher, media_publisher) &&
+                os_vol_size == media_vol_size) {
                 ret = os;
                 if (matched_media != NULL)
                     *matched_media = os_media;
-- 
2.1.0




More information about the Libosinfo mailing list