2000-01-25 04:02:32 +08:00
|
|
|
/** \file build/pack.c
|
|
|
|
* Assemble components of an RPM package.
|
|
|
|
*/
|
|
|
|
|
1998-07-26 05:00:26 +08:00
|
|
|
#include "system.h"
|
|
|
|
|
2000-06-10 02:57:23 +08:00
|
|
|
#include <rpmbuild.h>
|
|
|
|
#include <rpmio_internal.h>
|
1998-08-09 06:27:08 +08:00
|
|
|
#include "buildio.h"
|
1998-01-13 05:31:29 +08:00
|
|
|
|
2000-06-10 02:57:23 +08:00
|
|
|
#include "misc.h"
|
|
|
|
#include "signature.h"
|
|
|
|
#include "rpmlead.h"
|
1998-01-13 05:31:29 +08:00
|
|
|
|
2000-05-31 03:30:28 +08:00
|
|
|
#define RPM_MAJOR_NUMBER 4
|
1998-01-13 05:31:29 +08:00
|
|
|
|
1999-11-27 05:58:42 +08:00
|
|
|
extern int _noDirTokens;
|
|
|
|
|
1999-08-07 06:52:49 +08:00
|
|
|
static inline int genSourceRpmName(Spec spec)
|
1998-01-13 05:31:29 +08:00
|
|
|
{
|
1999-08-07 06:52:49 +08:00
|
|
|
if (spec->sourceRpmName == NULL) {
|
|
|
|
const char *name, *version, *release;
|
|
|
|
char fileName[BUFSIZ];
|
1998-04-08 07:58:01 +08:00
|
|
|
|
1999-08-07 06:52:49 +08:00
|
|
|
headerNVR(spec->packages->header, &name, &version, &release);
|
|
|
|
sprintf(fileName, "%s-%s-%s.%ssrc.rpm", name, version, release,
|
1998-04-08 07:58:01 +08:00
|
|
|
spec->noSource ? "no" : "");
|
1999-09-21 11:22:53 +08:00
|
|
|
spec->sourceRpmName = xstrdup(fileName);
|
1999-08-07 06:52:49 +08:00
|
|
|
}
|
1998-04-08 07:58:01 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-01-25 04:02:32 +08:00
|
|
|
static int cpio_doio(FD_t fdo, CSA_t * csa, const char * fmodeMacro)
|
1998-04-08 07:58:01 +08:00
|
|
|
{
|
2000-01-25 04:02:32 +08:00
|
|
|
FD_t cfd;
|
1999-01-06 07:13:56 +08:00
|
|
|
int rc;
|
2000-01-25 04:02:32 +08:00
|
|
|
const char *failedFile = NULL;
|
|
|
|
const char *fmode = rpmExpand(fmodeMacro, NULL);
|
1998-01-13 05:31:29 +08:00
|
|
|
|
2000-01-25 04:02:32 +08:00
|
|
|
if (!(fmode && fmode[0] == 'w'))
|
|
|
|
fmode = xstrdup("w9.gzdio");
|
|
|
|
(void) Fflush(fdo);
|
|
|
|
cfd = Fdopen(fdDup(Fileno(fdo)), fmode);
|
|
|
|
rc = cpioBuildArchive(cfd, csa->cpioList, csa->cpioCount, NULL, NULL,
|
|
|
|
&csa->cpioArchiveSize, &failedFile);
|
|
|
|
if (rc) {
|
|
|
|
rpmError(RPMERR_CPIO, _("create archive failed on file %s: %s"),
|
|
|
|
failedFile, cpioStrerror(rc));
|
|
|
|
rc = 1;
|
1998-11-20 02:10:28 +08:00
|
|
|
}
|
|
|
|
|
2000-01-25 04:02:32 +08:00
|
|
|
Fclose(cfd);
|
|
|
|
if (failedFile)
|
|
|
|
xfree(failedFile);
|
|
|
|
xfree(fmode);
|
1999-01-06 07:13:56 +08:00
|
|
|
|
|
|
|
return rc;
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
|
|
|
|
2000-01-25 04:02:32 +08:00
|
|
|
static int cpio_copy(FD_t fdo, CSA_t *csa)
|
1998-01-13 05:31:29 +08:00
|
|
|
{
|
2000-01-25 04:02:32 +08:00
|
|
|
char buf[BUFSIZ];
|
|
|
|
size_t nb;
|
1998-01-13 05:31:29 +08:00
|
|
|
|
2000-01-25 04:02:32 +08:00
|
|
|
while((nb = Fread(buf, sizeof(buf[0]), sizeof(buf), csa->cpioFdIn)) > 0) {
|
|
|
|
if (Fwrite(buf, sizeof(buf[0]), nb, fdo) != nb) {
|
|
|
|
rpmError(RPMERR_CPIO, _("cpio_copy write failed: %s"),
|
|
|
|
Fstrerror(fdo));
|
|
|
|
return 1;
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
2000-01-25 04:02:32 +08:00
|
|
|
csa->cpioArchiveSize += nb;
|
1998-11-20 02:10:28 +08:00
|
|
|
}
|
2000-01-25 04:02:32 +08:00
|
|
|
if (Ferror(csa->cpioFdIn)) {
|
|
|
|
rpmError(RPMERR_CPIO, _("cpio_copy read failed: %s"),
|
|
|
|
Fstrerror(csa->cpioFdIn));
|
|
|
|
return 1;
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-01-25 04:02:32 +08:00
|
|
|
static StringBuf addFileToTagAux(Spec spec, const char *file, StringBuf sb)
|
1998-10-12 04:58:58 +08:00
|
|
|
{
|
2000-01-25 04:02:32 +08:00
|
|
|
char buf[BUFSIZ];
|
|
|
|
const char *fn = buf;
|
|
|
|
FD_t fd;
|
1998-10-12 04:58:58 +08:00
|
|
|
|
2000-01-25 04:02:32 +08:00
|
|
|
/* XXX use rpmGenPath(rootdir, "%{_buildir}/%{_buildsubdir}/", file) */
|
|
|
|
fn = rpmGetPath("%{_builddir}/", spec->buildSubdir, "/", file, NULL);
|
1998-10-12 04:58:58 +08:00
|
|
|
|
2000-01-25 04:02:32 +08:00
|
|
|
fd = Fopen(fn, "r.ufdio");
|
|
|
|
if (fn != buf) xfree(fn);
|
|
|
|
if (fd == NULL || Ferror(fd)) {
|
|
|
|
freeStringBuf(sb);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
while (fgets(buf, sizeof(buf), (FILE *)fdGetFp(fd))) {
|
|
|
|
/* XXX display fn in error msg */
|
|
|
|
if (expandMacros(spec, spec->macros, buf, sizeof(buf))) {
|
|
|
|
rpmError(RPMERR_BADSPEC, _("line: %s"), buf);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
appendStringBuf(sb, buf);
|
1998-10-12 04:58:58 +08:00
|
|
|
}
|
2000-01-25 04:02:32 +08:00
|
|
|
Fclose(fd);
|
1999-10-28 07:18:10 +08:00
|
|
|
|
2000-01-25 04:02:32 +08:00
|
|
|
return sb;
|
|
|
|
}
|
1998-10-12 04:58:58 +08:00
|
|
|
|
2000-01-25 04:02:32 +08:00
|
|
|
static int addFileToTag(Spec spec, char *file, Header h, int tag)
|
|
|
|
{
|
|
|
|
StringBuf sb;
|
|
|
|
char *s;
|
1998-10-12 04:58:58 +08:00
|
|
|
|
2000-01-25 04:02:32 +08:00
|
|
|
sb = newStringBuf();
|
|
|
|
if (headerGetEntry(h, tag, NULL, (void **)&s, NULL)) {
|
|
|
|
appendLineStringBuf(sb, s);
|
|
|
|
headerRemoveEntry(h, tag);
|
1998-10-12 04:58:58 +08:00
|
|
|
}
|
|
|
|
|
2000-01-25 04:02:32 +08:00
|
|
|
if ((sb = addFileToTagAux(spec, file, sb)) == NULL) {
|
|
|
|
return 1;
|
1998-10-12 04:58:58 +08:00
|
|
|
}
|
2000-01-25 04:02:32 +08:00
|
|
|
|
|
|
|
headerAddEntry(h, tag, RPM_STRING_TYPE, getStringBuf(sb), 1);
|
1998-10-12 04:58:58 +08:00
|
|
|
|
2000-01-25 04:02:32 +08:00
|
|
|
freeStringBuf(sb);
|
|
|
|
return 0;
|
|
|
|
}
|
1998-10-12 04:58:58 +08:00
|
|
|
|
2000-01-25 04:02:32 +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)) == NULL) {
|
|
|
|
return 1;
|
1998-10-12 04:58:58 +08:00
|
|
|
}
|
|
|
|
|
2000-01-25 04:02:32 +08:00
|
|
|
s = getStringBuf(sb);
|
|
|
|
headerAddOrAppendEntry(h, tag, RPM_STRING_ARRAY_TYPE, &s, 1);
|
|
|
|
|
|
|
|
freeStringBuf(sb);
|
1998-10-12 04:58:58 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-01-25 04:02:32 +08:00
|
|
|
static int processScriptFiles(Spec spec, Package pkg)
|
1996-02-19 10:24:47 +08:00
|
|
|
{
|
2000-01-25 04:02:32 +08:00
|
|
|
struct TriggerFileEntry *p;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (p = pkg->triggerFiles; p != NULL; p = p->next) {
|
|
|
|
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. */
|
|
|
|
char *bull = "";
|
|
|
|
headerAddOrAppendEntry(pkg->header, RPMTAG_TRIGGERSCRIPTS,
|
|
|
|
RPM_STRING_ARRAY_TYPE, &bull, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** */
|
|
|
|
int readRPM(const char *fileName, Spec *specp, struct rpmlead *lead, Header *sigs,
|
|
|
|
CSA_t *csa)
|
|
|
|
{
|
|
|
|
FD_t fdi;
|
|
|
|
Spec spec;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (fileName != NULL) {
|
|
|
|
fdi = Fopen(fileName, "r.ufdio");
|
|
|
|
if (fdi == NULL || Ferror(fdi)) {
|
|
|
|
rpmError(RPMERR_BADMAGIC, _("readRPM: open %s: %s\n"), fileName,
|
|
|
|
Fstrerror(fdi));
|
|
|
|
return RPMERR_BADMAGIC;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fdi = fdDup(STDIN_FILENO);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get copy of lead */
|
|
|
|
if ((rc = Fread(lead, sizeof(char), sizeof(*lead), fdi)) != sizeof(*lead)) {
|
|
|
|
rpmError(RPMERR_BADMAGIC, _("readRPM: read %s: %s\n"), fileName,
|
|
|
|
Fstrerror(fdi));
|
|
|
|
return RPMERR_BADMAGIC;
|
|
|
|
}
|
|
|
|
|
|
|
|
(void)Fseek(fdi, 0, SEEK_SET); /* XXX FIXME: EPIPE */
|
|
|
|
|
|
|
|
/* Reallocate build data structures */
|
|
|
|
spec = newSpec();
|
|
|
|
spec->packages = newPackage(spec);
|
|
|
|
|
|
|
|
/* XXX the header just allocated will be allocated again */
|
|
|
|
if (spec->packages->header != NULL) {
|
|
|
|
headerFree(spec->packages->header);
|
|
|
|
spec->packages->header = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read the rpm lead and header */
|
|
|
|
rc = rpmReadPackageInfo(fdi, sigs, &spec->packages->header);
|
|
|
|
switch (rc) {
|
|
|
|
case 1:
|
|
|
|
rpmError(RPMERR_BADMAGIC, _("readRPM: %s is not an RPM package\n"),
|
|
|
|
fileName);
|
|
|
|
return RPMERR_BADMAGIC;
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
rpmError(RPMERR_BADMAGIC, _("readRPM: reading header from %s\n"), fileName);
|
|
|
|
return RPMERR_BADMAGIC;
|
|
|
|
/*@notreached@*/ break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (specp)
|
|
|
|
*specp = spec;
|
|
|
|
|
|
|
|
if (csa) {
|
|
|
|
csa->cpioFdIn = fdi;
|
|
|
|
} else {
|
|
|
|
Fclose(fdi);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** */
|
|
|
|
int writeRPM(Header h, const char *fileName, int type,
|
|
|
|
CSA_t *csa, char *passPhrase, char **cookie)
|
|
|
|
{
|
|
|
|
FD_t fd, ifd;
|
1998-11-19 05:41:05 +08:00
|
|
|
int rc, count, sigtype;
|
1998-10-08 01:06:10 +08:00
|
|
|
int archnum, osnum;
|
1999-01-07 01:33:50 +08:00
|
|
|
const char *sigtarget;
|
1998-01-13 05:31:29 +08:00
|
|
|
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
|
|
|
|
1999-10-31 00:43:29 +08:00
|
|
|
if (Fileno(csa->cpioFdIn) < 0) {
|
1998-08-10 01:01:57 +08:00
|
|
|
csa->cpioArchiveSize = 0;
|
1998-08-12 02:24:48 +08:00
|
|
|
/* Add a bogus archive size to the Header */
|
1999-08-07 06:52:49 +08:00
|
|
|
headerAddEntry(h, RPMTAG_ARCHIVESIZE, RPM_INT32_TYPE,
|
1998-08-10 01:01:57 +08:00
|
|
|
&csa->cpioArchiveSize, 1);
|
|
|
|
}
|
1996-02-20 07:00:16 +08:00
|
|
|
|
2000-01-25 04:44:29 +08:00
|
|
|
if (_noDirTokens)
|
|
|
|
expandFilelist(h);
|
|
|
|
else
|
|
|
|
compressFilelist(h);
|
1999-10-06 23:51:38 +08:00
|
|
|
|
2000-05-31 21:19:37 +08:00
|
|
|
providePackageNVR(h);
|
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
/* Create and add the cookie */
|
|
|
|
if (cookie) {
|
|
|
|
sprintf(buf, "%s %d", buildHost(), (int) time(NULL));
|
1999-09-21 11:22:53 +08:00
|
|
|
*cookie = xstrdup(buf);
|
1999-08-07 06:52:49 +08:00
|
|
|
headerAddEntry(h, RPMTAG_COOKIE, RPM_STRING_TYPE, *cookie, 1);
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
|
|
|
|
1996-12-07 00:52:11 +08:00
|
|
|
/* Write the header */
|
1998-01-13 05:31:29 +08:00
|
|
|
if (makeTempFile(NULL, &sigtarget, &fd)) {
|
2000-02-29 09:57:37 +08:00
|
|
|
rpmError(RPMERR_CREATE, _("Unable to open temp file."));
|
1998-01-13 05:31:29 +08:00
|
|
|
return RPMERR_CREATE;
|
|
|
|
}
|
1999-11-15 03:15:18 +08:00
|
|
|
|
1999-08-24 23:18:43 +08:00
|
|
|
if (headerWrite(fd, h, HEADER_MAGIC_YES)) {
|
|
|
|
rc = RPMERR_NOSPACE;
|
|
|
|
} else { /* Write the archive and get the size */
|
|
|
|
if (csa->cpioList != NULL) {
|
2000-01-12 00:13:16 +08:00
|
|
|
rc = cpio_doio(fd, csa, "%{_payload_compression}");
|
1999-10-31 00:43:29 +08:00
|
|
|
} else if (Fileno(csa->cpioFdIn) >= 0) {
|
1999-08-24 23:18:43 +08:00
|
|
|
rc = cpio_copy(fd, csa);
|
|
|
|
} else {
|
|
|
|
rpmError(RPMERR_CREATE, _("Bad CSA data"));
|
|
|
|
rc = RPMERR_BADARG;
|
|
|
|
}
|
1998-08-09 06:27:08 +08:00
|
|
|
}
|
1999-11-15 03:15:18 +08:00
|
|
|
|
1998-08-09 06:27:08 +08:00
|
|
|
if (rc != 0) {
|
1999-10-28 07:18:10 +08:00
|
|
|
Fclose(fd);
|
1996-12-07 00:52:11 +08:00
|
|
|
unlink(sigtarget);
|
1999-01-07 01:33:50 +08:00
|
|
|
xfree(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 */
|
1999-10-31 00:43:29 +08:00
|
|
|
if (Fileno(csa->cpioFdIn) < 0) {
|
1999-08-07 06:52:49 +08:00
|
|
|
headerModifyEntry(h, RPMTAG_ARCHIVESIZE,
|
1998-08-10 01:01:57 +08:00
|
|
|
RPM_INT32_TYPE, &csa->cpioArchiveSize, 1);
|
|
|
|
}
|
1999-10-28 07:18:10 +08:00
|
|
|
|
|
|
|
(void)Fseek(fd, 0, SEEK_SET);
|
|
|
|
|
1999-08-24 23:18:43 +08:00
|
|
|
if (headerWrite(fd, h, HEADER_MAGIC_YES))
|
|
|
|
rc = RPMERR_NOSPACE;
|
1998-01-13 05:31:29 +08:00
|
|
|
|
1999-10-28 07:18:10 +08:00
|
|
|
Fclose(fd);
|
1999-08-24 23:18:43 +08:00
|
|
|
unlink(fileName);
|
|
|
|
|
|
|
|
if (rc) {
|
|
|
|
unlink(sigtarget);
|
|
|
|
xfree(sigtarget);
|
|
|
|
return rc;
|
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
|
|
|
|
/* Open the output file */
|
1999-11-13 01:20:49 +08:00
|
|
|
fd = Fopen(fileName, "w.ufdio");
|
|
|
|
if (fd == NULL || Ferror(fd)) {
|
|
|
|
rpmError(RPMERR_CREATE, _("Could not open %s: %s\n"),
|
|
|
|
fileName, Fstrerror(fd));
|
1996-03-30 04:06:02 +08:00
|
|
|
unlink(sigtarget);
|
1999-01-07 01:33:50 +08:00
|
|
|
xfree(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 */
|
1999-08-07 06:52:49 +08:00
|
|
|
{ const char *name, *version, *release;
|
|
|
|
headerNVR(h, &name, &version, &release);
|
|
|
|
sprintf(buf, "%s-%s-%s", name, version, release);
|
|
|
|
}
|
1998-08-10 01:01:57 +08:00
|
|
|
|
1999-12-20 03:55:14 +08:00
|
|
|
archnum = -1;
|
|
|
|
osnum = -1;
|
1999-10-31 00:43:29 +08:00
|
|
|
if (Fileno(csa->cpioFdIn) < 0) {
|
1998-10-08 01:06:10 +08:00
|
|
|
rpmGetArchInfo(NULL, &archnum);
|
|
|
|
rpmGetOsInfo(NULL, &osnum);
|
1998-08-10 01:01:57 +08:00
|
|
|
} else if (csa->lead != NULL) { /* XXX FIXME: exorcize lead/arch/os */
|
1998-10-08 01:06:10 +08:00
|
|
|
archnum = csa->lead->archnum;
|
|
|
|
osnum = csa->lead->osnum;
|
1998-08-10 01:01:57 +08:00
|
|
|
}
|
|
|
|
|
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;
|
1998-10-08 01:06:10 +08:00
|
|
|
lead.archnum = archnum;
|
|
|
|
lead.osnum = osnum;
|
1998-01-13 05:31:29 +08:00
|
|
|
lead.signature_type = RPMSIG_HEADERSIG; /* New-style signature */
|
|
|
|
strncpy(lead.name, buf, sizeof(lead.name));
|
|
|
|
if (writeLead(fd, &lead)) {
|
1998-09-28 06:03:52 +08:00
|
|
|
rpmError(RPMERR_NOSPACE, _("Unable to write package: %s"),
|
1999-11-11 06:09:49 +08:00
|
|
|
Fstrerror(fd));
|
1999-10-28 07:18:10 +08:00
|
|
|
Fclose(fd);
|
1996-02-22 09:35:34 +08:00
|
|
|
unlink(sigtarget);
|
1999-01-07 01:33:50 +08:00
|
|
|
xfree(sigtarget);
|
1998-01-13 05:31:29 +08:00
|
|
|
unlink(fileName);
|
|
|
|
return rc;
|
1996-02-19 10:24:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Generate the signature */
|
|
|
|
fflush(stdout);
|
1996-11-19 02:02:36 +08:00
|
|
|
sig = rpmNewSignature();
|
|
|
|
rpmAddSignature(sig, sigtarget, RPMSIGTAG_SIZE, passPhrase);
|
|
|
|
rpmAddSignature(sig, sigtarget, RPMSIGTAG_MD5, passPhrase);
|
1999-09-11 07:48:56 +08:00
|
|
|
if ((sigtype = rpmLookupSignatureType(RPMLOOKUPSIG_QUERY)) > 0) {
|
1998-09-28 06:03:52 +08:00
|
|
|
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))) {
|
1999-10-28 07:18:10 +08:00
|
|
|
Fclose(fd);
|
1996-02-22 09:35:34 +08:00
|
|
|
unlink(sigtarget);
|
1999-01-07 01:33:50 +08:00
|
|
|
xfree(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 */
|
1999-11-13 01:20:49 +08:00
|
|
|
ifd = Fopen(sigtarget, "r.ufdio");
|
|
|
|
if (ifd == NULL || Ferror(ifd)) {
|
|
|
|
rpmError(RPMERR_READERROR, _("Unable to open sigtarget %s: %s"),
|
|
|
|
sigtarget, Fstrerror(ifd));
|
|
|
|
Fclose(fd);
|
|
|
|
Unlink(sigtarget);
|
|
|
|
xfree(sigtarget);
|
|
|
|
Unlink(fileName);
|
|
|
|
return RPMERR_READERROR;
|
|
|
|
}
|
1999-11-11 06:09:49 +08:00
|
|
|
while ((count = Fread(buf, sizeof(buf[0]), sizeof(buf), ifd)) > 0) {
|
1998-01-13 05:31:29 +08:00
|
|
|
if (count == -1) {
|
1999-11-13 01:20:49 +08:00
|
|
|
rpmError(RPMERR_READERROR, _("Unable to read sigtarget %s: %s"),
|
|
|
|
sigtarget, Fstrerror(ifd));
|
1999-10-28 07:18:10 +08:00
|
|
|
Fclose(ifd);
|
|
|
|
Fclose(fd);
|
1996-02-22 23:46:54 +08:00
|
|
|
unlink(sigtarget);
|
1999-01-07 01:33:50 +08:00
|
|
|
xfree(sigtarget);
|
1998-01-13 05:31:29 +08:00
|
|
|
unlink(fileName);
|
|
|
|
return RPMERR_READERROR;
|
|
|
|
}
|
1999-11-11 06:09:49 +08:00
|
|
|
if (Fwrite(buf, sizeof(buf[0]), count, fd) < 0) {
|
1999-11-13 01:20:49 +08:00
|
|
|
rpmError(RPMERR_NOSPACE, _("Unable to write package %s: %s"),
|
|
|
|
fileName, Fstrerror(fd));
|
1999-10-28 07:18:10 +08:00
|
|
|
Fclose(ifd);
|
|
|
|
Fclose(fd);
|
1996-02-22 23:46:54 +08:00
|
|
|
unlink(sigtarget);
|
1999-01-07 01:33:50 +08:00
|
|
|
xfree(sigtarget);
|
1998-01-13 05:31:29 +08:00
|
|
|
unlink(fileName);
|
|
|
|
return RPMERR_NOSPACE;
|
|
|
|
}
|
1996-02-19 10:24:47 +08:00
|
|
|
}
|
1999-10-28 07:18:10 +08:00
|
|
|
Fclose(ifd);
|
|
|
|
Fclose(fd);
|
1996-02-19 10:24:47 +08:00
|
|
|
unlink(sigtarget);
|
1999-01-07 01:33:50 +08:00
|
|
|
xfree(sigtarget);
|
1996-06-28 01:21:31 +08:00
|
|
|
|
1998-09-28 06:03:52 +08:00
|
|
|
rpmMessage(RPMMESS_NORMAL, _("Wrote: %s\n"), fileName);
|
1995-12-21 06:49:40 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-01-25 04:02:32 +08:00
|
|
|
static int_32 copyTags[] = {
|
|
|
|
RPMTAG_CHANGELOGTIME,
|
|
|
|
RPMTAG_CHANGELOGNAME,
|
|
|
|
RPMTAG_CHANGELOGTEXT,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
/** */
|
|
|
|
int packageBinaries(Spec spec)
|
1999-09-18 07:18:24 +08:00
|
|
|
{
|
2000-01-25 04:02:32 +08:00
|
|
|
CSA_t csabuf, *csa = &csabuf;
|
1998-07-25 23:33:15 +08:00
|
|
|
int rc;
|
2000-01-25 04:02:32 +08:00
|
|
|
const char *errorString;
|
|
|
|
Package pkg;
|
1998-12-06 07:22:41 +08:00
|
|
|
|
2000-01-25 04:02:32 +08:00
|
|
|
for (pkg = spec->packages; pkg != NULL; pkg = pkg->next) {
|
|
|
|
const char *fn;
|
1995-12-21 06:49:40 +08:00
|
|
|
|
2000-01-25 04:02:32 +08:00
|
|
|
if (pkg->fileList == NULL)
|
|
|
|
continue;
|
1998-07-25 23:33:15 +08:00
|
|
|
|
2000-01-25 04:02:32 +08:00
|
|
|
if ((rc = processScriptFiles(spec, pkg)))
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
if (spec->cookie) {
|
|
|
|
headerAddEntry(pkg->header, RPMTAG_COOKIE,
|
|
|
|
RPM_STRING_TYPE, spec->cookie, 1);
|
1998-07-25 23:33:15 +08:00
|
|
|
}
|
|
|
|
|
2000-01-25 04:02:32 +08:00
|
|
|
/* Copy changelog from src rpm */
|
|
|
|
headerCopyTags(spec->packages->header, pkg->header, copyTags);
|
|
|
|
|
|
|
|
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);
|
1999-11-13 01:20:49 +08:00
|
|
|
|
2000-01-25 04:02:32 +08:00
|
|
|
{ int capability = 0;
|
|
|
|
headerAddEntry(pkg->header, RPMTAG_CAPABILITY, RPM_INT32_TYPE,
|
|
|
|
&capability, 1);
|
1995-12-21 06:49:40 +08:00
|
|
|
}
|
1998-03-21 06:38:00 +08:00
|
|
|
|
2000-04-14 01:59:10 +08:00
|
|
|
providePackageNVR(pkg->header);
|
|
|
|
|
2000-01-25 04:02:32 +08:00
|
|
|
genSourceRpmName(spec);
|
|
|
|
headerAddEntry(pkg->header, RPMTAG_SOURCERPM, RPM_STRING_TYPE,
|
|
|
|
spec->sourceRpmName, 1);
|
|
|
|
|
|
|
|
{ const char *binFormat = rpmGetPath("%{_rpmfilename}", NULL);
|
|
|
|
char *binRpm, *binDir;
|
|
|
|
binRpm = headerSprintf(pkg->header, binFormat, rpmTagTable,
|
|
|
|
rpmHeaderFormats, &errorString);
|
|
|
|
xfree(binFormat);
|
|
|
|
if (binRpm == NULL) {
|
2000-04-14 00:00:34 +08:00
|
|
|
const char *name;
|
2000-04-13 17:07:08 +08:00
|
|
|
headerNVR(pkg->header, &name, NULL, NULL);
|
2000-01-25 04:02:32 +08:00
|
|
|
rpmError(RPMERR_BADFILENAME, _("Could not generate output "
|
|
|
|
"filename for package %s: %s\n"), name, errorString);
|
|
|
|
return RPMERR_BADFILENAME;
|
|
|
|
}
|
|
|
|
fn = rpmGetPath("%{_rpmdir}/", binRpm, NULL);
|
|
|
|
if ((binDir = strchr(binRpm, '/')) != NULL) {
|
|
|
|
struct stat st;
|
|
|
|
const char *dn;
|
|
|
|
*binDir = '\0';
|
|
|
|
dn = rpmGetPath("%{_rpmdir}/", binRpm, NULL);
|
|
|
|
if (Stat(dn, &st) < 0) {
|
|
|
|
switch(errno) {
|
|
|
|
case ENOENT:
|
|
|
|
if (Mkdir(dn, 0755) == 0)
|
|
|
|
break;
|
|
|
|
/*@fallthrough@*/
|
|
|
|
default:
|
|
|
|
rpmError(RPMERR_BADFILENAME,_("cannot create %s: %s\n"),
|
|
|
|
dn, strerror(errno));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
xfree(dn);
|
|
|
|
}
|
|
|
|
xfree(binRpm);
|
|
|
|
}
|
1998-03-21 06:38:00 +08:00
|
|
|
|
2000-01-25 04:02:32 +08:00
|
|
|
memset(csa, 0, sizeof(*csa));
|
|
|
|
csa->cpioArchiveSize = 0;
|
|
|
|
csa->cpioFdIn = fdNew("init (packageBinaries)");
|
|
|
|
csa->cpioList = pkg->cpioList;
|
|
|
|
csa->cpioCount = pkg->cpioCount;
|
1998-03-21 06:38:00 +08:00
|
|
|
|
2000-01-25 04:02:32 +08:00
|
|
|
rc = writeRPM(pkg->header, fn, RPMLEAD_BINARY,
|
|
|
|
csa, spec->passPhrase, NULL);
|
|
|
|
csa->cpioFdIn = fdFree(csa->cpioFdIn, "init (packageBinaries)");
|
|
|
|
xfree(fn);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
1998-03-21 06:38:00 +08:00
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
|
1995-12-21 06:49:40 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-01-25 04:02:32 +08:00
|
|
|
/** */
|
|
|
|
int packageSources(Spec spec)
|
1998-03-21 06:38:00 +08:00
|
|
|
{
|
2000-01-25 04:02:32 +08:00
|
|
|
CSA_t csabuf, *csa = &csabuf;
|
|
|
|
int rc;
|
1998-03-21 06:38:00 +08:00
|
|
|
|
2000-01-25 04:02:32 +08:00
|
|
|
/* 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-03-21 06:38:00 +08:00
|
|
|
|
2000-01-25 04:02:32 +08:00
|
|
|
{ int capability = 0;
|
|
|
|
headerAddEntry(spec->sourceHeader, RPMTAG_CAPABILITY, RPM_INT32_TYPE,
|
|
|
|
&capability, 1);
|
|
|
|
}
|
1998-03-21 06:38:00 +08:00
|
|
|
|
2000-01-25 04:02:32 +08:00
|
|
|
genSourceRpmName(spec);
|
1998-03-21 06:38:00 +08:00
|
|
|
|
2000-01-25 04:02:32 +08:00
|
|
|
FREE(spec->cookie);
|
1998-03-21 06:38:00 +08:00
|
|
|
|
2000-01-25 04:02:32 +08:00
|
|
|
/* XXX this should be %_srpmdir */
|
|
|
|
{ const char *fn = rpmGetPath("%{_srcrpmdir}/", spec->sourceRpmName,NULL);
|
1998-01-13 05:31:29 +08:00
|
|
|
|
2000-01-25 04:02:32 +08:00
|
|
|
memset(csa, 0, sizeof(*csa));
|
|
|
|
csa->cpioArchiveSize = 0;
|
|
|
|
csa->cpioFdIn = fdNew("init (packageSources)");
|
|
|
|
csa->cpioList = spec->sourceCpioList;
|
|
|
|
csa->cpioCount = spec->sourceCpioCount;
|
1998-03-21 06:38:00 +08:00
|
|
|
|
2000-01-25 04:02:32 +08:00
|
|
|
rc = writeRPM(spec->sourceHeader, fn, RPMLEAD_SOURCE,
|
|
|
|
csa, spec->passPhrase, &(spec->cookie));
|
|
|
|
csa->cpioFdIn = fdFree(csa->cpioFdIn, "init (packageSources)");
|
|
|
|
xfree(fn);
|
|
|
|
}
|
|
|
|
return rc;
|
1995-12-21 06:49:40 +08:00
|
|
|
}
|