From 6b4f0fe67d3380741c09b119887dcd7faa85734e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20=C3=98yvind=20Karlsen?= Date: Sun, 5 Dec 2010 07:33:34 +0000 Subject: just fetch RPMTAG_NVRA rather than messing with headerSprintf for get_nvra() --- URPM.xs | 51 ++++++--------------------------------------------- 1 file changed, 6 insertions(+), 45 deletions(-) diff --git a/URPM.xs b/URPM.xs index e1e2e9f..32cbefd 100644 --- a/URPM.xs +++ b/URPM.xs @@ -140,53 +140,14 @@ newSVpv_utf8(const char *s, STRLEN len) return sv; } -/* 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; -} +get_nvra(Header header) { + HE_t val = (HE_t)memset(alloca(sizeof(*val)), 0, sizeof(*val)); -static const char * -get_nvra(Header h) { - const char *qfmt = get_nvra_fmt(); - const char *NVRA = headerSprintf(h, qfmt, NULL, NULL, NULL); - return NVRA; + val->tag = RPMTAG_NVRA; + if(headerGet(header, val, 0)) + return val->p.str; + return ""; } static int -- cgit v1.2.1