serverspec/serverspec — pull request #316 by vincentbernat (2013-12-17 15:38:11+00:00)
Title: package: fix version comparison

`Gem::Version` does not accept the same versions that are usually used
in packages. Notably, packages like to define an upstream version and a
downstream version. For example, `2.2.4-15` is the 15th iteration of the
Apache 2.2.4 package.

With Debian, there are some more complex conventions:

- epoch is a way to use a smaller version number while ensuring strict
increase of version numbers. For example, upstream was numbering with
versions like 2011, 2012, 2013 and suddenly go back to a 1.2, 1.3
versioning scheme. In this cases, distributions like Debian are using
an epoch: 1:1.2, 1:1.3. Each time there is a problem with version
numbering, epoch is increased. Default epoch is 0.

- tilde is a way to make a version smaller than any other versions
sharing the same suffix. This is used when backporting a version to a
previous version of the distribution. For example, you backport
Apache 2.2.14-15, the version will be something like
2.2.14-15~bpo60+1 which is inferior to 2.2.14-15 or
2.2.14-15+something1.

The proposed implementation is quite basic, not widely tested but works
with the cases described above. Debian provides `libdpkg-rubyXX`
packages containing a more comprehensive way to compare version but this
would add a dependency. I believe that the proposed implementation is
equivalent with version numbers that can be found in the
wild.