aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPer Øyvind Karlsen <peroyvind@mandriva.org>2010-12-05 08:52:51 +0000
committerPer Øyvind Karlsen <peroyvind@mandriva.org>2010-12-05 08:52:51 +0000
commit4d02e7e8a7ebd49f325ddc5a733f0f9e3d9ed69d (patch)
tree46aa92079aceea7cfb1e828c949091080eef0f0d
parent36c1d586d607a9f8439b4bb25ce1b197fd367216 (diff)
downloadperl-URPM-4d02e7e8a7ebd49f325ddc5a733f0f9e3d9ed69d.tar
perl-URPM-4d02e7e8a7ebd49f325ddc5a733f0f9e3d9ed69d.tar.gz
perl-URPM-4d02e7e8a7ebd49f325ddc5a733f0f9e3d9ed69d.tar.bz2
perl-URPM-4d02e7e8a7ebd49f325ddc5a733f0f9e3d9ed69d.tar.xz
perl-URPM-4d02e7e8a7ebd49f325ddc5a733f0f9e3d9ed69d.zip
back out just fetching RPMTAG_NVRA in get_nvra() for now as it'll lack distepoch & disttag..
-rw-r--r--URPM.xs57
1 files changed, 56 insertions, 1 deletions
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;