diff options
Diffstat (limited to 'URPM.xs')
-rw-r--r-- | URPM.xs | 72 |
1 files changed, 39 insertions, 33 deletions
@@ -157,36 +157,24 @@ newSVpv_utf8(const char *s, STRLEN len) static void get_fullname_parts(URPM__Package pkg, char **name, char **version, char **release, char **arch, char **eos) { char *_version = NULL, *_release = NULL, *_arch = NULL, *_eos = NULL; - int distepoch = 0; - char *tmp; - /* search through provides for distepoch */ - if ((tmp = pkg->provides)) { - do { - if((_eos = strchr(tmp, '@'))) - *_eos = 0; - - if((tmp = strchr(tmp, '[')) && - (tmp = strchr(tmp, '-')) && - (tmp = strchr(tmp, ':'))) - distepoch = 1; - if(_eos) { - *_eos++ = '@'; - tmp = _eos; - } - } while(!distepoch && _eos != NULL); - /* XXX: filename at end of line, don't bother to support it, just make sure - * for it not to cause crash... - */ - if ((tmp = strrchr(pkg->info, '.')) && !strcmp(tmp, ".rpm")) - distepoch = 0; - } + int i, disttag = 0; + char *tmp = pkg->info; + for (i = 0; i < 4 && tmp != NULL; i++) + tmp = strchr(++tmp, '@'); + if (tmp++ != NULL && *tmp != '@') + disttag = 1; + /* XXX: filename at end of line, don't bother to support it, just make sure + * for it not to cause crash... + */ + if ((tmp = strrchr(pkg->info, '.')) && !strcmp(tmp, ".rpm")) + disttag = 0; if ((_eos = strchr(pkg->info, '@')) != NULL) { *_eos = 0; /* mark end of string to enable searching backwards */ if ((_arch = strrchr(pkg->info, '.')) != NULL) { *_arch = 0; if ((release != NULL || version != NULL || name != NULL) && (_release = strrchr(pkg->info, '-')) != NULL) { - if (distepoch) { + if (disttag) { tmp = _release; while(tmp != _arch) { backup_char(tmp++); @@ -1736,7 +1724,7 @@ Pkg_release(pkg) get_fullname_parts(pkg, NULL, NULL, &release, &arch, NULL); if (arch - release < 1) croak("invalid fullname"); - XPUSHs(sv_2mortal(newSVpv(release, arch-release-1))); + XPUSHs(sv_2mortal(newSVpv(release, arch[-2] ? arch-release-1 : 0))); restore_chars(); } else if (pkg->h) { XPUSHs(sv_2mortal(newSVpv(get_name(pkg->h, RPMTAG_RELEASE), 0))); @@ -1968,7 +1956,7 @@ Pkg_fullname(pkg) EXTEND(SP, 4); PUSHs(sv_2mortal(newSVpv(name, version-name-1))); PUSHs(sv_2mortal(newSVpv(version, release-version-1))); - PUSHs(sv_2mortal(newSVpv(release, arch-release-1))); + PUSHs(sv_2mortal(newSVpv(release, arch[-2] ? arch-release-1 : 0))); PUSHs(sv_2mortal(newSVpv(arch == eos ? "" : arch, eos-arch))); restore_chars(); } @@ -2160,7 +2148,7 @@ Pkg_compare(pkg, evr) _epoch = get_int(pkg->h, RPMTAG_EPOCH); } else croak("undefined package"); if (!compare) { - char *epoch, *version, *release; + char *epoch, *version, *release, *distepoch; /* extract epoch and version from evr */ version = evr; @@ -2182,6 +2170,10 @@ Pkg_compare(pkg, evr) /* continue extracting release if any */ if ((release = strrchr(version, '-')) != NULL) { *release++ = 0; + /* XXX: compare distepoch rather than just ignoring? */ + if ((distepoch = strrchr(release, ':')) != NULL) + *distepoch++ = 0; + compare = rpmvercmp(_version, version); if (!compare) { /* need to compare with release here */ @@ -2190,6 +2182,8 @@ Pkg_compare(pkg, evr) compare = rpmvercmp(_release, release); } release[-1] = '-'; /* restore in memory modification */ + if (distepoch != NULL) + distepoch[-1] = ':'; } else { compare = rpmvercmp(_version, version); } @@ -2516,18 +2510,30 @@ Pkg_dirnames(pkg) void Pkg_distepoch(pkg) URPM::Package pkg PPCODE: -#ifdef RPMTAG_DISTEPOCH - if (pkg->h) { + if (pkg->info) { + int i; + char *tmp = pkg->info, *eos = NULL; + for (i = 0; i < 5 && tmp != NULL; i++) + tmp = strchr(++tmp, '@'); + if (tmp != NULL && *tmp) + eos = strchr(++tmp, '@'); + XPUSHs(sv_2mortal(newSVpv((tmp && *tmp != '@') ? tmp : "", eos ? eos-tmp : 0))); + } else if (pkg->h) { XPUSHs(sv_2mortal(newSVpv(get_name(pkg->h, RPMTAG_DISTEPOCH), 0))); } -#else - croak("distepoch isn't available with this rpm version"); -#endif void Pkg_disttag(pkg) URPM::Package pkg PPCODE: - if (pkg->h) { + if (pkg->info) { + int i; + char *tmp = pkg->info, *eos = NULL; + for (i = 0; i < 4 && tmp != NULL; i++) + tmp = strchr(++tmp, '@'); + if (tmp != NULL && *tmp) + eos = strchr(++tmp, '@'); + XPUSHs(sv_2mortal(newSVpv((tmp && *tmp != '@') ? tmp : "", eos ? eos-tmp : 0))); + } else if (pkg->h) { XPUSHs(sv_2mortal(newSVpv(get_name(pkg->h, RPMTAG_DISTTAG), 0))); } |