[virt-tools-list] [libosinfo] Match substring regex in the end

Christophe Fergeau cfergeau at redhat.com
Tue Feb 7 10:22:10 UTC 2012


On Mon, Feb 06, 2012 at 08:23:01PM +0100, Zeeshan Ali (Khattak) wrote:
> 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;
> +}

Alternatively, I think sorting the regexp by length would work too even if
it's less accurate.

Christophe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/virt-tools-list/attachments/20120207/424a5315/attachment.sig>


More information about the virt-tools-list mailing list