diff options
author | Per Øyvind Karlsen <peroyvind@mandriva.org> | 2009-08-05 19:20:57 +0000 |
---|---|---|
committer | Per Øyvind Karlsen <peroyvind@mandriva.org> | 2009-08-05 19:20:57 +0000 |
commit | fee6493885dd548871e71824f049ea37c903c312 (patch) | |
tree | c2d1eda786a805246cb9715668b140041d6ba4d7 /URPM.xs | |
parent | d4d1a175ea6c4fe1770fcfa0d1f31eaeb9e1fb69 (diff) | |
download | perl-URPM-fee6493885dd548871e71824f049ea37c903c312.tar perl-URPM-fee6493885dd548871e71824f049ea37c903c312.tar.gz perl-URPM-fee6493885dd548871e71824f049ea37c903c312.tar.bz2 perl-URPM-fee6493885dd548871e71824f049ea37c903c312.tar.xz perl-URPM-fee6493885dd548871e71824f049ea37c903c312.zip |
store package filename based on rpm configuration rather than hardcoding it
Diffstat (limited to 'URPM.xs')
-rw-r--r-- | URPM.xs | 80 |
1 files changed, 61 insertions, 19 deletions
@@ -178,6 +178,55 @@ get_int(Header header, int32_t tag) { return ep ? *ep : 0; } +/* 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 char * +get_nvra(Header h) { + const char *qfmt = get_nvra_fmt(); + char *NVRA = headerFormat(h, qfmt, NULL); + return NVRA; +} + static int sigsize_to_filesize(int sigsize) { return sigsize + 440; /* 440 is the rpm header size (?) empirical, but works */ @@ -797,15 +846,12 @@ pack_header(URPM__Package pkg) { if (pkg->info == NULL) { char buff[1024]; char *p = buff; - char *name = get_name(pkg->h, RPMTAG_NAME); - char *version = get_name(pkg->h, RPMTAG_VERSION); - char *release = get_name(pkg->h, RPMTAG_RELEASE); - char *arch = headerIsEntry(pkg->h, RPMTAG_SOURCERPM) ? get_name(pkg->h, RPMTAG_ARCH) : "src"; - - p += 1 + snprintf(buff, sizeof(buff), "%s-%s-%s.%s@%d@%d@%s", name, version, release, arch, + char *nvra = get_nvra(pkg->h); + p += 1 + snprintf(buff, sizeof(buff), "%s@%d@%d@%s", nvra, get_int(pkg->h, RPMTAG_EPOCH), get_int(pkg->h, RPMTAG_SIZE), get_name(pkg->h, RPMTAG_GROUP)); pkg->info = memcpy(malloc(p-buff), buff, p-buff); + _free(nvra); } if (pkg->filesize == 0) pkg->filesize = sigsize_to_filesize(get_int(pkg->h, RPMTAG_SIGSIZE)); if (pkg->requires == NULL && pkg->suggests == NULL) @@ -1724,7 +1770,9 @@ Pkg_fullname(pkg) char *arch = headerIsEntry(pkg->h, RPMTAG_SOURCERPM) ? get_name(pkg->h, RPMTAG_ARCH) : "src"; if (gimme == G_SCALAR) { - XPUSHs(sv_2mortal(newSVpvf("%s-%s-%s.%s", name, version, release, arch))); + char *nvra = get_nvra(pkg->h); + XPUSHs(sv_2mortal(newSVpvf("%s", nvra))); + _free(nvra); } else if (gimme == G_ARRAY) { EXTEND(SP, 4); PUSHs(sv_2mortal(newSVpv(name, 0))); @@ -2003,12 +2051,9 @@ Pkg_filename(pkg) memcpy(eon, savbuf, 4); } } else if (pkg->h) { - char *name = get_name(pkg->h, RPMTAG_NAME); - char *version = get_name(pkg->h, RPMTAG_VERSION); - char *release = get_name(pkg->h, RPMTAG_RELEASE); - char *arch = headerIsEntry(pkg->h, RPMTAG_SOURCERPM) ? get_name(pkg->h, RPMTAG_ARCH) : "src"; - - XPUSHs(sv_2mortal(newSVpvf("%s-%s-%s.%s.rpm", name, version, release, arch))); + char *nvra = get_nvra(pkg->h); + XPUSHs(sv_2mortal(newSVpvf("%s.rpm", nvra))); + _free(nvra); } # deprecated @@ -2025,12 +2070,9 @@ Pkg_header_filename(pkg) } else if (pkg->h) { char buff[1024]; char *p = buff; - char *name = get_name(pkg->h, RPMTAG_NAME); - char *version = get_name(pkg->h, RPMTAG_VERSION); - char *release = get_name(pkg->h, RPMTAG_RELEASE); - char *arch = headerIsEntry(pkg->h, RPMTAG_SOURCERPM) ? get_name(pkg->h, RPMTAG_ARCH) : "src"; - - p += snprintf(buff, sizeof(buff), "%s-%s-%s.%s", name, version, release, arch); + char *nvra = get_nvra(pkg->h); + p += snprintf(buff, sizeof(buff), "%s", nvra); + _free(nvra); XPUSHs(sv_2mortal(newSVpv(buff, p-buff))); } |