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

rpm version comparisons...



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.


Does all this seem correct, or am going astray at any point (or ommiting
something important)?

Thanks...james





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