From 4d02e7e8a7ebd49f325ddc5a733f0f9e3d9ed69d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20=C3=98yvind=20Karlsen?= Date: Sun, 5 Dec 2010 08:52:51 +0000 Subject: back out just fetching RPMTAG_NVRA in get_nvra() for now as it'll lack distepoch & disttag.. --- URPM.xs | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/URPM.xs b/URPM.xs index dae51d7..adfa3ac 100644 --- a/URPM.xs +++ b/URPM.xs @@ -140,16 +140,71 @@ newSVpv_utf8(const char *s, STRLEN len) return sv; } +/* XXX: RPMTAG_NVRA doesn't have disttag & distepoch */ +#if 0 static const char * get_nvra(Header header) { HE_t val = (HE_t)memset(alloca(sizeof(*val)), 0, sizeof(*val)); val->tag = RPMTAG_NVRA; if(headerGet(header, val, 0)) - return val->p.str; + return val->p.str; return ""; } +#else + +/* Since the NVRA format won't change, we'll store it in a global variable so + * that we only have to expand the macro once. + */ +static const char *nvra_fmt = NULL; + +static const char * +get_nvra_fmt() { + if(!nvra_fmt) { + char *qfmt = rpmExpand("%{?___NVRA:%___NVRA}%{?!___NVRA:/%_build_name_fmt}", NULL); + /* On older rpm versions '%___NVRA' isn't defined, so then we'll have to create + * it from the '%_build_name_fmt' + */ + if(qfmt[0] == '/') { + char *tmp; + const char macroName[] = "___NVRA"; + if(strcasecmp(tmp = qfmt+strlen(qfmt)-4, ".rpm") == 0) + *tmp = '\0'; + tmp = qfmt; + /* As %{ARCH} will be incorrect with source rpms, we replace it with a + * conditional expression so that we get '.src.rpm' for source rpms. + * This we'll do in a uhm.. "creative" way replacing '%{ARCH}' with '%{XXXX}', + * which is a macro we'll define for the conditional expression, + * when expanded it will return the format macro with the conditional + * expression. + */ + while((size_t)(tmp = strcasestr(tmp, "%{ARCH}")+2) != 2)while(*tmp != '}') + *tmp++ = 'X'; + + rpmDefineMacro(NULL, "XXXX %%|ARCH?{%%|SOURCERPM?{%%{ARCH}}:{src}|}:{}|", RMIL_DEFAULT); + tmp = rpmExpand((tmp = strrchr(qfmt, '/')) ? tmp+1 : qfmt, NULL); + + qfmt = realloc(qfmt, strlen(tmp) + sizeof(macroName)+1); + sprintf(qfmt, "%s %s", macroName, tmp); + rpmDefineMacro(NULL, qfmt, RMIL_DEFAULT); + sprintf(qfmt, "%s", qfmt+sizeof(macroName)); + _free(tmp); + } + nvra_fmt = qfmt; + } + return nvra_fmt; +} + +static const char * +get_nvra(Header h) { + const char *qfmt = get_nvra_fmt(); + const char *NVRA = headerSprintf(h, qfmt, NULL, NULL, NULL); + return NVRA; +} + +#endif + static int do_rpmEVRcompare(const char *a, const char *b) { int compare; -- cgit v1.2.1