[pacman-dev] [PATCH 1/4] pactest: Rename epoch pactests
Signed-off-by: Dan McGee <dan@archlinux.org> --- test/pacman/tests/{sync140.py => epoch001.py} | 0 test/pacman/tests/{sync141.py => epoch002.py} | 0 test/pacman/tests/{sync142.py => epoch003.py} | 0 test/pacman/tests/{sync143.py => epoch004.py} | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename test/pacman/tests/{sync140.py => epoch001.py} (100%) rename test/pacman/tests/{sync141.py => epoch002.py} (100%) rename test/pacman/tests/{sync142.py => epoch003.py} (100%) rename test/pacman/tests/{sync143.py => epoch004.py} (100%) diff --git a/test/pacman/tests/sync140.py b/test/pacman/tests/epoch001.py similarity index 100% rename from test/pacman/tests/sync140.py rename to test/pacman/tests/epoch001.py diff --git a/test/pacman/tests/sync141.py b/test/pacman/tests/epoch002.py similarity index 100% rename from test/pacman/tests/sync141.py rename to test/pacman/tests/epoch002.py diff --git a/test/pacman/tests/sync142.py b/test/pacman/tests/epoch003.py similarity index 100% rename from test/pacman/tests/sync142.py rename to test/pacman/tests/epoch003.py diff --git a/test/pacman/tests/sync143.py b/test/pacman/tests/epoch004.py similarity index 100% rename from test/pacman/tests/sync143.py rename to test/pacman/tests/epoch004.py -- 1.7.3.5
We were missing this in a few places; also add the ability to check the outcome via a new rule type. Signed-off-by: Dan McGee <dan@archlinux.org> --- test/pacman/pmdb.py | 2 ++ test/pacman/pmpkg.py | 4 ++++ test/pacman/pmrule.py | 3 +++ 3 files changed, 9 insertions(+), 0 deletions(-) diff --git a/test/pacman/pmdb.py b/test/pacman/pmdb.py index c275337..60460ce 100755 --- a/test/pacman/pmdb.py +++ b/test/pacman/pmdb.py @@ -252,6 +252,8 @@ def db_write(self, pkg): data.append(_mksection("SIZE", pkg.size)) if pkg.reason: data.append(_mksection("REASON", pkg.reason)) + if pkg.epoch: + data.append(_mksection("EPOCH", pkg.epoch)) else: data.append(_mksection("FILENAME", pkg.filename())) if pkg.replaces: diff --git a/test/pacman/pmpkg.py b/test/pacman/pmpkg.py index e0f3baa..3aabea4 100755 --- a/test/pacman/pmpkg.py +++ b/test/pacman/pmpkg.py @@ -132,6 +132,10 @@ def makepkg(self, path): data.append("builddate = %s" % self.builddate) data.append("packager = %s" % self.packager) data.append("size = %s" % self.size) + if self.force: + data.append("force = true") + if self.epoch: + data.append("epoch = %d" % self.epoch) if self.arch: data.append("arch = %s" % self.arch) for i in self.license: diff --git a/test/pacman/pmrule.py b/test/pacman/pmrule.py index 89ae3f4..bea8e4a 100755 --- a/test/pacman/pmrule.py +++ b/test/pacman/pmrule.py @@ -78,6 +78,9 @@ def check(self, root, retcode, localdb, files): elif case == "VERSION": if value != newpkg.version: success = 0 + elif case == "EPOCH": + if int(value) != newpkg.epoch: + success = 0 elif case == "DESC": if value != newpkg.desc: success = 0 -- 1.7.3.5
Signed-off-by: Dan McGee <dan@archlinux.org> --- test/pacman/tests/epoch001.py | 1 + test/pacman/tests/epoch002.py | 1 + test/pacman/tests/epoch003.py | 1 + test/pacman/tests/epoch004.py | 1 + test/pacman/tests/epoch010.py | 14 ++++++++++++++ test/pacman/tests/epoch011.py | 15 +++++++++++++++ test/pacman/tests/epoch012.py | 15 +++++++++++++++ 7 files changed, 48 insertions(+), 0 deletions(-) create mode 100644 test/pacman/tests/epoch010.py create mode 100644 test/pacman/tests/epoch011.py create mode 100644 test/pacman/tests/epoch012.py diff --git a/test/pacman/tests/epoch001.py b/test/pacman/tests/epoch001.py index b7ec9fc..e1d3114 100644 --- a/test/pacman/tests/epoch001.py +++ b/test/pacman/tests/epoch001.py @@ -11,3 +11,4 @@ self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_VERSION=dummy|1.0-1") +self.addrule("PKG_EPOCH=dummy|1") diff --git a/test/pacman/tests/epoch002.py b/test/pacman/tests/epoch002.py index dac81f7..9e8a048 100644 --- a/test/pacman/tests/epoch002.py +++ b/test/pacman/tests/epoch002.py @@ -11,3 +11,4 @@ self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_VERSION=dummy|1.0-1") +self.addrule("PKG_EPOCH=dummy|0") diff --git a/test/pacman/tests/epoch003.py b/test/pacman/tests/epoch003.py index 726ef30..17ca9bf 100644 --- a/test/pacman/tests/epoch003.py +++ b/test/pacman/tests/epoch003.py @@ -12,3 +12,4 @@ self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_VERSION=dummy|1.4-1") +self.addrule("PKG_EPOCH=dummy|2") diff --git a/test/pacman/tests/epoch004.py b/test/pacman/tests/epoch004.py index 2ee940a..ad3e995 100644 --- a/test/pacman/tests/epoch004.py +++ b/test/pacman/tests/epoch004.py @@ -16,3 +16,4 @@ self.addrule("PKG_VERSION=dummy|2.0-1") self.addrule("FILE_EXIST=bin/dummynew") self.addrule("!FILE_EXIST=bin/dummyold") +self.addrule("PKG_EPOCH=dummy|2") diff --git a/test/pacman/tests/epoch010.py b/test/pacman/tests/epoch010.py new file mode 100644 index 0000000..3277597 --- /dev/null +++ b/test/pacman/tests/epoch010.py @@ -0,0 +1,14 @@ +self.description = "usbutils case study: force in new package" + +sp = pmpkg("usbutils", "001-1") +sp.force = True +self.addpkg2db("sync", sp) + +lp = pmpkg("usbutils", "0.91-4") +self.addpkg2db("local", lp) + +self.args = "-Su" + +self.addrule("PACMAN_RETCODE=0") +self.addrule("PKG_VERSION=usbutils|001-1") +self.addrule("PKG_EPOCH=usbutils|1") diff --git a/test/pacman/tests/epoch011.py b/test/pacman/tests/epoch011.py new file mode 100644 index 0000000..2c064aa --- /dev/null +++ b/test/pacman/tests/epoch011.py @@ -0,0 +1,15 @@ +self.description = "usbutils case study: force stays, epoch now in local db" + +sp = pmpkg("usbutils", "002-1") +sp.force = True +self.addpkg2db("sync", sp) + +lp = pmpkg("usbutils", "001-1") +lp.epoch = 1 +self.addpkg2db("local", lp) + +self.args = "-Su" + +self.addrule("PACMAN_RETCODE=0") +self.addrule("PKG_VERSION=usbutils|002-1") +self.addrule("PKG_EPOCH=usbutils|1") diff --git a/test/pacman/tests/epoch012.py b/test/pacman/tests/epoch012.py new file mode 100644 index 0000000..e0c7314 --- /dev/null +++ b/test/pacman/tests/epoch012.py @@ -0,0 +1,15 @@ +self.description = "usbutils case study: maintainer screws up and removes force" + +sp = pmpkg("usbutils", "003-1") +self.addpkg2db("sync", sp) + +lp = pmpkg("usbutils", "002-1") +lp.epoch = 1 +self.addpkg2db("local", lp) + +self.args = "-Su" + +self.addrule("PACMAN_RETCODE=0") +# remember, this is how we have to handle this- 003 will not be installed +self.addrule("PKG_VERSION=usbutils|002-1") +self.addrule("PKG_EPOCH=usbutils|1") -- 1.7.3.5
Adapting from RPM, follow the [epoch:]version[-release] syntax. We can also borrow some of their parsing code for our purposes (thanks!). Add some new tests to our vercmp shell script tester for epoch comparisons, and then make the code work with these newfangled epoch specifiers. Signed-off-by: Dan McGee <dan@archlinux.org> --- The diff ends up being a lot bigger than the changes on this one. Basically, add one more preprocessing step to our public vercmp function that splits the triplet up and runs rpmvercmp() on each of the pieces. All original tests still pass and a bunch of new ones do as well, so I'm fairly confident I didn't break anything changing the parsing this time around. -Dan lib/libalpm/version.c | 157 +++++++++++++++++++++++++++++++++++------------ src/util/vercmp.c | 4 +- test/util/vercmptest.sh | 19 ++++++ 3 files changed, 138 insertions(+), 42 deletions(-) diff --git a/lib/libalpm/version.c b/lib/libalpm/version.c index 85cc2f5..eba6621 100644 --- a/lib/libalpm/version.c +++ b/lib/libalpm/version.c @@ -23,23 +23,66 @@ /* libalpm */ #include "util.h" -/** Compare two version strings and determine which one is 'newer'. - * Returns a value comparable to the way strcmp works. Returns 1 - * if a is newer than b, 0 if a and b are the same version, or -1 - * if b is newer than a. - * - * This function has been adopted from the rpmvercmp function located - * at lib/rpmvercmp.c, and was most recently updated against rpm - * version 4.4.2.3. Small modifications have been made to make it more - * consistent with the libalpm coding style. - * - * Keep in mind that the pkgrel is only compared if it is available - * on both versions handed to this function. For example, comparing - * 1.5-1 and 1.5 will yield 0; comparing 1.5-1 and 1.5-2 will yield - * -1 as expected. This is mainly for supporting versioned dependencies - * that do not include the pkgrel. +/** + * Some functions in this file have been adopted from the rpm source, notably + * 'rpmvercmp' located at lib/rpmvercmp.c and 'parseEVR' located at + * lib/rpmds.c. It was most recently updated against rpm version 4.8.1. Small + * modifications have been made to make it more consistent with the libalpm + * coding style. */ -int SYMEXPORT alpm_pkg_vercmp(const char *a, const char *b) + +/** + * Split EVR into epoch, version, and release components. + * @param evr [epoch:]version[-release] string + * @retval *ep pointer to epoch + * @retval *vp pointer to version + * @retval *rp pointer to release + */ +static void parseEVR(char *evr, const char **ep, const char **vp, + const char **rp) +{ + const char *epoch; + const char *version; + const char *release; + char *s, *se; + + s = evr; + /* s points to epoch terminator */ + while (*s && isdigit(*s)) s++; + /* se points to version terminator */ + se = strrchr(s, '-'); + + if(*s == ':') { + epoch = evr; + *s++ = '\0'; + version = s; + if(*epoch == '\0') { + epoch = "0"; + } + } else { + /* different from RPM- always assume 0 epoch */ + epoch = "0"; + version = evr; + } + if(se) { + *se++ = '\0'; + release = se; + } else { + release = NULL; + } + + if(ep) *ep = epoch; + if(vp) *vp = version; + if(rp) *rp = release; +} + +/** + * Compare alpha and numeric segments of two versions. + * return 1: a is newer than b + * 0: a and b are the same version + * -1: b is newer than a + */ +static int rpmvercmp(const char *a, const char *b) { char oldch1, oldch2; char *str1, *str2; @@ -49,13 +92,6 @@ int SYMEXPORT alpm_pkg_vercmp(const char *a, const char *b) int isnum; int ret = 0; - /* libalpm added code. ensure our strings are not null */ - if(!a) { - if(!b) return(0); - return(-1); - } - if(!b) return(1); - /* easy comparison to see if versions are identical */ if(strcmp(a, b) == 0) return(0); @@ -147,22 +183,6 @@ int SYMEXPORT alpm_pkg_vercmp(const char *a, const char *b) one = ptr1; *ptr2 = oldch2; two = ptr2; - - /* libalpm added code. check if version strings have hit the pkgrel - * portion. depending on which strings have hit, take correct action. - * this is all based on the premise that we only have one dash in - * the version string, and it separates pkgver from pkgrel. */ - if(*ptr1 == '-' && *ptr2 == '-') { - /* no-op, continue comparing since we are equivalent throughout */ - } else if(*ptr1 == '-') { - /* ptr1 has hit the pkgrel and ptr2 has not. continue version - * comparison after stripping the pkgrel from ptr1. */ - *ptr1 = '\0'; - } else if(*ptr2 == '-') { - /* ptr2 has hit the pkgrel and ptr1 has not. continue version - * comparison after stripping the pkgrel from ptr2. */ - *ptr2 = '\0'; - } } /* this catches the case where all numeric and alpha segments have */ @@ -179,7 +199,7 @@ int SYMEXPORT alpm_pkg_vercmp(const char *a, const char *b) * - if one is an alpha, two is newer. * - otherwise one is newer. * */ - if ( ( !*one && !isalpha((int)*two) ) + if ( (!*one && !isalpha((int)*two)) || isalpha((int)*one) ) { ret = -1; } else { @@ -192,4 +212,61 @@ cleanup: return(ret); } +/** Compare two version strings and determine which one is 'newer'. + * Returns a value comparable to the way strcmp works. Returns 1 + * if a is newer than b, 0 if a and b are the same version, or -1 + * if b is newer than a. + * + * Different epoch values for version strings will override any further + * comparison. If no epoch is provided, 0 is assumed. + * + * Keep in mind that the pkgrel is only compared if it is available + * on both versions handed to this function. For example, comparing + * 1.5-1 and 1.5 will yield 0; comparing 1.5-1 and 1.5-2 will yield + * -1 as expected. This is mainly for supporting versioned dependencies + * that do not include the pkgrel. + */ +int SYMEXPORT alpm_pkg_vercmp(const char *a, const char *b) +{ + char *full1, *full2; + const char *epoch1, *ver1, *rel1; + const char *epoch2, *ver2, *rel2; + int ret; + + /* ensure our strings are not null */ + if(!a && !b) { + return(0); + } else if(!a) { + return(-1); + } else if(!b) { + return(1); + } + /* another quick shortcut- if full version specs are equal */ + if(strcmp(a, b) == 0) { + return(0); + } + + /* Parse both versions into [epoch:]version[-release] triplets. We probably + * don't need epoch and release to support all the same magic, but it is + * easier to just run it all through the same code. */ + full1 = strdup(a); + full2 = strdup(b); + + /* parseEVR modifies passed in version, so have to dupe it first */ + parseEVR(full1, &epoch1, &ver1, &rel1); + parseEVR(full2, &epoch2, &ver2, &rel2); + + ret = rpmvercmp(epoch1, epoch2); + if(ret == 0) { + ret = rpmvercmp(ver1, ver2); + if(ret == 0 && rel1 && rel2) { + ret = rpmvercmp(rel1, rel2); + } + } + + free(full1); + free(full2); + return(ret); +} + /* vim: set ts=2 sw=2 noet: */ diff --git a/src/util/vercmp.c b/src/util/vercmp.c index a1da23c..adb5a42 100644 --- a/src/util/vercmp.c +++ b/src/util/vercmp.c @@ -24,8 +24,8 @@ #define BASENAME "vercmp" -/* forward declaration, comes from vercmp.o in libalpm source that is linked in - * directly so we don't have any library deps */ +/* forward declaration, comes from version.o in libalpm source that is linked + * in directly so we don't have any library deps */ int alpm_pkg_vercmp(const char *a, const char *b); static void usage(void) diff --git a/test/util/vercmptest.sh b/test/util/vercmptest.sh index fca0657..a9ed3b2 100755 --- a/test/util/vercmptest.sh +++ b/test/util/vercmptest.sh @@ -118,6 +118,25 @@ runtest 1.5.1 1.5.b 1 runtest 1.5.b-1 1.5.b 0 runtest 1.5-1 1.5.b -1 +# epoch included version comparisons +runtest 0:1.0 0:1.0 0 +runtest 0:1.0 0:1.1 -1 +runtest 1:1.0 0:1.0 1 +runtest 1:1.0 0:1.1 1 +runtest 1:1.0 2:1.1 -1 + +# epoch + sometimes present pkgrel +runtest 1:1.0 0:1.0-1 1 +runtest 1:1.0-1 0:1.1-1 1 + +# epoch included on one version +runtest 0:1.0 1.0 0 +runtest 0:1.0 1.1 -1 +runtest 0:1.1 1.0 1 +runtest 1:1.0 1.0 1 +runtest 1:1.0 1.1 1 +runtest 1:1.1 1.1 1 + #END TESTS echo -- 1.7.3.5
On 11/01/11 02:48, Dan McGee wrote:
Adapting from RPM, follow the [epoch:]version[-release] syntax. We can also borrow some of their parsing code for our purposes (thanks!). Add some new tests to our vercmp shell script tester for epoch comparisons, and then make the code work with these newfangled epoch specifiers.
Signed-off-by: Dan McGee<dan@archlinux.org>
Ack: Allan
+ /* different from RPM- always assume 0 epoch */ ^ space
participants (2)
-
Allan McRae
-
Dan McGee