summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabiano Fidêncio <fidencio@redhat.com>2019-11-05 15:56:28 +0100
committerFabiano Fidêncio <fidencio@redhat.com>2019-11-08 13:24:38 +0100
commit71cf18b07b830f7966dbd6b6705c0f9cddb5c587 (patch)
treec342e234a382b37042e6b3d32f9db5cb9ed0f106
parent4647abdfbfec074fe71835fac08514f51fc239dc (diff)
downloadlibosinfo-71cf18b07b830f7966dbd6b6705c0f9cddb5c587.tar.gz
db: Take the media's volume size into account when sorting the medias
If volume-size is not taken into account, when dealing with identical ISOs, we may end up wrongly matching an entry that has its volume-size with one which doesn't have the value, simply because the one which does not have the value may be declared first the in XML entry. Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com> Reviewed-by; Daniel P. Berrangé <berrange@redhat.com>
-rw-r--r--osinfo/osinfo_db.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/osinfo/osinfo_db.c b/osinfo/osinfo_db.c
index 328b251..e2845df 100644
--- a/osinfo/osinfo_db.c
+++ b/osinfo/osinfo_db.c
@@ -538,11 +538,21 @@ static gint media_volume_compare(gconstpointer a, gconstpointer b)
/* Order doesn't matter then */
return 0;
- if (strstr(volume_a, volume_b) != NULL)
+ if (strstr(volume_a, volume_b) != NULL) {
+ gint64 volume_size_a = osinfo_media_get_volume_size(media_a);
+ gint64 volume_size_b = osinfo_media_get_volume_size(media_b);
+
+ if (volume_size_a != -1 && volume_size_b == -1)
+ return -1;
+
+ if (volume_size_b != -1 && volume_size_a == -1)
+ return 1;
+
return -1;
- else
+ } else {
/* Sub-string comes later */
return 1;
+ }
}
static gboolean compare_media(OsinfoMedia *media,