Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/libalpm/package.c36
-rw-r--r--pactest/tests/upgrade058.py2
-rwxr-xr-xpactest/vercmptest.sh39
3 files changed, 59 insertions, 18 deletions
diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c
index 07b5fa38..685a411f 100644
--- a/lib/libalpm/package.c
+++ b/lib/libalpm/package.c
@@ -566,8 +566,6 @@ alpm_list_t SYMEXPORT *alpm_pkg_compute_requiredby(pmpkg_t *pkg)
return(reqs);
}
-/** @} */
-
/** 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
@@ -577,6 +575,12 @@ alpm_list_t SYMEXPORT *alpm_pkg_compute_requiredby(pmpkg_t *pkg)
* 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.
*/
int SYMEXPORT alpm_pkg_vercmp(const char *a, const char *b)
{
@@ -688,6 +692,26 @@ 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.
+ * version 2 is newer iff we are not at the end of ptr2;
+ * if we are at end then one version had pkgrel and one did not */
+ ret = *ptr2 ? -1 : 0;
+ goto cleanup;
+ } else if(*ptr2 == '-') {
+ /* ptr2 has hit the pkgrel and ptr1 has not.
+ * version 1 is newer iff we are not at the end of ptr1;
+ * if we are at end then one version had pkgrel and one did not */
+ ret = *ptr1 ? 1 : 0;
+ goto cleanup;
+ }
}
/* this catches the case where all numeric and alpha segments have */
@@ -698,13 +722,6 @@ int SYMEXPORT alpm_pkg_vercmp(const char *a, const char *b)
goto cleanup;
}
- /* libalpm added code. one version string may have a pkgrel number, the
- * other may not. unless both have them, we ignore it and return 0. */
- if( (*one && *one == '-') || (*two && *two == '-') ) {
- ret = 0;
- goto cleanup;
- }
-
/* whichever version still has characters left over wins */
if (!*one) {
ret = -1;
@@ -718,6 +735,7 @@ cleanup:
return(ret);
}
+/** @} */
pmpkg_t *_alpm_pkg_new(void)
{
diff --git a/pactest/tests/upgrade058.py b/pactest/tests/upgrade058.py
index 76416802..109289ea 100644
--- a/pactest/tests/upgrade058.py
+++ b/pactest/tests/upgrade058.py
@@ -14,4 +14,4 @@ self.addpkg(p)
self.args = "-U %s" % p.filename()
self.addrule("PACMAN_RETCODE=1")
-self.addrule("!PKG_VERSION=pkg2|1.1")
+self.addrule("!PKG_VERSION=pkg2|1.1-1")
diff --git a/pactest/vercmptest.sh b/pactest/vercmptest.sh
index 62a3e32c..f8d457ee 100755
--- a/pactest/vercmptest.sh
+++ b/pactest/vercmptest.sh
@@ -19,22 +19,43 @@
# default binary if one was not specified as $1
bin='vercmp'
-# holds count of failed tests
+# holds counts of tests
+total=0
failure=0
# args:
+# pass ver1 ver2 ret expected
+pass() {
+ echo "test: ver1: $1 ver2: $2 ret: $3 expected: $4"
+ echo " --> pass"
+}
+
+# args:
# fail ver1 ver2 ret expected
fail() {
- echo "unexpected failure:"
- echo " ver1: $1 ver2: $2 ret: $3 expected: $4"
+ echo "test: ver1: $1 ver2: $2 ret: $3 expected: $4"
+ echo " ==> FAILURE"
failure=$(expr $failure + 1)
}
# args:
# runtest ver1 ver2 expected
runtest() {
+ # run the test
ret=$($bin $1 $2)
- [ $ret -eq $3 ] || fail $1 $2 $ret $3
+ func='pass'
+ [ $ret -eq $3 ] || func='fail'
+ $func $1 $2 $ret $3
+ total=$(expr $total + 1)
+ # and run its mirror case just to be sure
+ reverse=0
+ [ $3 -eq 1 ] && reverse=-1
+ [ $3 -eq -1 ] && reverse=1
+ ret=$($bin $2 $1)
+ func='pass'
+ [ $ret -eq $reverse ] || func='fail'
+ $func $1 $2 $ret $reverse
+ total=$(expr $total + 1)
}
# use first arg as our binary if specified
@@ -44,11 +65,9 @@ runtest() {
# all similar length, no pkgrel
runtest 1.5.0 1.5.0 0
-runtest 1.5.0 1.5.1 -1
runtest 1.5.1 1.5.0 1
# mixed length
-runtest 1.5 1.5.1 -1
runtest 1.5.1 1.5 1
# with pkgrel, simple
@@ -65,13 +84,17 @@ runtest 1.5-2 1.5.1-2 -1
# mixed pkgrel inclusion
runtest 1.5 1.5-1 0
runtest 1.5-1 1.5 0
+runtest 1.1-1 1.1 0
+runtest 1.0-1 1.1 -1
+runtest 1.1-1 1.0 1
#END TESTS
+echo
if [ $failure -eq 0 ]; then
- echo "All tests successful"
+ echo "All $total tests successful"
exit 0
fi
-echo "$failure failed tests"
+echo "$failure of $total tests failed"
exit 1