summaryrefslogtreecommitdiff
path: root/build
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2008-05-06 12:48:09 +0300
committerPanu Matilainen <pmatilai@redhat.com>2008-05-06 12:48:09 +0300
commite907b912f9e237bc840d714e4e03f4d26deafe0c (patch)
tree99e7c24da1e23bc35e4138e11be1cfd38df85949 /build
parent41147e5b18ad09b04697c3aa729539689547281c (diff)
downloadrpm-e907b912f9e237bc840d714e4e03f4d26deafe0c.tar.gz
rpm-e907b912f9e237bc840d714e4e03f4d26deafe0c.tar.bz2
rpm-e907b912f9e237bc840d714e4e03f4d26deafe0c.zip
Eliminate nasty hackery with "special" doc + docdir format
- figure out docdir early on in spec parsing, store in package struct instead of abusing parse buffer - fixes memleaks from docdir_fmt and headerSprintf too
Diffstat (limited to 'build')
-rw-r--r--build/files.c29
-rw-r--r--build/parsePreamble.c30
-rw-r--r--build/rpmspec.h1
-rw-r--r--build/spec.c2
4 files changed, 36 insertions, 26 deletions
diff --git a/build/files.c b/build/files.c
index 18b71b338..e7074dd82 100644
--- a/build/files.c
+++ b/build/files.c
@@ -863,39 +863,16 @@ static rpmRC parseForSimple(rpmSpec spec, Package pkg, char * buf,
(*fileName ? *fileName : ""));
res = RPMRC_FAIL;
} else {
- /* XXX WATCHOUT: buf is an arg */
- {
- static const char *_docdir_fmt = NULL;
- static int oneshot = 0;
- char *ddir, *fmt;
- errmsg_t errstr;
- if (!oneshot) {
- _docdir_fmt = rpmExpand("%{?_docdir_fmt}", NULL);
- if (!_docdir_fmt || !*_docdir_fmt)
- _docdir_fmt = "%{NAME}-%{VERSION}";
- oneshot = 1;
- }
- fmt = headerSprintf(pkg->header, _docdir_fmt, rpmTagTable, rpmHeaderFormats, &errstr);
- if (!fmt) {
- rpmlog(RPMLOG_ERR, _("illegal _docdir_fmt: %s\n"), errstr);
- res = RPMRC_FAIL;
- }
- ddir = rpmGetPath("%{_docdir}/", fmt, NULL);
- strcpy(buf, ddir);
- ddir = _free(ddir);
- }
-
- /* XXX FIXME: this is easy to do as macro expansion */
-
+ /* XXX FIXME: this is easy to do as macro expansion */
if (! fl->passedSpecialDoc) {
pkg->specialDoc = newStringBuf();
appendStringBuf(pkg->specialDoc, "DOCDIR=$RPM_BUILD_ROOT");
- appendLineStringBuf(pkg->specialDoc, buf);
+ appendLineStringBuf(pkg->specialDoc, pkg->specialDocDir);
appendLineStringBuf(pkg->specialDoc, "export DOCDIR");
appendLineStringBuf(pkg->specialDoc, "rm -rf $DOCDIR");
appendLineStringBuf(pkg->specialDoc, RPM_MKDIR_P " $DOCDIR");
- *fileName = buf;
+ *fileName = pkg->specialDocDir;
fl->passedSpecialDoc = 1;
fl->isSpecialDoc = 1;
}
diff --git a/build/parsePreamble.c b/build/parsePreamble.c
index 9a23fcb4a..f606100e3 100644
--- a/build/parsePreamble.c
+++ b/build/parsePreamble.c
@@ -327,6 +327,31 @@ static void fillOutMainPackage(Header h)
}
}
+static int getSpecialDocDir(Package pkg)
+{
+ const char *errstr, *docdir_fmt = "%{NAME}-%{VERSION}";
+ char *fmt_macro, *fmt;
+ int rc = -1;
+
+ fmt_macro = rpmExpand("%{?_docdir_fmt}", NULL);
+ if (fmt_macro && strlen(fmt_macro) > 0) {
+ docdir_fmt = fmt_macro;
+ }
+ fmt = headerSprintf(pkg->header, docdir_fmt,
+ rpmTagTable, rpmHeaderFormats, &errstr);
+ if (!fmt) {
+ rpmlog(RPMLOG_ERR, _("illegal _docdir_fmt: %s\n"), errstr);
+ goto exit;
+ }
+ pkg->specialDocDir = rpmGetPath("%{_docdir}/", fmt, NULL);
+ rc = 0;
+
+exit:
+ free(fmt);
+ free(fmt_macro);
+ return rc;
+}
+
/**
*/
static rpmRC readIcon(Header h, const char * file)
@@ -900,6 +925,11 @@ int parsePreamble(rpmSpec spec, int initialPackage)
if (checkForRequired(pkg->header, NVR)) {
goto exit;
}
+
+ if (getSpecialDocDir(pkg)) {
+ goto exit;
+ }
+
/* if we get down here nextPart has been set to non-error */
res = nextPart;
diff --git a/build/rpmspec.h b/build/rpmspec.h
index 77c7b309d..31a6087c3 100644
--- a/build/rpmspec.h
+++ b/build/rpmspec.h
@@ -167,6 +167,7 @@ struct Package_s {
char * verifyFile; /*!< %verifyscript scriptlet. */
StringBuf specialDoc;
+ char *specialDocDir;
struct TriggerFileEntry * triggerFiles;
diff --git a/build/spec.c b/build/spec.c
index 9f9c6f23a..038839c47 100644
--- a/build/spec.c
+++ b/build/spec.c
@@ -131,6 +131,7 @@ Package newPackage(rpmSpec spec)
p->verifyFile = NULL;
p->specialDoc = NULL;
+ p->specialDocDir = NULL;
if (spec->packages == NULL) {
spec->packages = p;
@@ -166,6 +167,7 @@ Package freePackage(Package pkg)
}
pkg->specialDoc = freeStringBuf(pkg->specialDoc);
+ pkg->specialDocDir = _free(pkg->specialDocDir);
pkg->icon = freeSources(pkg->icon);
pkg->triggerFiles = freeTriggerFiles(pkg->triggerFiles);