1996-06-08 02:31:31 +08:00
|
|
|
#include <sys/types.h>
|
1998-01-13 05:31:29 +08:00
|
|
|
#include <sys/stat.h>
|
1995-12-21 06:49:40 +08:00
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <fcntl.h>
|
1998-01-13 05:31:29 +08:00
|
|
|
#include <malloc.h>
|
1996-06-08 02:31:31 +08:00
|
|
|
#include <string.h>
|
1996-06-19 01:07:21 +08:00
|
|
|
#include <errno.h>
|
1998-01-13 05:31:29 +08:00
|
|
|
#include <signal.h>
|
|
|
|
#include <time.h>
|
1998-03-05 00:51:06 +08:00
|
|
|
#include <stdlib.h>
|
1995-12-21 06:49:40 +08:00
|
|
|
|
1996-06-08 02:31:31 +08:00
|
|
|
#include "spec.h"
|
1998-01-13 05:31:29 +08:00
|
|
|
#include "header.h"
|
1995-12-21 06:49:40 +08:00
|
|
|
#include "misc.h"
|
1998-01-13 05:31:29 +08:00
|
|
|
#include "reqprov.h"
|
1996-06-08 02:31:31 +08:00
|
|
|
#include "names.h"
|
1998-01-13 05:31:29 +08:00
|
|
|
#include "macro.h"
|
|
|
|
|
|
|
|
#include "rpmlib.h"
|
1996-06-08 02:31:31 +08:00
|
|
|
#include "files.h"
|
1998-01-13 05:31:29 +08:00
|
|
|
#include "lib/cpio.h"
|
|
|
|
#include "lib/misc.h"
|
|
|
|
#include "lib/signature.h"
|
|
|
|
#include "lib/rpmlead.h"
|
|
|
|
#include "lib/messages.h"
|
|
|
|
|
|
|
|
#define RPM_MAJOR_NUMBER 3
|
|
|
|
|
|
|
|
static int processScriptFiles(Spec spec, Package pkg);
|
1998-03-21 06:38:00 +08:00
|
|
|
static StringBuf addFileToTagAux(Spec spec, char *file, StringBuf sb);
|
1998-01-13 05:31:29 +08:00
|
|
|
static int addFileToTag(Spec spec, char *file, Header h, int tag);
|
1998-03-21 06:38:00 +08:00
|
|
|
static int addFileToArrayTag(Spec spec, char *file, Header h, int tag);
|
1998-01-13 05:31:29 +08:00
|
|
|
static int writeRPM(Header header, char *fileName, int type,
|
|
|
|
struct cpioFileMapping *cpioList, int cpioCount,
|
|
|
|
char *passPhrase, char **cookie);
|
|
|
|
static int cpio_gzip(int fd, struct cpioFileMapping *cpioList,
|
|
|
|
int cpioCount, int *archiveSize);
|
|
|
|
|
1998-04-08 07:58:01 +08:00
|
|
|
static int genSourceRpmName(Spec spec)
|
1998-01-13 05:31:29 +08:00
|
|
|
{
|
|
|
|
char *name, *version, *release;
|
|
|
|
char fileName[BUFSIZ];
|
1998-04-08 07:58:01 +08:00
|
|
|
|
|
|
|
if (spec->sourceRpmName) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
headerGetEntry(spec->packages->header, RPMTAG_NAME,
|
|
|
|
NULL, (void **)&name, NULL);
|
|
|
|
headerGetEntry(spec->packages->header, RPMTAG_VERSION,
|
|
|
|
NULL, (void **)&version, NULL);
|
|
|
|
headerGetEntry(spec->packages->header, RPMTAG_RELEASE,
|
|
|
|
NULL, (void **)&release, NULL);
|
|
|
|
sprintf(fileName, "%s-%s-%s.%ssrc.rpm", name, version, release,
|
|
|
|
spec->noSource ? "no" : "");
|
|
|
|
spec->sourceRpmName = strdup(fileName);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int packageSources(Spec spec)
|
|
|
|
{
|
|
|
|
char fileName[BUFSIZ];
|
1998-01-13 05:31:29 +08:00
|
|
|
HeaderIterator iter;
|
|
|
|
int_32 tag, count;
|
|
|
|
char **ptr;
|
|
|
|
|
|
|
|
/* Add some cruft */
|
|
|
|
headerAddEntry(spec->sourceHeader, RPMTAG_RPMVERSION,
|
|
|
|
RPM_STRING_TYPE, VERSION, 1);
|
|
|
|
headerAddEntry(spec->sourceHeader, RPMTAG_BUILDHOST,
|
|
|
|
RPM_STRING_TYPE, buildHost(), 1);
|
|
|
|
headerAddEntry(spec->sourceHeader, RPMTAG_BUILDTIME,
|
|
|
|
RPM_INT32_TYPE, getBuildTime(), 1);
|
|
|
|
|
1998-04-08 07:58:01 +08:00
|
|
|
genSourceRpmName(spec);
|
1998-01-13 05:31:29 +08:00
|
|
|
sprintf(fileName, "%s/%s", rpmGetVar(RPMVAR_SRPMDIR), spec->sourceRpmName);
|
|
|
|
|
|
|
|
/* Add the build restrictions */
|
|
|
|
iter = headerInitIterator(spec->buildRestrictions);
|
|
|
|
while (headerNextIterator(iter, &tag, NULL, (void **)&ptr, &count)) {
|
|
|
|
headerAddEntry(spec->sourceHeader, tag,
|
|
|
|
RPM_STRING_ARRAY_TYPE, ptr, count);
|
|
|
|
FREE(ptr);
|
|
|
|
}
|
|
|
|
headerFreeIterator(iter);
|
|
|
|
if (spec->buildArchitectureCount) {
|
|
|
|
headerAddEntry(spec->sourceHeader, RPMTAG_BUILDARCHS,
|
|
|
|
RPM_STRING_ARRAY_TYPE,
|
|
|
|
spec->buildArchitectures, spec->buildArchitectureCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
FREE(spec->cookie);
|
|
|
|
|
|
|
|
return writeRPM(spec->sourceHeader, fileName, RPMLEAD_SOURCE,
|
|
|
|
spec->sourceCpioList, spec->sourceCpioCount,
|
|
|
|
spec->passPhrase, &(spec->cookie));
|
|
|
|
}
|
|
|
|
|
|
|
|
int packageBinaries(Spec spec)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
char *binFormat, *binRpm, *errorString;
|
|
|
|
char *name, fileName[BUFSIZ];
|
|
|
|
Package pkg;
|
|
|
|
|
|
|
|
pkg = spec->packages;
|
|
|
|
while (pkg) {
|
|
|
|
if (!pkg->fileList) {
|
|
|
|
pkg = pkg->next;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((rc = processScriptFiles(spec, pkg))) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (spec->cookie) {
|
|
|
|
headerAddEntry(pkg->header, RPMTAG_COOKIE,
|
|
|
|
RPM_STRING_TYPE, spec->cookie, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
headerAddEntry(pkg->header, RPMTAG_RPMVERSION,
|
|
|
|
RPM_STRING_TYPE, VERSION, 1);
|
|
|
|
headerAddEntry(pkg->header, RPMTAG_BUILDHOST,
|
|
|
|
RPM_STRING_TYPE, buildHost(), 1);
|
|
|
|
headerAddEntry(pkg->header, RPMTAG_BUILDTIME,
|
|
|
|
RPM_INT32_TYPE, getBuildTime(), 1);
|
1998-04-08 07:58:01 +08:00
|
|
|
|
|
|
|
genSourceRpmName(spec);
|
1998-01-13 05:31:29 +08:00
|
|
|
headerAddEntry(pkg->header, RPMTAG_SOURCERPM, RPM_STRING_TYPE,
|
1998-04-08 07:58:01 +08:00
|
|
|
spec->sourceRpmName, 1);
|
1998-01-13 05:31:29 +08:00
|
|
|
|
|
|
|
binFormat = rpmGetVar(RPMVAR_RPMFILENAME);
|
|
|
|
binRpm = headerSprintf(pkg->header, binFormat, rpmTagTable,
|
|
|
|
rpmHeaderFormats, &errorString);
|
|
|
|
if (!binRpm) {
|
|
|
|
headerGetEntry(pkg->header, RPMTAG_NAME, NULL,
|
|
|
|
(void **)&name, NULL);
|
|
|
|
rpmError(RPMERR_BADFILENAME, "Could not generate output "
|
|
|
|
"filename for package %s: %s\n", name, errorString);
|
|
|
|
return RPMERR_BADFILENAME;
|
|
|
|
}
|
|
|
|
sprintf(fileName, "%s/%s", rpmGetVar(RPMVAR_RPMDIR), binRpm);
|
|
|
|
FREE(binRpm);
|
|
|
|
|
|
|
|
if ((rc = writeRPM(pkg->header, fileName, RPMLEAD_BINARY,
|
|
|
|
pkg->cpioList, pkg->cpioCount,
|
|
|
|
spec->passPhrase, NULL))) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
pkg = pkg->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int writeRPM(Header header, char *fileName, int type,
|
|
|
|
struct cpioFileMapping *cpioList, int cpioCount,
|
|
|
|
char *passPhrase, char **cookie)
|
1996-02-19 10:24:47 +08:00
|
|
|
{
|
1998-01-13 05:31:29 +08:00
|
|
|
int archiveSize, fd, ifd, rc, count, arch, os, sigtype;
|
|
|
|
char *sigtarget, *name, *version, *release;
|
|
|
|
char buf[BUFSIZ];
|
1996-07-08 06:11:13 +08:00
|
|
|
Header sig;
|
1998-01-13 05:31:29 +08:00
|
|
|
struct rpmlead lead;
|
1996-02-19 10:24:47 +08:00
|
|
|
|
1996-12-07 00:52:11 +08:00
|
|
|
/* Add the a bogus archive size to the Header */
|
|
|
|
headerAddEntry(header, RPMTAG_ARCHIVESIZE, RPM_INT32_TYPE,
|
|
|
|
&archiveSize, 1);
|
1996-02-20 07:00:16 +08:00
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
/* Create and add the cookie */
|
|
|
|
if (cookie) {
|
|
|
|
sprintf(buf, "%s %d", buildHost(), (int) time(NULL));
|
|
|
|
*cookie = strdup(buf);
|
|
|
|
headerAddEntry(header, RPMTAG_COOKIE, RPM_STRING_TYPE, *cookie, 1);
|
|
|
|
}
|
|
|
|
|
1996-12-07 00:52:11 +08:00
|
|
|
/* Write the header */
|
1998-01-13 05:31:29 +08:00
|
|
|
if (makeTempFile(NULL, &sigtarget, &fd)) {
|
|
|
|
rpmError(RPMERR_CREATE, "Unable to open temp file");
|
|
|
|
return RPMERR_CREATE;
|
|
|
|
}
|
1996-11-19 02:02:36 +08:00
|
|
|
headerWrite(fd, header, HEADER_MAGIC_YES);
|
1998-01-13 05:31:29 +08:00
|
|
|
|
1996-12-07 00:52:11 +08:00
|
|
|
/* Write the archive and get the size */
|
1998-01-13 05:31:29 +08:00
|
|
|
if ((rc = cpio_gzip(fd, cpioList, cpioCount, &archiveSize))) {
|
1996-12-07 00:52:11 +08:00
|
|
|
close(fd);
|
|
|
|
unlink(sigtarget);
|
1997-08-29 03:13:54 +08:00
|
|
|
free(sigtarget);
|
1998-01-13 05:31:29 +08:00
|
|
|
return rc;
|
1996-02-19 10:24:47 +08:00
|
|
|
}
|
|
|
|
|
1996-12-07 00:52:11 +08:00
|
|
|
/* Now set the real archive size in the Header */
|
|
|
|
headerModifyEntry(header, RPMTAG_ARCHIVESIZE,
|
|
|
|
RPM_INT32_TYPE, &archiveSize, 1);
|
|
|
|
lseek(fd, 0, SEEK_SET);
|
|
|
|
headerWrite(fd, header, HEADER_MAGIC_YES);
|
1998-01-13 05:31:29 +08:00
|
|
|
|
1996-12-07 00:52:11 +08:00
|
|
|
close(fd);
|
1998-01-13 05:31:29 +08:00
|
|
|
|
|
|
|
/* Open the output file */
|
|
|
|
if ((fd = open(fileName, O_WRONLY|O_CREAT|O_TRUNC, 0644)) == -1) {
|
|
|
|
rpmError(RPMERR_CREATE, "Could not open %s\n", fileName);
|
1996-03-30 04:06:02 +08:00
|
|
|
unlink(sigtarget);
|
1997-08-29 03:13:54 +08:00
|
|
|
free(sigtarget);
|
1998-01-13 05:31:29 +08:00
|
|
|
return RPMERR_CREATE;
|
1996-03-30 04:06:02 +08:00
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
|
|
|
|
/* Now write the lead */
|
|
|
|
headerGetEntry(header, RPMTAG_NAME, NULL, (void **)&name, NULL);
|
|
|
|
headerGetEntry(header, RPMTAG_VERSION, NULL, (void **)&version, NULL);
|
|
|
|
headerGetEntry(header, RPMTAG_RELEASE, NULL, (void **)&release, NULL);
|
|
|
|
sprintf(buf, "%s-%s-%s", name, version, release);
|
|
|
|
rpmGetArchInfo(NULL, &arch);
|
|
|
|
rpmGetOsInfo(NULL, &os);
|
1998-04-10 04:20:17 +08:00
|
|
|
memset(&lead, 0, sizeof(lead));
|
1998-01-13 05:31:29 +08:00
|
|
|
lead.major = RPM_MAJOR_NUMBER;
|
|
|
|
lead.minor = 0;
|
|
|
|
lead.type = type;
|
|
|
|
lead.archnum = arch;
|
|
|
|
lead.osnum = os;
|
|
|
|
lead.signature_type = RPMSIG_HEADERSIG; /* New-style signature */
|
|
|
|
strncpy(lead.name, buf, sizeof(lead.name));
|
|
|
|
if (writeLead(fd, &lead)) {
|
|
|
|
rpmError(RPMERR_NOSPACE, "Unable to write package: %s",
|
|
|
|
strerror(errno));
|
1996-02-22 09:35:34 +08:00
|
|
|
close(fd);
|
|
|
|
unlink(sigtarget);
|
1997-08-29 03:13:54 +08:00
|
|
|
free(sigtarget);
|
1998-01-13 05:31:29 +08:00
|
|
|
unlink(fileName);
|
|
|
|
return rc;
|
1996-02-19 10:24:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Generate the signature */
|
1996-11-19 02:02:36 +08:00
|
|
|
sigtype = rpmLookupSignatureType();
|
1996-02-19 10:24:47 +08:00
|
|
|
fflush(stdout);
|
1996-11-19 02:02:36 +08:00
|
|
|
sig = rpmNewSignature();
|
|
|
|
rpmAddSignature(sig, sigtarget, RPMSIGTAG_SIZE, passPhrase);
|
|
|
|
rpmAddSignature(sig, sigtarget, RPMSIGTAG_MD5, passPhrase);
|
1998-01-13 05:31:29 +08:00
|
|
|
if (sigtype > 0) {
|
|
|
|
rpmMessage(RPMMESS_NORMAL, "Generating signature: %d\n", sigtype);
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmAddSignature(sig, sigtarget, sigtype, passPhrase);
|
1996-07-08 06:11:13 +08:00
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
if ((rc = rpmWriteSignature(fd, sig))) {
|
1996-02-22 09:35:34 +08:00
|
|
|
close(fd);
|
|
|
|
unlink(sigtarget);
|
1997-08-29 03:13:54 +08:00
|
|
|
free(sigtarget);
|
1998-01-13 05:31:29 +08:00
|
|
|
unlink(fileName);
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmFreeSignature(sig);
|
1998-01-13 05:31:29 +08:00
|
|
|
return rc;
|
1996-02-22 09:35:34 +08:00
|
|
|
}
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmFreeSignature(sig);
|
1998-01-13 05:31:29 +08:00
|
|
|
|
1996-02-19 10:24:47 +08:00
|
|
|
/* Append the header and archive */
|
|
|
|
ifd = open(sigtarget, O_RDONLY);
|
1998-01-13 05:31:29 +08:00
|
|
|
while ((count = read(ifd, buf, sizeof(buf))) > 0) {
|
|
|
|
if (count == -1) {
|
|
|
|
rpmError(RPMERR_READERROR, "Unable to read sigtarget: %s",
|
|
|
|
strerror(errno));
|
1996-02-22 23:46:54 +08:00
|
|
|
close(ifd);
|
|
|
|
close(fd);
|
|
|
|
unlink(sigtarget);
|
1997-08-29 03:13:54 +08:00
|
|
|
free(sigtarget);
|
1998-01-13 05:31:29 +08:00
|
|
|
unlink(fileName);
|
|
|
|
return RPMERR_READERROR;
|
|
|
|
}
|
|
|
|
if (write(fd, buf, count) < 0) {
|
|
|
|
rpmError(RPMERR_NOSPACE, "Unable to write package: %s",
|
|
|
|
strerror(errno));
|
1996-02-22 23:46:54 +08:00
|
|
|
close(ifd);
|
|
|
|
close(fd);
|
|
|
|
unlink(sigtarget);
|
1997-08-29 03:13:54 +08:00
|
|
|
free(sigtarget);
|
1998-01-13 05:31:29 +08:00
|
|
|
unlink(fileName);
|
|
|
|
return RPMERR_NOSPACE;
|
|
|
|
}
|
1996-02-19 10:24:47 +08:00
|
|
|
}
|
|
|
|
close(ifd);
|
|
|
|
close(fd);
|
|
|
|
unlink(sigtarget);
|
1997-08-29 03:13:54 +08:00
|
|
|
free(sigtarget);
|
1996-06-28 01:21:31 +08:00
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
rpmMessage(RPMMESS_NORMAL, "Wrote: %s\n", fileName);
|
1995-12-21 06:49:40 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
static int cpio_gzip(int fd, struct cpioFileMapping *cpioList,
|
|
|
|
int cpioCount, int *archiveSize)
|
1995-12-21 06:49:40 +08:00
|
|
|
{
|
1998-01-13 05:31:29 +08:00
|
|
|
char *gzipbin;
|
1996-02-29 08:55:31 +08:00
|
|
|
void *oldhandler;
|
1998-01-13 05:31:29 +08:00
|
|
|
int rc, gzipPID, toGzip[2], status;
|
|
|
|
char *failedFile;
|
1996-02-29 08:55:31 +08:00
|
|
|
|
1997-05-08 04:22:55 +08:00
|
|
|
gzipbin = rpmGetVar(RPMVAR_GZIPBIN);
|
1997-07-24 02:08:01 +08:00
|
|
|
oldhandler = signal(SIGPIPE, SIG_IGN);
|
1995-12-21 06:49:40 +08:00
|
|
|
|
1996-02-29 08:55:31 +08:00
|
|
|
/* GZIP */
|
1998-01-13 05:31:29 +08:00
|
|
|
pipe(toGzip);
|
1996-02-29 08:55:31 +08:00
|
|
|
if (!(gzipPID = fork())) {
|
|
|
|
close(toGzip[1]);
|
|
|
|
|
|
|
|
dup2(toGzip[0], 0); /* Make stdin the in pipe */
|
|
|
|
dup2(fd, 1); /* Make stdout the passed-in fd */
|
1995-12-21 06:49:40 +08:00
|
|
|
|
1997-05-02 03:08:15 +08:00
|
|
|
execlp(gzipbin, gzipbin, "-c9fn", NULL);
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmError(RPMERR_EXEC, "Couldn't exec gzip");
|
1996-12-12 11:35:01 +08:00
|
|
|
_exit(RPMERR_EXEC);
|
1996-02-29 08:55:31 +08:00
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
close(toGzip[0]);
|
1996-02-29 08:55:31 +08:00
|
|
|
if (gzipPID < 0) {
|
1998-01-13 05:31:29 +08:00
|
|
|
close(toGzip[1]);
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmError(RPMERR_FORK, "Couldn't fork gzip");
|
1996-02-29 08:55:31 +08:00
|
|
|
return RPMERR_FORK;
|
|
|
|
}
|
|
|
|
|
1998-01-15 23:36:52 +08:00
|
|
|
rc = cpioBuildArchive(toGzip[1], cpioList, cpioCount, NULL, NULL,
|
1997-08-25 22:38:48 +08:00
|
|
|
archiveSize, &failedFile);
|
1997-07-31 06:19:39 +08:00
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
close(toGzip[1]);
|
1996-02-20 07:00:16 +08:00
|
|
|
signal(SIGPIPE, oldhandler);
|
1996-02-29 08:55:31 +08:00
|
|
|
waitpid(gzipPID, &status, 0);
|
|
|
|
if (!WIFEXITED(status) || WEXITSTATUS(status)) {
|
1998-01-13 05:31:29 +08:00
|
|
|
rpmError(RPMERR_GZIP, "Execution of gzip failed");
|
1996-02-29 08:55:31 +08:00
|
|
|
return 1;
|
|
|
|
}
|
1995-12-21 06:49:40 +08:00
|
|
|
|
1997-07-24 02:08:01 +08:00
|
|
|
if (rc) {
|
1997-08-01 00:02:19 +08:00
|
|
|
if (rc & CPIO_CHECK_ERRNO)
|
1998-01-13 05:31:29 +08:00
|
|
|
rpmError(RPMERR_CPIO, "cpio failed on file %s: %s",
|
|
|
|
failedFile, strerror(errno));
|
1997-08-01 00:02:19 +08:00
|
|
|
else
|
1998-01-13 05:31:29 +08:00
|
|
|
rpmError(RPMERR_CPIO, "cpio failed on file %s: %d",
|
|
|
|
failedFile, rc);
|
1997-07-24 02:08:01 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1995-12-21 06:49:40 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1998-03-21 06:38:00 +08:00
|
|
|
static StringBuf addFileToTagAux(Spec spec, char *file, StringBuf sb)
|
1995-12-21 06:49:40 +08:00
|
|
|
{
|
1998-01-13 05:31:29 +08:00
|
|
|
char *s;
|
|
|
|
char buf[BUFSIZ];
|
|
|
|
FILE *f;
|
|
|
|
|
|
|
|
sprintf(buf, "%s/%s/%s", rpmGetVar(RPMVAR_BUILDDIR),
|
|
|
|
spec->buildSubdir, file);
|
|
|
|
if ((f = fopen(buf, "r")) == NULL) {
|
|
|
|
freeStringBuf(sb);
|
1998-03-21 06:38:00 +08:00
|
|
|
return NULL;
|
1996-02-19 10:24:47 +08:00
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
while (fgets(buf, sizeof(buf), f)) {
|
1998-05-21 01:05:26 +08:00
|
|
|
if (expandMacros(&spec->macros, buf)) {
|
|
|
|
rpmError(RPMERR_BADSPEC, "line: %s", buf);
|
|
|
|
return NULL;
|
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
appendStringBuf(sb, buf);
|
1995-12-21 06:49:40 +08:00
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
fclose(f);
|
1998-03-21 06:38:00 +08:00
|
|
|
|
|
|
|
return sb;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int addFileToTag(Spec spec, char *file, Header h, int tag)
|
|
|
|
{
|
|
|
|
StringBuf sb;
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
sb = newStringBuf();
|
|
|
|
if (headerGetEntry(h, tag, NULL, (void **)&s, NULL)) {
|
|
|
|
appendLineStringBuf(sb, s);
|
|
|
|
headerRemoveEntry(h, tag);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! (sb = addFileToTagAux(spec, file, sb))) {
|
|
|
|
return 1;
|
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
|
|
|
|
headerAddEntry(h, tag, RPM_STRING_TYPE, getStringBuf(sb), 1);
|
1996-07-19 00:09:25 +08:00
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
freeStringBuf(sb);
|
1995-12-21 06:49:40 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1998-03-21 06:38:00 +08:00
|
|
|
static int addFileToArrayTag(Spec spec, char *file, Header h, int tag)
|
|
|
|
{
|
|
|
|
StringBuf sb;
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
sb = newStringBuf();
|
|
|
|
if (! (sb = addFileToTagAux(spec, file, sb))) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
s = getStringBuf(sb);
|
|
|
|
headerAddOrAppendEntry(h, tag, RPM_STRING_ARRAY_TYPE, &s, 1);
|
|
|
|
|
|
|
|
freeStringBuf(sb);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
static int processScriptFiles(Spec spec, Package pkg)
|
1995-12-21 06:49:40 +08:00
|
|
|
{
|
1998-03-21 06:38:00 +08:00
|
|
|
struct TriggerFileEntry *p;
|
|
|
|
char *bull = "";
|
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
if (pkg->preInFile) {
|
|
|
|
if (addFileToTag(spec, pkg->preInFile, pkg->header, RPMTAG_PREIN)) {
|
|
|
|
rpmError(RPMERR_BADFILENAME,
|
|
|
|
"Could not open PreIn file: %s", pkg->preInFile);
|
|
|
|
return RPMERR_BADFILENAME;
|
1996-01-18 02:17:50 +08:00
|
|
|
}
|
1996-01-08 15:07:35 +08:00
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
if (pkg->preUnFile) {
|
|
|
|
if (addFileToTag(spec, pkg->preUnFile, pkg->header, RPMTAG_PREUN)) {
|
|
|
|
rpmError(RPMERR_BADFILENAME,
|
|
|
|
"Could not open PreUn file: %s", pkg->preUnFile);
|
|
|
|
return RPMERR_BADFILENAME;
|
1996-01-08 15:07:35 +08:00
|
|
|
}
|
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
if (pkg->postInFile) {
|
|
|
|
if (addFileToTag(spec, pkg->postInFile, pkg->header, RPMTAG_POSTIN)) {
|
|
|
|
rpmError(RPMERR_BADFILENAME,
|
|
|
|
"Could not open PostIn file: %s", pkg->postInFile);
|
|
|
|
return RPMERR_BADFILENAME;
|
1996-02-19 10:24:47 +08:00
|
|
|
}
|
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
if (pkg->postUnFile) {
|
|
|
|
if (addFileToTag(spec, pkg->postUnFile, pkg->header, RPMTAG_POSTUN)) {
|
|
|
|
rpmError(RPMERR_BADFILENAME,
|
|
|
|
"Could not open PostUn file: %s", pkg->postUnFile);
|
|
|
|
return RPMERR_BADFILENAME;
|
1996-02-19 10:24:47 +08:00
|
|
|
}
|
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
if (pkg->verifyFile) {
|
|
|
|
if (addFileToTag(spec, pkg->verifyFile, pkg->header,
|
|
|
|
RPMTAG_VERIFYSCRIPT)) {
|
|
|
|
rpmError(RPMERR_BADFILENAME,
|
|
|
|
"Could not open VerifyScript file: %s", pkg->verifyFile);
|
|
|
|
return RPMERR_BADFILENAME;
|
1996-01-08 15:07:35 +08:00
|
|
|
}
|
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
|
1998-03-21 06:38:00 +08:00
|
|
|
p = pkg->triggerFiles;
|
|
|
|
while (p) {
|
|
|
|
headerAddOrAppendEntry(pkg->header, RPMTAG_TRIGGERSCRIPTPROG,
|
|
|
|
RPM_STRING_ARRAY_TYPE, &(p->prog), 1);
|
|
|
|
if (p->script) {
|
|
|
|
headerAddOrAppendEntry(pkg->header, RPMTAG_TRIGGERSCRIPTS,
|
|
|
|
RPM_STRING_ARRAY_TYPE, &(p->script), 1);
|
|
|
|
} else if (p->fileName) {
|
|
|
|
if (addFileToArrayTag(spec, p->fileName, pkg->header,
|
|
|
|
RPMTAG_TRIGGERSCRIPTS)) {
|
|
|
|
rpmError(RPMERR_BADFILENAME,
|
|
|
|
"Could not open Trigger script file: %s",
|
|
|
|
p->fileName);
|
|
|
|
return RPMERR_BADFILENAME;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* This is dumb. When the header supports NULL string */
|
|
|
|
/* this will go away. */
|
|
|
|
headerAddOrAppendEntry(pkg->header, RPMTAG_TRIGGERSCRIPTS,
|
|
|
|
RPM_STRING_ARRAY_TYPE, &bull, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
|
1995-12-21 06:49:40 +08:00
|
|
|
return 0;
|
|
|
|
}
|