aboutsummaryrefslogtreecommitdiffstats
path: root/URPM.xs
diff options
context:
space:
mode:
authorPer Øyvind Karlsen <peroyvind@mandriva.org>2010-10-12 23:57:05 +0000
committerPer Øyvind Karlsen <peroyvind@mandriva.org>2010-10-12 23:57:05 +0000
commit548ee6869603b2f50ecd44cd30d8e4d18fa46e32 (patch)
treeb259d7d15db630917fac061a7646be4fc9c9636d /URPM.xs
parentf138e68cbd17940e258539f467ce8a896a169823 (diff)
downloadperl-URPM-548ee6869603b2f50ecd44cd30d8e4d18fa46e32.tar
perl-URPM-548ee6869603b2f50ecd44cd30d8e4d18fa46e32.tar.gz
perl-URPM-548ee6869603b2f50ecd44cd30d8e4d18fa46e32.tar.bz2
perl-URPM-548ee6869603b2f50ecd44cd30d8e4d18fa46e32.tar.xz
perl-URPM-548ee6869603b2f50ecd44cd30d8e4d18fa46e32.zip
add get_evr() and do_rpmEVRcmp() wrapper for using rpmEVRcompare() from rpmlib
Diffstat (limited to 'URPM.xs')
-rw-r--r--URPM.xs92
1 files changed, 54 insertions, 38 deletions
diff --git a/URPM.xs b/URPM.xs
index 87f687a..bae8a19 100644
--- a/URPM.xs
+++ b/URPM.xs
@@ -196,6 +196,20 @@ get_nvra(Header h) {
return NVRA;
}
+static int
+do_rpmEVRcmp(const char *a, const char *b) {
+ int compare;
+ EVR_t lEVR,
+ rEVR;
+ lEVR = rpmEVRnew(RPMSENSE_EQUAL, 0),
+ rEVR = rpmEVRnew(RPMSENSE_EQUAL, 0);
+ rpmEVRparse(a, lEVR);
+ rpmEVRparse(b, rEVR);
+ compare = rpmEVRcompare(lEVR, rEVR);
+ lEVR = rpmEVRfree(lEVR),
+ rEVR = rpmEVRfree(rEVR);
+ return compare;
+}
static const char *
get_name(Header header, rpmTag tag) {
@@ -221,6 +235,29 @@ get_int(Header header, rpmTag tag) {
return (val->t == RPM_UINT32_TYPE) ? val->p.ui32p[val->ix >= 0 ? val->ix : 0] : 0;
}
+/* This function might modify strings that needs to be reverted after use
+ * with restore_chars()
+ */
+static const char *
+get_evr(URPM__Package pkg) {
+ const char *evr = NULL;
+ if(pkg->provides) {
+ evr = strrchr(pkg->provides, ' ')+1;
+ char *tmp = strrchr(evr, ']');
+ if(tmp)
+ backup_char(tmp);
+ } else if(pkg->h) {
+ HE_t val = (HE_t)memset(alloca(sizeof(*val)), 0, sizeof(*val));
+ val->tag = RPMTAG_PROVIDEVERSION;
+ headerGet(pkg->h, val, 0);
+ evr = val->p.argv[val->c-1];
+ }
+ return evr;
+}
+
+/* This function might modify strings that needs to be reverted after use
+ * with restore_chars()
+ */
static int
get_fullname_parts(URPM__Package pkg, char **name, int *epoch, char **version, char **release, char **disttag, char **distepoch, char **arch, char **eos) {
char *_version = NULL, *_release = NULL, *_disttag = NULL, *_distepoch = NULL, *_arch = NULL, *_eos = NULL, *tmp = NULL;
@@ -1962,46 +1999,25 @@ Pkg_compare(pkg, evr)
char *evr
PREINIT:
int compare = 0;
- int _epoch;
- char *_version;
- char *_release;
- char *_distepoch;
- char *_eos;
- CODE:
- if(get_fullname_parts(pkg, NULL, &_epoch, &_version, &_release, &_distepoch, NULL, NULL, &_eos))
- croak("undefined package");
+ char *_evr;
+ CODE:
if (!compare) {
- char *epoch, *version, *release;
-
- /* extract epoch and version from evr */
- version = evr;
- while (*version && isdigit(*version)) version++;
- if (*version == ':') {
- epoch = evr;
- *version++ = 0;
- if (!*epoch) epoch = "0";
- compare = _epoch - (*epoch ? atoi(epoch) : 0);
- } else {
- /* there is no epoch defined, so assume epoch = 0 */
- version = evr;
- compare = _epoch;
- }
- if (!compare) {
- /* continue extracting release if any */
- if ((release = strrchr(version, '-')) != NULL) {
- *release++ = 0;
- compare = rpmvercmp(_version, version);
- if (!compare) {
- /* need to compare with release here */
- compare = rpmvercmp(_release, release);
- }
- } else {
- compare = rpmvercmp(_version, version);
- }
- }
+ const char *seps;
+ char *tmp;
+
+ _evr = (char*)get_evr(pkg);
+ /* This will remove fields from _evr (from the right) that evr is missing
+ * so that ie. if only version is given as an argument, it won't compare
+ * release etc.
+ */
+ for(seps = ":-:"; *seps != 0; seps++)
+ if((tmp = strrchr(_evr, *seps)) != NULL && strrchr(evr, *seps) == NULL)
+ backup_char(tmp);
+
+ compare = do_rpmEVRcmp(_evr, evr);
+ /* restore provides string modified */
+ restore_chars();
}
- /* restore info string modified */
- restore_chars();
RETVAL = compare;
OUTPUT:
RETVAL