summaryrefslogtreecommitdiff
path: root/build/pack.c
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2011-05-18 13:23:29 +0300
committerPanu Matilainen <pmatilai@redhat.com>2011-05-18 13:36:14 +0300
commit96bfbe0486a2f488a6b44f396f8f812c330b1d91 (patch)
treeb6c6806b2c63d01a2c8399bb029098187f45cd3f /build/pack.c
parent4030d4b9d9160371f00a01971c61894eac2e18c2 (diff)
downloadrpm-96bfbe0486a2f488a6b44f396f8f812c330b1d91.tar.gz
rpm-96bfbe0486a2f488a6b44f396f8f812c330b1d91.tar.bz2
rpm-96bfbe0486a2f488a6b44f396f8f812c330b1d91.zip
Further simplify & cleanup script file (error) handling
- Simply always call addFileToFoo() and handle no scriptfile condition as early success case there (and allocate sb only if actually needed). - Consolidate error logging into addFileToTagAux(), removing the need for umphteen nearly identical rpmlog error messages + related logic. - Eliminate the now pointless addFileToFoo() wrapper functions and just call the main thing directly.
Diffstat (limited to 'build/pack.c')
-rw-r--r--build/pack.c111
1 files changed, 32 insertions, 79 deletions
diff --git a/build/pack.c b/build/pack.c
index 62aa8066c..84960f8cf 100644
--- a/build/pack.c
+++ b/build/pack.c
@@ -108,21 +108,29 @@ static rpmRC cpio_copy(FD_t fdo, CSA_t csa)
return RPMRC_OK;
}
-static rpmRC addFileToTagAux(rpmSpec spec, const char * file,
- Header h, rpmTagVal tag, int append)
+static rpmRC addFileToTag(rpmSpec spec, const char * file,
+ Header h, rpmTagVal tag, int append)
{
- StringBuf sb = newStringBuf();
+ StringBuf sb = NULL;
char buf[BUFSIZ];
char * fn;
FILE * f;
rpmRC rc = RPMRC_FAIL; /* assume failure */
+ /* no script file is not an error */
+ if (file == NULL)
+ return RPMRC_OK;
+
fn = rpmGetPath("%{_builddir}/%{?buildsubdir:%{buildsubdir}/}", file, NULL);
f = fopen(fn, "r");
- if (f == NULL)
+ if (f == NULL) {
+ rpmlog(RPMLOG_ERR,_("Could not open %s file: %s\n"),
+ rpmTagGetName(tag), file);
goto exit;
+ }
+ sb = newStringBuf();
if (append) {
const char *s = headerGetString(h, tag);
if (s) {
@@ -177,74 +185,22 @@ static const char * buildHost(void)
return(hostname);
}
-static rpmRC addFileToTag(rpmSpec spec, const char * file,
- Header h, rpmTagVal tag)
-{
- return addFileToTagAux(spec, file, h, tag, 1);
-}
-
-static rpmRC addFileToArrayTag(rpmSpec spec, const char *file,
- Header h, rpmTagVal tag)
-{
- return addFileToTagAux(spec, file, h, tag, 0);
-}
-
-/**
- */
static rpmRC processScriptFiles(rpmSpec spec, Package pkg)
{
struct TriggerFileEntry *p;
int addflags = 0;
+ rpmRC rc = RPMRC_FAIL;
+ Header h = pkg->header;
- if (pkg->preInFile) {
- if (addFileToTag(spec, pkg->preInFile, pkg->header, RPMTAG_PREIN)) {
- rpmlog(RPMLOG_ERR,
- _("Could not open PreIn file: %s\n"), pkg->preInFile);
- return RPMRC_FAIL;
- }
- }
- if (pkg->preUnFile) {
- if (addFileToTag(spec, pkg->preUnFile, pkg->header, RPMTAG_PREUN)) {
- rpmlog(RPMLOG_ERR,
- _("Could not open PreUn file: %s\n"), pkg->preUnFile);
- return RPMRC_FAIL;
- }
- }
- if (pkg->preTransFile) {
- if (addFileToTag(spec, pkg->preTransFile, pkg->header, RPMTAG_PRETRANS)) {
- rpmlog(RPMLOG_ERR,
- _("Could not open PreTrans file: %s\n"), pkg->preTransFile);
- return RPMRC_FAIL;
- }
- }
- if (pkg->postInFile) {
- if (addFileToTag(spec, pkg->postInFile, pkg->header, RPMTAG_POSTIN)) {
- rpmlog(RPMLOG_ERR,
- _("Could not open PostIn file: %s\n"), pkg->postInFile);
- return RPMRC_FAIL;
- }
- }
- if (pkg->postUnFile) {
- if (addFileToTag(spec, pkg->postUnFile, pkg->header, RPMTAG_POSTUN)) {
- rpmlog(RPMLOG_ERR,
- _("Could not open PostUn file: %s\n"), pkg->postUnFile);
- return RPMRC_FAIL;
- }
- }
- if (pkg->postTransFile) {
- if (addFileToTag(spec, pkg->postTransFile, pkg->header, RPMTAG_POSTTRANS)) {
- rpmlog(RPMLOG_ERR,
- _("Could not open PostTrans file: %s\n"), pkg->postTransFile);
- return RPMRC_FAIL;
- }
- }
- if (pkg->verifyFile) {
- if (addFileToTag(spec, pkg->verifyFile, pkg->header,
- RPMTAG_VERIFYSCRIPT)) {
- rpmlog(RPMLOG_ERR,
- _("Could not open VerifyScript file: %s\n"), pkg->verifyFile);
- return RPMRC_FAIL;
- }
+ if (addFileToTag(spec, pkg->preInFile, h, RPMTAG_PREIN, 1) ||
+ addFileToTag(spec, pkg->preUnFile, h, RPMTAG_PREUN, 1) ||
+ addFileToTag(spec, pkg->preTransFile, h, RPMTAG_PRETRANS, 1) ||
+ addFileToTag(spec, pkg->postInFile, h, RPMTAG_POSTIN, 1) ||
+ addFileToTag(spec, pkg->postUnFile, h, RPMTAG_POSTUN, 1) ||
+ addFileToTag(spec, pkg->postTransFile, h, RPMTAG_POSTTRANS, 1) ||
+ addFileToTag(spec, pkg->verifyFile, h, RPMTAG_VERIFYSCRIPT, 1))
+ {
+ goto exit;
}
/* if any trigger has flags, we need to add flags entry for all of them */
@@ -256,30 +212,27 @@ static rpmRC processScriptFiles(rpmSpec spec, Package pkg)
}
for (p = pkg->triggerFiles; p != NULL; p = p->next) {
- headerPutString(pkg->header, RPMTAG_TRIGGERSCRIPTPROG, p->prog);
+ headerPutString(h, RPMTAG_TRIGGERSCRIPTPROG, p->prog);
if (addflags) {
- headerPutUint32(pkg->header, RPMTAG_TRIGGERSCRIPTFLAGS,
- &p->flags, 1);
+ headerPutUint32(h, RPMTAG_TRIGGERSCRIPTFLAGS, &p->flags, 1);
}
if (p->script) {
- headerPutString(pkg->header, RPMTAG_TRIGGERSCRIPTS, p->script);
+ headerPutString(h, RPMTAG_TRIGGERSCRIPTS, p->script);
} else if (p->fileName) {
- if (addFileToArrayTag(spec, p->fileName, pkg->header,
- RPMTAG_TRIGGERSCRIPTS)) {
- rpmlog(RPMLOG_ERR,
- _("Could not open Trigger script file: %s\n"),
- p->fileName);
- return RPMRC_FAIL;
+ if (addFileToTag(spec, p->fileName, h, RPMTAG_TRIGGERSCRIPTS, 0)) {
+ goto exit;
}
} else {
/* This is dumb. When the header supports NULL string */
/* this will go away. */
- headerPutString(pkg->header, RPMTAG_TRIGGERSCRIPTS, "");
+ headerPutString(h, RPMTAG_TRIGGERSCRIPTS, "");
}
}
+ rc = RPMRC_OK;
- return RPMRC_OK;
+exit:
+ return rc;
}
static rpmRC writeRPM(Header *hdrp, unsigned char ** pkgidp, const char *fileName,