[virt-tools-list] [libosinfo] Match substring regex in the end
Zeeshan Ali (Khattak)
zeeshanak at gnome.org
Mon Feb 6 19:23:01 UTC 2012
From: "Zeeshan Ali (Khattak)" <zeeshanak at gnome.org>
Sometimes volume-id expression of one architecture is a substring of
volume-id expression of another architecture for the same OS. For
example '.*G.*RMC.*' is volume-id expression for i386 media of win7,
while '.*G.*RMC.*X.*' is for x86_64. To avoid incorrect matching, we
need to ensure that matching is done against '.*G.*RMC.*X.*' first and
then '.*G.*RMC.*'.
---
osinfo/osinfo_db.c | 20 ++++++++++++++++++++
1 files changed, 20 insertions(+), 0 deletions(-)
diff --git a/osinfo/osinfo_db.c b/osinfo/osinfo_db.c
index 0e90f6e..b5ac506 100644
--- a/osinfo/osinfo_db.c
+++ b/osinfo/osinfo_db.c
@@ -321,6 +321,24 @@ void osinfo_db_add_deployment(OsinfoDb *db, OsinfoDeployment *deployment)
osinfo_list_add(OSINFO_LIST(db->priv->deployments), OSINFO_ENTITY(deployment));
}
+static gint media_volume_compare (gconstpointer a, gconstpointer b)
+{
+ OsinfoMedia *media_a = OSINFO_MEDIA(a);
+ OsinfoMedia *media_b = OSINFO_MEDIA(b);
+ const gchar *volume_a = osinfo_media_get_volume_id(media_a);
+ const gchar *volume_b = osinfo_media_get_volume_id(media_b);
+
+ if (volume_a == NULL || volume_b == NULL)
+ /* Order doesn't matter then */
+ return 0;
+
+ if (strstr(volume_a, volume_b) != NULL)
+ return -1;
+ else
+ /* Sub-string comes later */
+ return 1;
+}
+
/**
* osinfo_db_guess_os_from_media:
* @db: the database
@@ -357,6 +375,8 @@ OsinfoOs *osinfo_db_guess_os_from_media(OsinfoDb *db,
GList *medias = osinfo_list_get_elements(OSINFO_LIST(media_list));
GList *media_iter;
+ medias = g_list_sort(medias, media_volume_compare);
+
for (media_iter = medias; media_iter; media_iter = media_iter->next) {
OsinfoMedia *os_media = OSINFO_MEDIA(media_iter->data);
const gchar *os_volume = osinfo_media_get_volume_id(os_media);
--
1.7.7.6
More information about the virt-tools-list
mailing list