summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemi Collet <remi@remirepo.net>2020-03-10 11:32:27 +0100
committerRemi Collet <remi@remirepo.net>2020-03-10 11:32:27 +0100
commit97b001f8bd05dd1dab189fdda8c02f9dd998827d (patch)
treedb145b852fbf464b8f0fce2b01700be9b657f9ba
parent23b2a30f034e9cb184eef60c6dd235fe500dfa4a (diff)
fix rpmvercmp logic
-rw-r--r--rpminfo.c46
-rw-r--r--tests/002-rpmvercmp.phpt8
2 files changed, 48 insertions, 6 deletions
diff --git a/rpminfo.c b/rpminfo.c
index 263270a..23bbf57 100644
--- a/rpminfo.c
+++ b/rpminfo.c
@@ -289,14 +289,54 @@ ZEND_END_ARG_INFO()
Compare 2 RPM evr (epoch:version-release) strings */
PHP_FUNCTION(rpmvercmp)
{
- char *evr1, *evr2;
+ char *evr1, *evr2, *v1, *r1, *v2, *r2, *p;
+ char empty[] = "";
size_t len1, len2;
+ long e1, e2, r;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &evr1, &len1, &evr2, &len2) == FAILURE) {
return;
}
-
- RETURN_LONG(rpmvercmp(evr1, evr2));
+ p = strchr(evr1, ':');
+ if (p) {
+ v1 = p+1;
+ *p=0;
+ e1 = atol(evr1);
+ } else {
+ v1 = evr1;
+ e1 = 0;
+ }
+ p = strchr(evr2, ':');
+ if (p) {
+ v2 = p+1;
+ *p=0;
+ e2 = atol(evr2);
+ } else {
+ v2 = evr2;
+ e2 = 0;
+ }
+ if (e1 != e2) {
+ RETURN_LONG(e1 - e2);
+ }
+ p = strchr(v1, '-');
+ if (p) {
+ r1 = p+1;
+ *p = 0;
+ } else {
+ r1 = empty;
+ }
+ p = strchr(v2, '-');
+ if (p) {
+ r2 = p+1;
+ *p = 0;
+ } else {
+ r2 = empty;
+ }
+ r = rpmvercmp(v1, v2);
+ if (r) {
+ RETURN_LONG(r);
+ }
+ RETURN_LONG(rpmvercmp(r1, r2));
}
/* }}} */
diff --git a/tests/002-rpmvercmp.phpt b/tests/002-rpmvercmp.phpt
index 6cffef0..909ad0f 100644
--- a/tests/002-rpmvercmp.phpt
+++ b/tests/002-rpmvercmp.phpt
@@ -7,6 +7,7 @@ Check for rpmvercmp function
var_dump(rpmvercmp("1.0", "1.1"));
var_dump(rpmvercmp("1.1", "1.0"));
var_dump(rpmvercmp("1.0", "1.0"));
+var_dump(rpmvercmp("2.0.14-22.el7_0", "2.0.14.1-35.el7_6"));
// Errors
var_dump(rpmvercmp());
var_dump(rpmvercmp("a"));
@@ -17,13 +18,14 @@ Done
int(-1)
int(1)
int(0)
+int(-1)
-Warning: rpmvercmp() expects exactly 2 parameters, 0 given in %s/002-rpmvercmp.php on line 6
+Warning: rpmvercmp() expects exactly 2 parameters, 0 given in %s/002-rpmvercmp.php on line %d
NULL
-Warning: rpmvercmp() expects exactly 2 parameters, 1 given in %s/002-rpmvercmp.php on line 7
+Warning: rpmvercmp() expects exactly 2 parameters, 1 given in %s/002-rpmvercmp.php on line %d
NULL
-Warning: rpmvercmp() expects exactly 2 parameters, 3 given in %s/002-rpmvercmp.php on line 8
+Warning: rpmvercmp() expects exactly 2 parameters, 3 given in %s/002-rpmvercmp.php on line %d
NULL
Done