[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

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



On Tue, Feb 7, 2012 at 12:22 PM, Christophe Fergeau <cfergeau redhat com> wrote:
> On Mon, Feb 06, 2012 at 08:23:01PM +0100, Zeeshan Ali (Khattak) wrote:
>> From: "Zeeshan Ali (Khattak)" <zeeshanak 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.

Hmm.. Perhaps! I would like to get this fixed ASAP so I'll push my patch now.

-- 
Regards,

Zeeshan Ali (Khattak)
FSF member#5124


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]