Comparing RPM version strings, RPM version algorithm, rpmvercmp

01 Apr 2010

Given two RPM version strings, which one is more recent? The algorithm isn't explained (at least not that I could find), and apparently it's been screwed up a few times (where a < b and b < a for certain values)

I had to hack the source to make a command tool. The source is here. Just compile and go

$ gcc rpmver.c
$ ./a.out 1 2
1 < 2

For simple stuff, yeah,

1.9.2 < 1.9.2.8
1.9.2 < 1.9.3
1.9 < 2

others aren't so obvious.

1 < 2010
1 < -2010
1 < +2010
1 < ~2010
1 < 02010
1 > 0.2010
1 < 2010x
1 > x2010
0.201 < 0.2010
1 < 1-0
1-0 < 1-1

Comment 2010-04-06 by None

1 < 2010
this isn't "obvious"?

1 < -2010
1 < +2010
1 < ~2010
The comparison does NOT include signs. In fact
all non-alpha, non-digits, are created equal and
ignored by rpmvercmp (and RPM comparisons).

1 < 02010
I guess this REALLY isn't "obvious" (to you). ;-)

1 > 0.2010
These are integer, not float, comparisons. 1 is indeed larger than 0.

1 < 2010x
This is still very very "obvious" even if your repetion obscures.

1 > x2010
This ISNT obvious. In fact its counter intuitive if
one is used to ASCII collation. But breaking ASCII
collation ordering is/was a RFE from Mandriva (nee Mandrake)
a long time ago. See bugzilla #50977 @redhat.com for the RFE.

0.201 < 0.2010
This isn't obvious if one is expecting float comparisons
because of the single decimal point. But note that
interpreting 0.201 fractionally will never generalize
to ISO versioning like MAJOR.MINOR.MICRO. And its
true that "201 < 2010" which is actually the comparison
being performed.

1 < 1-0
1-0 < 1-1
rpmvercmp is NEVER passed a '-' character by RPM itself,
and a '-' character is FORBIDDEN in all Version: and Release:
strings so that a single dependency string like E:V-R
(E == Epoch, V == Version, R == Release) can be unambigously
split into components in spite of missing (as in unspecified) R.


Comment 2010-04-07 by None

Hi there. Many in the second box are, yes, obvious. And all your points are very valid (and helpful). In fact your comments are better than anything I found on the Red Hat or RPM website! Maybe I missed something.

My examples above aren't too complicated. But many times people start throwing whole words and whatnot -- then It's not so clear. And then try and compare it to the debian algorithm. They differ in subtle ways, especially in characters that are ignored.

Anyways it would be nice if RPM had a command line option to compare two versions strings.


Comment 2010-04-07 by None

if for some reason you are reading this, you might be interested in this

http://semver.org/