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

Re: rpm version comparisons...

On Sat, Jan 18, 2003 at 08:30:18AM -0500, James Olin Oden wrote:
> Hi All,
> I just went through the source for the rpmVersionCompare() and rpmvercmp()
> functions to determine exactly how rpm compares versions.  
> Given rpm's A and B the following is what I believe the code is doing:
>         1) First compare epoch's:
>                 - Does A have an epoch and B does not.  A is newer.
>                 - Does B have an epoch and A does not.  B is newer.
>                 - Do both have epechs.  The one with greater epoch
>                   is newer.
>                 - Are the epochs equal...go on to the next check.
>                 - Do neither have epochs...go on to next check.
>         2) Next we compare rpm versions:
>                 - Are the version's equal....go on to the next check.
>                   (this is done with a simple strcmp() between the
>                   two versions).
>                 - Loop through each alpha numeric section of te
>                   version (basically split it on non alphanumeric
>                   characters).  Further split on alpha versus
>                   numeric sections.   For instance the following
>                   version, 1.005p2 would be split into the following
>                   components:
>                         1, 005, p, 2
>                   Now that we have all the sections, compare each one
>                   from left to right (in decreasing magnitude in
>                   other words):
>                         -  If either of the version segments are empty
>                            B is the newer one.  This is quite arbitrary
>                            but it is the way it works (and I am not sure
>                            what other methodology would be better; if this
>                            was a problem with a package, then its probably
>                            time to use epoch's.).
>                         -  If the version segment is numerical:
>                                 - Throw out leading zeros.
>                                 - If one number has more digits, that one
>                                   is newer.
>                         - use strcmp() from stdio to compare the segments.
>                           Whichever version segment is greater is newer.
>                 - At this point whichever version string still has characters
>                   left over is newer.
>         3) Then we compare releases.  Releases are compared in exactly the
>            same way as the versions.
>         4) If all these comparison's yield equal then the RPM is equal.

Yes, basically correct, rpmvercmp et al have not ever changed in any
meaningful way. Note "basically" and "meaningful", please.

The devil is in the details, however. Are you looking at a specific
problem, or are you just looking for general information? If specific,
details please.

73 de Jeff

Jeff Johnson	ARS N3NPQ
jbj@redhat.com (jbj@jbj.org)
Chapel Hill, NC

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