2000-08-28 03:18:25 +08:00
|
|
|
/** \ingroup rpmbuild
|
|
|
|
* \file build/pack.c
|
2000-01-25 04:02:32 +08:00
|
|
|
* 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 <rpmio_internal.h>
|
2000-06-20 23:54:48 +08:00
|
|
|
#include <rpmbuild.h>
|
1998-01-13 05:31:29 +08:00
|
|
|
|
2002-05-20 02:42:25 +08:00
|
|
|
#include "rpmps.h"
|
|
|
|
|
2002-04-13 09:28:20 +08:00
|
|
|
#include "cpio.h"
|
|
|
|
#include "fsm.h"
|
2002-04-12 00:55:19 +08:00
|
|
|
#include "psm.h"
|
2002-05-17 00:55:21 +08:00
|
|
|
|
2002-04-12 00:55:19 +08:00
|
|
|
#include "rpmfi.h"
|
2002-05-17 00:55:21 +08:00
|
|
|
#include "rpmts.h"
|
2002-04-12 00:55:19 +08:00
|
|
|
|
|
|
|
#include "buildio.h"
|
2001-10-26 12:16:19 +08:00
|
|
|
|
2001-10-22 05:43:32 +08:00
|
|
|
#include "legacy.h" /* XXX providePackageNVR */
|
2000-06-10 02:57:23 +08:00
|
|
|
#include "signature.h"
|
|
|
|
#include "rpmlead.h"
|
2000-12-13 04:03:45 +08:00
|
|
|
#include "debug.h"
|
1998-01-13 05:31:29 +08:00
|
|
|
|
2002-05-20 02:42:25 +08:00
|
|
|
/*@access rpmts @*/
|
|
|
|
/*@access rpmfi @*/ /* compared with NULL */
|
2001-03-15 07:09:09 +08:00
|
|
|
/*@access Header @*/ /* compared with NULL */
|
|
|
|
/*@access FD_t @*/ /* compared with NULL */
|
2001-10-26 12:16:19 +08:00
|
|
|
/*@access StringBuf @*/ /* compared with NULL */
|
2001-05-04 05:00:18 +08:00
|
|
|
/*@access CSA_t @*/
|
2001-03-15 07:09:09 +08:00
|
|
|
|
2001-01-11 22:13:04 +08:00
|
|
|
/**
|
|
|
|
*/
|
1999-08-07 06:52:49 +08:00
|
|
|
static inline int genSourceRpmName(Spec spec)
|
2001-05-04 05:00:18 +08:00
|
|
|
/*@modifies spec->sourceRpmName @*/
|
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
|
|
|
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) headerNVR(spec->packages->header, &name, &version, &release);
|
1999-08-07 06:52:49 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2001-01-11 22:13:04 +08:00
|
|
|
/**
|
2001-01-26 04:26:35 +08:00
|
|
|
* @todo Create transaction set *much* earlier.
|
2001-01-11 22:13:04 +08:00
|
|
|
*/
|
2001-05-04 05:00:18 +08:00
|
|
|
static int cpio_doio(FD_t fdo, /*@unused@*/ Header h, CSA_t csa,
|
2001-04-29 09:05:43 +08:00
|
|
|
const char * fmodeMacro)
|
2001-10-15 11:22:10 +08:00
|
|
|
/*@globals rpmGlobalMacroContext,
|
|
|
|
fileSystem@*/
|
2001-10-18 00:43:36 +08:00
|
|
|
/*@modifies fdo, csa, rpmGlobalMacroContext, fileSystem @*/
|
1998-04-08 07:58:01 +08:00
|
|
|
{
|
2002-05-20 02:42:25 +08:00
|
|
|
rpmts ts = rpmtsCreate();
|
|
|
|
rpmfi fi = csa->cpioList;
|
2001-01-24 07:03:28 +08:00
|
|
|
const char *failedFile = NULL;
|
2000-01-25 04:02:32 +08:00
|
|
|
FD_t cfd;
|
2001-06-20 14:29:20 +08:00
|
|
|
int rc, ec;
|
1998-01-13 05:31:29 +08:00
|
|
|
|
2001-08-01 02:13:22 +08:00
|
|
|
{ const char *fmode = rpmExpand(fmodeMacro, NULL);
|
|
|
|
if (!(fmode && fmode[0] == 'w'))
|
|
|
|
fmode = xstrdup("w9.gzdio");
|
|
|
|
/*@-nullpass@*/
|
|
|
|
(void) Fflush(fdo);
|
|
|
|
cfd = Fdopen(fdDup(Fileno(fdo)), fmode);
|
|
|
|
/*@=nullpass@*/
|
|
|
|
fmode = _free(fmode);
|
|
|
|
}
|
2001-05-04 05:00:18 +08:00
|
|
|
if (cfd == NULL)
|
|
|
|
return 1;
|
2001-02-02 23:04:44 +08:00
|
|
|
|
2001-02-09 05:50:38 +08:00
|
|
|
rc = fsmSetup(fi->fsm, FSM_PKGBUILD, ts, fi, cfd,
|
2001-02-04 04:07:39 +08:00
|
|
|
&csa->cpioArchiveSize, &failedFile);
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) Fclose(cfd);
|
2001-06-20 14:29:20 +08:00
|
|
|
ec = fsmTeardown(fi->fsm);
|
|
|
|
if (!rc) rc = ec;
|
2001-02-02 23:04:44 +08:00
|
|
|
|
2000-01-25 04:02:32 +08:00
|
|
|
if (rc) {
|
2001-06-20 14:29:20 +08:00
|
|
|
if (failedFile)
|
|
|
|
rpmError(RPMERR_CPIO, _("create archive failed on file %s: %s\n"),
|
2000-01-25 04:02:32 +08:00
|
|
|
failedFile, cpioStrerror(rc));
|
2001-06-20 14:29:20 +08:00
|
|
|
else
|
|
|
|
rpmError(RPMERR_CPIO, _("create archive failed: %s\n"),
|
|
|
|
cpioStrerror(rc));
|
2000-01-25 04:02:32 +08:00
|
|
|
rc = 1;
|
1998-11-20 02:10:28 +08:00
|
|
|
}
|
|
|
|
|
2001-04-29 09:05:43 +08:00
|
|
|
failedFile = _free(failedFile);
|
2002-05-17 00:55:21 +08:00
|
|
|
ts = rpmtsFree(ts);
|
1999-01-06 07:13:56 +08:00
|
|
|
|
|
|
|
return rc;
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
|
|
|
|
2001-01-11 22:13:04 +08:00
|
|
|
/**
|
|
|
|
*/
|
2001-05-04 05:00:18 +08:00
|
|
|
static int cpio_copy(FD_t fdo, CSA_t csa)
|
2001-10-15 11:22:10 +08:00
|
|
|
/*@globals fileSystem@*/
|
2001-06-04 21:55:58 +08:00
|
|
|
/*@modifies fdo, csa, fileSystem @*/
|
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) {
|
2001-01-16 07:09:42 +08:00
|
|
|
rpmError(RPMERR_CPIO, _("cpio_copy write failed: %s\n"),
|
2000-01-25 04:02:32 +08:00
|
|
|
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)) {
|
2001-01-16 07:09:42 +08:00
|
|
|
rpmError(RPMERR_CPIO, _("cpio_copy read failed: %s\n"),
|
2000-01-25 04:02:32 +08:00
|
|
|
Fstrerror(csa->cpioFdIn));
|
|
|
|
return 1;
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-01-11 22:13:04 +08:00
|
|
|
/**
|
|
|
|
*/
|
2001-05-01 06:32:22 +08:00
|
|
|
static /*@only@*/ /*@null@*/ StringBuf addFileToTagAux(Spec spec,
|
|
|
|
const char * file, /*@only@*/ StringBuf sb)
|
2001-10-15 11:22:10 +08:00
|
|
|
/*@globals rpmGlobalMacroContext,
|
|
|
|
fileSystem@*/
|
2001-10-18 00:43:36 +08:00
|
|
|
/*@modifies rpmGlobalMacroContext, fileSystem @*/
|
1998-10-12 04:58:58 +08:00
|
|
|
{
|
2000-01-25 04:02:32 +08:00
|
|
|
char buf[BUFSIZ];
|
2001-05-01 06:32:22 +08:00
|
|
|
const char * fn = buf;
|
|
|
|
FILE * f;
|
2000-01-25 04:02:32 +08:00
|
|
|
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");
|
2001-04-29 09:05:43 +08:00
|
|
|
if (fn != buf) fn = _free(fn);
|
2000-01-25 04:02:32 +08:00
|
|
|
if (fd == NULL || Ferror(fd)) {
|
2001-05-06 03:28:32 +08:00
|
|
|
sb = freeStringBuf(sb);
|
2000-01-25 04:02:32 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
2001-10-17 01:42:18 +08:00
|
|
|
/*@-type@*/ /* FIX: cast? */
|
2001-05-04 05:00:18 +08:00
|
|
|
if ((f = fdGetFp(fd)) != NULL)
|
2001-10-17 01:42:18 +08:00
|
|
|
/*@=type@*/
|
2001-05-01 06:32:22 +08:00
|
|
|
while (fgets(buf, sizeof(buf), f)) {
|
2000-01-25 04:02:32 +08:00
|
|
|
/* XXX display fn in error msg */
|
|
|
|
if (expandMacros(spec, spec->macros, buf, sizeof(buf))) {
|
2001-01-16 07:09:42 +08:00
|
|
|
rpmError(RPMERR_BADSPEC, _("line: %s\n"), buf);
|
2001-05-06 03:28:32 +08:00
|
|
|
sb = freeStringBuf(sb);
|
2001-05-01 06:32:22 +08:00
|
|
|
break;
|
2000-01-25 04:02:32 +08:00
|
|
|
}
|
|
|
|
appendStringBuf(sb, buf);
|
1998-10-12 04:58:58 +08:00
|
|
|
}
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) 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
|
|
|
|
2001-01-11 22:13:04 +08:00
|
|
|
/**
|
|
|
|
*/
|
2001-04-29 09:05:43 +08:00
|
|
|
static int addFileToTag(Spec spec, const char * file, Header h, int tag)
|
2001-10-15 11:22:10 +08:00
|
|
|
/*@globals rpmGlobalMacroContext,
|
|
|
|
fileSystem@*/
|
2001-10-18 00:43:36 +08:00
|
|
|
/*@modifies h, rpmGlobalMacroContext, fileSystem @*/
|
2000-01-25 04:02:32 +08:00
|
|
|
{
|
2001-04-29 09:05:43 +08:00
|
|
|
HGE_t hge = (HGE_t)headerGetEntryMinMemory;
|
2000-12-03 05:53:44 +08:00
|
|
|
StringBuf sb = newStringBuf();
|
2000-01-25 04:02:32 +08:00
|
|
|
char *s;
|
1998-10-12 04:58:58 +08:00
|
|
|
|
2001-04-29 09:05:43 +08:00
|
|
|
if (hge(h, tag, NULL, (void **)&s, NULL)) {
|
2000-01-25 04:02:32 +08:00
|
|
|
appendLineStringBuf(sb, s);
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) headerRemoveEntry(h, tag);
|
1998-10-12 04:58:58 +08:00
|
|
|
}
|
|
|
|
|
2000-12-03 05:53:44 +08:00
|
|
|
if ((sb = addFileToTagAux(spec, file, sb)) == NULL)
|
2000-01-25 04:02:32 +08:00
|
|
|
return 1;
|
|
|
|
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) headerAddEntry(h, tag, RPM_STRING_TYPE, getStringBuf(sb), 1);
|
1998-10-12 04:58:58 +08:00
|
|
|
|
2001-05-06 03:28:32 +08:00
|
|
|
sb = freeStringBuf(sb);
|
2000-01-25 04:02:32 +08:00
|
|
|
return 0;
|
|
|
|
}
|
1998-10-12 04:58:58 +08:00
|
|
|
|
2001-01-11 22:13:04 +08:00
|
|
|
/**
|
|
|
|
*/
|
2001-04-29 09:05:43 +08:00
|
|
|
static int addFileToArrayTag(Spec spec, const char *file, Header h, int tag)
|
2001-10-15 11:22:10 +08:00
|
|
|
/*@globals rpmGlobalMacroContext,
|
|
|
|
fileSystem@*/
|
2001-10-18 00:43:36 +08:00
|
|
|
/*@modifies h, rpmGlobalMacroContext, fileSystem @*/
|
2000-01-25 04:02:32 +08:00
|
|
|
{
|
2000-12-03 05:53:44 +08:00
|
|
|
StringBuf sb = newStringBuf();
|
2000-01-25 04:02:32 +08:00
|
|
|
char *s;
|
|
|
|
|
2000-12-03 05:53:44 +08:00
|
|
|
if ((sb = addFileToTagAux(spec, file, sb)) == NULL)
|
2000-01-25 04:02:32 +08:00
|
|
|
return 1;
|
1998-10-12 04:58:58 +08:00
|
|
|
|
2000-01-25 04:02:32 +08:00
|
|
|
s = getStringBuf(sb);
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) headerAddOrAppendEntry(h, tag, RPM_STRING_ARRAY_TYPE, &s, 1);
|
2000-01-25 04:02:32 +08:00
|
|
|
|
2001-05-06 03:28:32 +08:00
|
|
|
sb = freeStringBuf(sb);
|
1998-10-12 04:58:58 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-01-11 22:13:04 +08:00
|
|
|
/**
|
|
|
|
*/
|
2000-01-25 04:02:32 +08:00
|
|
|
static int processScriptFiles(Spec spec, Package pkg)
|
2001-10-15 11:22:10 +08:00
|
|
|
/*@globals rpmGlobalMacroContext,
|
|
|
|
fileSystem@*/
|
2001-10-18 00:43:36 +08:00
|
|
|
/*@modifies pkg->header, rpmGlobalMacroContext, fileSystem @*/
|
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,
|
2001-01-16 07:09:42 +08:00
|
|
|
_("Could not open PreIn file: %s\n"), pkg->preInFile);
|
2000-01-25 04:02:32 +08:00
|
|
|
return RPMERR_BADFILENAME;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pkg->preUnFile) {
|
|
|
|
if (addFileToTag(spec, pkg->preUnFile, pkg->header, RPMTAG_PREUN)) {
|
|
|
|
rpmError(RPMERR_BADFILENAME,
|
2001-01-16 07:09:42 +08:00
|
|
|
_("Could not open PreUn file: %s\n"), pkg->preUnFile);
|
2000-01-25 04:02:32 +08:00
|
|
|
return RPMERR_BADFILENAME;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pkg->postInFile) {
|
|
|
|
if (addFileToTag(spec, pkg->postInFile, pkg->header, RPMTAG_POSTIN)) {
|
|
|
|
rpmError(RPMERR_BADFILENAME,
|
2001-01-16 07:09:42 +08:00
|
|
|
_("Could not open PostIn file: %s\n"), pkg->postInFile);
|
2000-01-25 04:02:32 +08:00
|
|
|
return RPMERR_BADFILENAME;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pkg->postUnFile) {
|
|
|
|
if (addFileToTag(spec, pkg->postUnFile, pkg->header, RPMTAG_POSTUN)) {
|
|
|
|
rpmError(RPMERR_BADFILENAME,
|
2001-01-16 07:09:42 +08:00
|
|
|
_("Could not open PostUn file: %s\n"), pkg->postUnFile);
|
2000-01-25 04:02:32 +08:00
|
|
|
return RPMERR_BADFILENAME;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pkg->verifyFile) {
|
|
|
|
if (addFileToTag(spec, pkg->verifyFile, pkg->header,
|
|
|
|
RPMTAG_VERIFYSCRIPT)) {
|
|
|
|
rpmError(RPMERR_BADFILENAME,
|
2001-01-16 07:09:42 +08:00
|
|
|
_("Could not open VerifyScript file: %s\n"), pkg->verifyFile);
|
2000-01-25 04:02:32 +08:00
|
|
|
return RPMERR_BADFILENAME;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (p = pkg->triggerFiles; p != NULL; p = p->next) {
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) headerAddOrAppendEntry(pkg->header, RPMTAG_TRIGGERSCRIPTPROG,
|
2000-01-25 04:02:32 +08:00
|
|
|
RPM_STRING_ARRAY_TYPE, &(p->prog), 1);
|
|
|
|
if (p->script) {
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) headerAddOrAppendEntry(pkg->header, RPMTAG_TRIGGERSCRIPTS,
|
2000-01-25 04:02:32 +08:00
|
|
|
RPM_STRING_ARRAY_TYPE, &(p->script), 1);
|
|
|
|
} else if (p->fileName) {
|
|
|
|
if (addFileToArrayTag(spec, p->fileName, pkg->header,
|
|
|
|
RPMTAG_TRIGGERSCRIPTS)) {
|
|
|
|
rpmError(RPMERR_BADFILENAME,
|
2001-01-16 07:09:42 +08:00
|
|
|
_("Could not open Trigger script file: %s\n"),
|
2000-01-25 04:02:32 +08:00
|
|
|
p->fileName);
|
|
|
|
return RPMERR_BADFILENAME;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* This is dumb. When the header supports NULL string */
|
|
|
|
/* this will go away. */
|
|
|
|
char *bull = "";
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) headerAddOrAppendEntry(pkg->header, RPMTAG_TRIGGERSCRIPTS,
|
2000-01-25 04:02:32 +08:00
|
|
|
RPM_STRING_ARRAY_TYPE, &bull, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-06-12 12:10:21 +08:00
|
|
|
int readRPM(const char *fileName, Spec *specp, struct rpmlead *lead,
|
|
|
|
Header *sigs, CSA_t csa)
|
2000-01-25 04:02:32 +08:00
|
|
|
{
|
|
|
|
FD_t fdi;
|
|
|
|
Spec spec;
|
2001-02-13 03:02:15 +08:00
|
|
|
rpmRC rc;
|
2001-06-12 12:10:21 +08:00
|
|
|
|
|
|
|
fdi = (fileName != NULL)
|
|
|
|
? Fopen(fileName, "r.ufdio")
|
|
|
|
: fdDup(STDIN_FILENO);
|
2000-01-25 04:02:32 +08:00
|
|
|
|
2001-05-04 05:00:18 +08:00
|
|
|
if (fdi == NULL || Ferror(fdi)) {
|
|
|
|
rpmError(RPMERR_BADMAGIC, _("readRPM: open %s: %s\n"),
|
|
|
|
(fileName ? fileName : "<stdin>"),
|
2000-01-25 04:02:32 +08:00
|
|
|
Fstrerror(fdi));
|
2001-05-04 05:00:18 +08:00
|
|
|
if (fdi) (void) Fclose(fdi);
|
|
|
|
return RPMERR_BADMAGIC;
|
2000-01-25 04:02:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get copy of lead */
|
2001-10-16 22:58:57 +08:00
|
|
|
/*@-sizeoftype@*/
|
2000-01-25 04:02:32 +08:00
|
|
|
if ((rc = Fread(lead, sizeof(char), sizeof(*lead), fdi)) != sizeof(*lead)) {
|
2001-05-04 05:00:18 +08:00
|
|
|
rpmError(RPMERR_BADMAGIC, _("readRPM: read %s: %s\n"),
|
|
|
|
(fileName ? fileName : "<stdin>"),
|
|
|
|
Fstrerror(fdi));
|
2000-01-25 04:02:32 +08:00
|
|
|
return RPMERR_BADMAGIC;
|
|
|
|
}
|
2001-10-16 22:58:57 +08:00
|
|
|
/*@=sizeoftype@*/
|
2000-01-25 04:02:32 +08:00
|
|
|
|
2001-06-12 12:10:21 +08:00
|
|
|
/* XXX FIXME: EPIPE on <stdin> */
|
|
|
|
if (Fseek(fdi, 0, SEEK_SET) == -1) {
|
|
|
|
rpmError(RPMERR_FSEEK, _("%s: Fseek failed: %s\n"),
|
|
|
|
(fileName ? fileName : "<stdin>"), Fstrerror(fdi));
|
|
|
|
return RPMERR_FSEEK;
|
|
|
|
}
|
2000-01-25 04:02:32 +08:00
|
|
|
|
|
|
|
/* Reallocate build data structures */
|
|
|
|
spec = newSpec();
|
|
|
|
spec->packages = newPackage(spec);
|
|
|
|
|
|
|
|
/* XXX the header just allocated will be allocated again */
|
2001-11-02 04:15:10 +08:00
|
|
|
spec->packages->header = headerFree(spec->packages->header, "spec->packages");
|
2000-01-25 04:02:32 +08:00
|
|
|
|
2001-10-26 12:16:19 +08:00
|
|
|
/* Read the rpm lead, signatures, and header */
|
2002-05-20 02:42:25 +08:00
|
|
|
{ rpmts ts = rpmtsCreate();
|
2001-10-26 12:16:19 +08:00
|
|
|
|
|
|
|
/* XXX W2DO? pass fileName? */
|
|
|
|
/*@-mustmod@*/ /* LCL: segfault */
|
2001-10-28 04:09:20 +08:00
|
|
|
rc = rpmReadPackageFile(ts, fdi, "readRPM",
|
2001-10-26 12:16:19 +08:00
|
|
|
&spec->packages->header);
|
|
|
|
/*@=mustmod@*/
|
|
|
|
|
2002-05-17 00:55:21 +08:00
|
|
|
ts = rpmtsFree(ts);
|
2001-10-26 12:16:19 +08:00
|
|
|
|
|
|
|
if (sigs) *sigs = NULL; /* XXX HACK */
|
|
|
|
}
|
|
|
|
|
2000-01-25 04:02:32 +08:00
|
|
|
switch (rc) {
|
2002-05-05 04:13:14 +08:00
|
|
|
case RPMRC_NOTFOUND:
|
2000-01-25 04:02:32 +08:00
|
|
|
rpmError(RPMERR_BADMAGIC, _("readRPM: %s is not an RPM package\n"),
|
2001-05-04 05:00:18 +08:00
|
|
|
(fileName ? fileName : "<stdin>"));
|
2000-01-25 04:02:32 +08:00
|
|
|
return RPMERR_BADMAGIC;
|
2001-02-13 03:02:15 +08:00
|
|
|
case RPMRC_OK:
|
2000-01-25 04:02:32 +08:00
|
|
|
break;
|
2001-02-13 03:02:15 +08:00
|
|
|
case RPMRC_FAIL:
|
|
|
|
case RPMRC_BADSIZE:
|
|
|
|
case RPMRC_SHORTREAD:
|
2000-01-25 04:02:32 +08:00
|
|
|
default:
|
2001-01-16 07:09:42 +08:00
|
|
|
rpmError(RPMERR_BADMAGIC, _("readRPM: reading header from %s\n"),
|
2001-05-04 05:00:18 +08:00
|
|
|
(fileName ? fileName : "<stdin>"));
|
2000-01-25 04:02:32 +08:00
|
|
|
return RPMERR_BADMAGIC;
|
|
|
|
/*@notreached@*/ break;
|
|
|
|
}
|
|
|
|
|
2001-10-16 01:53:34 +08:00
|
|
|
/*@-branchstate@*/
|
2000-01-25 04:02:32 +08:00
|
|
|
if (specp)
|
|
|
|
*specp = spec;
|
2000-11-07 21:16:43 +08:00
|
|
|
else
|
2001-05-07 03:17:14 +08:00
|
|
|
spec = freeSpec(spec);
|
2001-10-16 01:53:34 +08:00
|
|
|
/*@=branchstate@*/
|
2000-01-25 04:02:32 +08:00
|
|
|
|
2001-05-04 05:00:18 +08:00
|
|
|
if (csa != NULL)
|
2000-01-25 04:02:32 +08:00
|
|
|
csa->cpioFdIn = fdi;
|
2000-11-07 21:16:43 +08:00
|
|
|
else
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) Fclose(fdi);
|
2000-01-25 04:02:32 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-03-07 07:17:31 +08:00
|
|
|
#ifdef DYING
|
2001-10-15 11:22:10 +08:00
|
|
|
/*@unchecked@*/
|
2001-06-12 12:10:21 +08:00
|
|
|
static unsigned char header_magic[8] = {
|
|
|
|
0x8e, 0xad, 0xe8, 0x01, 0x00, 0x00, 0x00, 0x00
|
|
|
|
};
|
2002-03-07 07:17:31 +08:00
|
|
|
#endif
|
2001-06-12 12:10:21 +08:00
|
|
|
|
2001-07-11 01:59:11 +08:00
|
|
|
#define RPMPKGVERSION_MIN 30004
|
|
|
|
#define RPMPKGVERSION_MAX 40003
|
2001-10-15 11:22:10 +08:00
|
|
|
/*@unchecked@*/
|
2001-07-11 01:59:11 +08:00
|
|
|
static int rpmpkg_version = -1;
|
|
|
|
|
|
|
|
static int rpmLeadVersion(void)
|
2001-10-18 00:43:36 +08:00
|
|
|
/*@globals rpmpkg_version, rpmGlobalMacroContext @*/
|
|
|
|
/*@modifies rpmpkg_version, rpmGlobalMacroContext @*/
|
2001-07-11 01:59:11 +08:00
|
|
|
{
|
|
|
|
int rpmlead_version;
|
|
|
|
|
|
|
|
/* Intitialize packaging version from macro configuration. */
|
|
|
|
if (rpmpkg_version < 0) {
|
|
|
|
rpmpkg_version = rpmExpandNumeric("%{_package_version}");
|
|
|
|
if (rpmpkg_version < RPMPKGVERSION_MIN)
|
|
|
|
rpmpkg_version = RPMPKGVERSION_MIN;
|
|
|
|
if (rpmpkg_version > RPMPKGVERSION_MAX)
|
|
|
|
rpmpkg_version = RPMPKGVERSION_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
rpmlead_version = rpmpkg_version / 10000;
|
|
|
|
if (_noDirTokens || (rpmlead_version < 3 || rpmlead_version > 4))
|
|
|
|
rpmlead_version = 3;
|
|
|
|
return rpmlead_version;
|
|
|
|
}
|
|
|
|
|
2000-11-07 21:16:43 +08:00
|
|
|
int writeRPM(Header *hdrp, const char *fileName, int type,
|
2001-05-04 05:00:18 +08:00
|
|
|
CSA_t csa, char *passPhrase, const char **cookie)
|
2000-01-25 04:02:32 +08:00
|
|
|
{
|
2000-11-07 21:16:43 +08:00
|
|
|
FD_t fd = NULL;
|
|
|
|
FD_t ifd = NULL;
|
2002-04-08 03:52:42 +08:00
|
|
|
int_32 count, sigtag;
|
2001-06-12 12:10:21 +08:00
|
|
|
const char * sigtarget;
|
2000-06-23 09:19:45 +08:00
|
|
|
const char * rpmio_flags = NULL;
|
2001-06-12 12:10:21 +08:00
|
|
|
const char * sha1 = NULL;
|
2000-06-23 09:19:45 +08:00
|
|
|
char *s;
|
1998-01-13 05:31:29 +08:00
|
|
|
char buf[BUFSIZ];
|
2001-06-12 12:10:21 +08:00
|
|
|
Header h;
|
2000-12-03 05:53:44 +08:00
|
|
|
Header sig = NULL;
|
2001-08-01 02:13:22 +08:00
|
|
|
int rc = 0;
|
1996-02-19 10:24:47 +08:00
|
|
|
|
2001-06-12 12:10:21 +08:00
|
|
|
/* Transfer header reference form *hdrp to h. */
|
2001-11-02 04:15:10 +08:00
|
|
|
h = headerLink(*hdrp, "writeRPM xfer");
|
|
|
|
*hdrp = headerFree(*hdrp, "writeRPM xfer");
|
2001-06-12 12:10:21 +08:00
|
|
|
|
2002-03-04 07:09:49 +08:00
|
|
|
#ifdef DYING
|
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 */
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) headerAddEntry(h, RPMTAG_ARCHIVESIZE, RPM_INT32_TYPE,
|
1998-08-10 01:01:57 +08:00
|
|
|
&csa->cpioArchiveSize, 1);
|
|
|
|
}
|
2002-03-04 07:09:49 +08:00
|
|
|
#endif
|
1996-02-20 07:00:16 +08:00
|
|
|
|
2000-07-11 10:12:49 +08:00
|
|
|
/* Binary packages now have explicit Provides: name = version-release. */
|
|
|
|
if (type == RPMLEAD_BINARY)
|
|
|
|
providePackageNVR(h);
|
2000-05-31 21:19:37 +08:00
|
|
|
|
2000-06-23 09:19:45 +08:00
|
|
|
/* Save payload information */
|
2001-10-16 01:53:34 +08:00
|
|
|
/*@-branchstate@*/
|
2000-06-23 09:19:45 +08:00
|
|
|
switch(type) {
|
|
|
|
case RPMLEAD_SOURCE:
|
2001-12-07 02:34:49 +08:00
|
|
|
rpmio_flags = rpmExpand("%{?_source_payload}", NULL);
|
2000-06-23 09:19:45 +08:00
|
|
|
break;
|
|
|
|
case RPMLEAD_BINARY:
|
2001-12-07 02:34:49 +08:00
|
|
|
rpmio_flags = rpmExpand("%{?_binary_payload}", NULL);
|
2000-06-23 09:19:45 +08:00
|
|
|
break;
|
|
|
|
}
|
2001-10-16 01:53:34 +08:00
|
|
|
/*@=branchstate@*/
|
2000-06-23 09:19:45 +08:00
|
|
|
if (!(rpmio_flags && *rpmio_flags)) {
|
2001-04-29 09:05:43 +08:00
|
|
|
rpmio_flags = _free(rpmio_flags);
|
2000-06-23 09:19:45 +08:00
|
|
|
rpmio_flags = xstrdup("w9.gzdio");
|
|
|
|
}
|
|
|
|
s = strchr(rpmio_flags, '.');
|
|
|
|
if (s) {
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) headerAddEntry(h, RPMTAG_PAYLOADFORMAT, RPM_STRING_TYPE, "cpio", 1);
|
2000-06-23 09:19:45 +08:00
|
|
|
if (s[1] == 'g' && s[2] == 'z')
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) headerAddEntry(h, RPMTAG_PAYLOADCOMPRESSOR, RPM_STRING_TYPE,
|
2000-06-23 09:19:45 +08:00
|
|
|
"gzip", 1);
|
|
|
|
if (s[1] == 'b' && s[2] == 'z') {
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) headerAddEntry(h, RPMTAG_PAYLOADCOMPRESSOR, RPM_STRING_TYPE,
|
2000-06-23 09:19:45 +08:00
|
|
|
"bzip2", 1);
|
|
|
|
/* Add prereq on rpm version that understands bzip2 payloads */
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) rpmlibNeedsFeature(h, "PayloadIsBzip2", "3.0.5-1");
|
2000-06-23 09:19:45 +08:00
|
|
|
}
|
2000-07-10 07:10:25 +08:00
|
|
|
strcpy(buf, rpmio_flags);
|
|
|
|
buf[s - rpmio_flags] = '\0';
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) headerAddEntry(h, RPMTAG_PAYLOADFLAGS, RPM_STRING_TYPE, buf+1, 1);
|
2000-06-23 09:19:45 +08:00
|
|
|
}
|
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
/* Create and add the cookie */
|
|
|
|
if (cookie) {
|
2001-12-07 02:34:49 +08:00
|
|
|
sprintf(buf, "%s %d", buildHost(), (int) (*getBuildTime()));
|
1999-09-21 11:22:53 +08:00
|
|
|
*cookie = xstrdup(buf);
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) headerAddEntry(h, RPMTAG_COOKIE, RPM_STRING_TYPE, *cookie, 1);
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
|
|
|
|
2000-11-09 01:07:01 +08:00
|
|
|
/* Reallocate the header into one contiguous region. */
|
2001-06-12 12:10:21 +08:00
|
|
|
h = headerReload(h, RPMTAG_HEADERIMMUTABLE);
|
2001-05-04 05:00:18 +08:00
|
|
|
if (h == NULL) { /* XXX can't happen */
|
|
|
|
rc = RPMERR_RELOAD;
|
2001-08-01 02:13:22 +08:00
|
|
|
rpmError(RPMERR_RELOAD, _("Unable to create immutable header region.\n"));
|
2001-05-04 05:00:18 +08:00
|
|
|
goto exit;
|
|
|
|
}
|
2001-06-12 12:10:21 +08:00
|
|
|
/* Re-reference reallocated header. */
|
2001-11-02 04:15:10 +08:00
|
|
|
*hdrp = headerLink(h, "writeRPM");
|
2000-11-09 01:07:01 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Write the header+archive into a temp file so that the size of
|
|
|
|
* archive (after compression) can be added to the header.
|
|
|
|
*/
|
1998-01-13 05:31:29 +08:00
|
|
|
if (makeTempFile(NULL, &sigtarget, &fd)) {
|
2001-05-04 05:00:18 +08:00
|
|
|
rc = RPMERR_CREATE;
|
2001-06-12 12:10:21 +08:00
|
|
|
rpmError(RPMERR_CREATE, _("Unable to open temp file.\n"));
|
2001-05-04 05:00:18 +08:00
|
|
|
goto exit;
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
1999-11-15 03:15:18 +08:00
|
|
|
|
2002-03-04 07:09:49 +08:00
|
|
|
fdInitDigest(fd, PGPHASHALGO_SHA1, 0);
|
1999-08-24 23:18:43 +08:00
|
|
|
if (headerWrite(fd, h, HEADER_MAGIC_YES)) {
|
|
|
|
rc = RPMERR_NOSPACE;
|
2001-08-28 02:39:17 +08:00
|
|
|
rpmError(RPMERR_NOSPACE, _("Unable to write temp header\n"));
|
1999-08-24 23:18:43 +08:00
|
|
|
} else { /* Write the archive and get the size */
|
2002-03-07 07:17:31 +08:00
|
|
|
(void) Fflush(fd);
|
2002-03-04 07:09:49 +08:00
|
|
|
fdFiniDigest(fd, PGPHASHALGO_SHA1, (void **)&sha1, NULL, 1);
|
1999-08-24 23:18:43 +08:00
|
|
|
if (csa->cpioList != NULL) {
|
2001-01-24 07:03:28 +08:00
|
|
|
rc = cpio_doio(fd, h, csa, rpmio_flags);
|
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 {
|
|
|
|
rc = RPMERR_BADARG;
|
2001-08-01 02:13:22 +08:00
|
|
|
rpmError(RPMERR_BADARG, _("Bad CSA data\n"));
|
1999-08-24 23:18:43 +08:00
|
|
|
}
|
1998-08-09 06:27:08 +08:00
|
|
|
}
|
2001-04-29 09:05:43 +08:00
|
|
|
rpmio_flags = _free(rpmio_flags);
|
1999-11-15 03:15:18 +08:00
|
|
|
|
2000-11-07 21:16:43 +08:00
|
|
|
if (rc)
|
|
|
|
goto exit;
|
1996-02-19 10:24:47 +08:00
|
|
|
|
2002-03-04 07:09:49 +08:00
|
|
|
#ifdef DYING
|
2000-11-09 01:07:01 +08:00
|
|
|
/*
|
|
|
|
* Set the actual archive size, and rewrite the header.
|
|
|
|
* This used to be done using headerModifyEntry(), but now that headers
|
|
|
|
* have regions, the value is scribbled directly into the header data
|
|
|
|
* area. Some new scheme for adding the final archive size will have
|
2001-06-12 12:10:21 +08:00
|
|
|
* to be devised if headerGetEntryMinMemory() ever changes to return
|
|
|
|
* a pointer to memory not in the region, probably by appending
|
|
|
|
* the archive size to the header region rather than including the
|
|
|
|
* archive size within the header region.
|
2000-11-09 01:07:01 +08:00
|
|
|
*/
|
1999-10-31 00:43:29 +08:00
|
|
|
if (Fileno(csa->cpioFdIn) < 0) {
|
2001-04-29 09:05:43 +08:00
|
|
|
HGE_t hge = (HGE_t)headerGetEntryMinMemory;
|
2000-11-09 01:07:01 +08:00
|
|
|
int_32 * archiveSize;
|
2001-04-29 09:05:43 +08:00
|
|
|
if (hge(h, RPMTAG_ARCHIVESIZE, NULL, (void *)&archiveSize, NULL))
|
2000-12-03 05:53:44 +08:00
|
|
|
*archiveSize = csa->cpioArchiveSize;
|
1998-08-10 01:01:57 +08:00
|
|
|
}
|
1999-10-28 07:18:10 +08:00
|
|
|
|
2001-06-12 12:10:21 +08:00
|
|
|
(void) Fflush(fd);
|
2002-04-08 03:52:42 +08:00
|
|
|
if (Fseek(fd, 0, SEEK_SET) == -1) {
|
2001-06-12 12:10:21 +08:00
|
|
|
rc = RPMERR_FSEEK;
|
|
|
|
rpmError(RPMERR_FSEEK, _("%s: Fseek failed: %s\n"),
|
|
|
|
sigtarget, Fstrerror(fd));
|
|
|
|
}
|
1999-10-28 07:18:10 +08:00
|
|
|
|
2001-10-19 09:35:57 +08:00
|
|
|
fdInitDigest(fd, PGPHASHALGO_SHA1, 0);
|
2002-04-08 03:52:42 +08:00
|
|
|
if (headerWrite(fd, h, HEADER_MAGIC_YES)) {
|
1999-08-24 23:18:43 +08:00
|
|
|
rc = RPMERR_NOSPACE;
|
2001-08-28 02:39:17 +08:00
|
|
|
rpmError(RPMERR_NOSPACE, _("Unable to write final header\n"));
|
2001-08-01 02:13:22 +08:00
|
|
|
}
|
2001-06-12 12:10:21 +08:00
|
|
|
(void) Fflush(fd);
|
2001-10-20 06:47:40 +08:00
|
|
|
fdFiniDigest(fd, PGPHASHALGO_SHA1, (void **)&sha1, NULL, 1);
|
2002-03-04 07:09:49 +08:00
|
|
|
#endif
|
1998-01-13 05:31:29 +08:00
|
|
|
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) Fclose(fd);
|
2000-11-07 21:16:43 +08:00
|
|
|
fd = NULL;
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) Unlink(fileName);
|
1999-08-24 23:18:43 +08:00
|
|
|
|
2000-11-07 21:16:43 +08:00
|
|
|
if (rc)
|
|
|
|
goto exit;
|
1998-01-13 05:31:29 +08:00
|
|
|
|
2000-12-03 05:53:44 +08:00
|
|
|
/* Generate the signature */
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) fflush(stdout);
|
2000-12-03 05:53:44 +08:00
|
|
|
sig = rpmNewSignature();
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) rpmAddSignature(sig, sigtarget, RPMSIGTAG_SIZE, passPhrase);
|
|
|
|
(void) rpmAddSignature(sig, sigtarget, RPMSIGTAG_MD5, passPhrase);
|
2002-03-04 07:09:49 +08:00
|
|
|
|
2002-04-08 03:52:42 +08:00
|
|
|
if ((sigtag = rpmLookupSignatureType(RPMLOOKUPSIG_QUERY)) > 0) {
|
|
|
|
rpmMessage(RPMMESS_NORMAL, _("Generating signature: %d\n"), sigtag);
|
|
|
|
(void) rpmAddSignature(sig, sigtarget, sigtag, passPhrase);
|
2000-12-03 05:53:44 +08:00
|
|
|
}
|
2001-06-12 12:10:21 +08:00
|
|
|
|
|
|
|
if (sha1) {
|
2002-03-04 07:09:49 +08:00
|
|
|
(void) headerAddEntry(sig, RPMSIGTAG_SHA1, RPM_STRING_TYPE, sha1, 1);
|
2001-06-12 12:10:21 +08:00
|
|
|
sha1 = _free(sha1);
|
|
|
|
}
|
2000-12-03 05:53:44 +08:00
|
|
|
|
2002-03-04 07:09:49 +08:00
|
|
|
{ int_32 payloadSize = csa->cpioArchiveSize;
|
|
|
|
(void) headerAddEntry(sig, RPMSIGTAG_PAYLOADSIZE, RPM_INT32_TYPE,
|
|
|
|
&payloadSize, 1);
|
|
|
|
}
|
|
|
|
|
2000-12-03 05:53:44 +08:00
|
|
|
/* Reallocate the signature into one contiguous region. */
|
|
|
|
sig = headerReload(sig, RPMTAG_HEADERSIGNATURES);
|
2001-05-04 05:00:18 +08:00
|
|
|
if (sig == NULL) { /* XXX can't happen */
|
|
|
|
rc = RPMERR_RELOAD;
|
2001-08-28 02:39:17 +08:00
|
|
|
rpmError(RPMERR_RELOAD, _("Unable to reload signature header.\n"));
|
2001-05-04 05:00:18 +08:00
|
|
|
goto exit;
|
|
|
|
}
|
2000-12-03 05:53:44 +08:00
|
|
|
|
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)) {
|
2001-08-01 02:13:22 +08:00
|
|
|
rc = RPMERR_CREATE;
|
1999-11-13 01:20:49 +08:00
|
|
|
rpmError(RPMERR_CREATE, _("Could not open %s: %s\n"),
|
|
|
|
fileName, Fstrerror(fd));
|
2000-11-07 21:16:43 +08:00
|
|
|
goto exit;
|
1996-03-30 04:06:02 +08:00
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
|
2000-12-03 05:53:44 +08:00
|
|
|
/* Write the lead section into the package. */
|
|
|
|
{ int archnum = -1;
|
|
|
|
int osnum = -1;
|
|
|
|
struct rpmlead lead;
|
|
|
|
|
|
|
|
if (Fileno(csa->cpioFdIn) < 0) {
|
|
|
|
#ifndef DYING
|
|
|
|
rpmGetArchInfo(NULL, &archnum);
|
|
|
|
rpmGetOsInfo(NULL, &osnum);
|
2000-08-28 03:18:25 +08:00
|
|
|
#endif
|
2000-12-03 05:53:44 +08:00
|
|
|
} else if (csa->lead != NULL) {
|
|
|
|
archnum = csa->lead->archnum;
|
|
|
|
osnum = csa->lead->osnum;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&lead, 0, sizeof(lead));
|
2001-07-11 01:59:11 +08:00
|
|
|
lead.major = rpmLeadVersion();
|
2000-12-03 05:53:44 +08:00
|
|
|
lead.minor = 0;
|
|
|
|
lead.type = type;
|
|
|
|
lead.archnum = archnum;
|
|
|
|
lead.osnum = osnum;
|
2001-02-13 00:33:08 +08:00
|
|
|
lead.signature_type = RPMSIGTYPE_HEADERSIG;
|
2000-12-03 05:53:44 +08:00
|
|
|
|
2001-02-12 06:02:29 +08:00
|
|
|
{ const char *name, *version, *release;
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) headerNVR(h, &name, &version, &release);
|
2000-12-03 05:53:44 +08:00
|
|
|
sprintf(buf, "%s-%s-%s", name, version, release);
|
|
|
|
strncpy(lead.name, buf, sizeof(lead.name));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (writeLead(fd, &lead)) {
|
2001-08-01 02:13:22 +08:00
|
|
|
rc = RPMERR_NOSPACE;
|
2001-01-16 07:09:42 +08:00
|
|
|
rpmError(RPMERR_NOSPACE, _("Unable to write package: %s\n"),
|
1999-11-11 06:09:49 +08:00
|
|
|
Fstrerror(fd));
|
2000-12-03 05:53:44 +08:00
|
|
|
goto exit;
|
|
|
|
}
|
1996-02-19 10:24:47 +08:00
|
|
|
}
|
|
|
|
|
2000-12-03 05:53:44 +08:00
|
|
|
/* Write the signature section into the package. */
|
2000-11-07 21:16:43 +08:00
|
|
|
rc = rpmWriteSignature(fd, sig);
|
2000-12-03 05:53:44 +08:00
|
|
|
if (rc)
|
2000-11-07 21:16:43 +08:00
|
|
|
goto exit;
|
2000-12-03 05:53:44 +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)) {
|
2001-08-01 02:13:22 +08:00
|
|
|
rc = RPMERR_READ;
|
2001-01-16 07:09:42 +08:00
|
|
|
rpmError(RPMERR_READ, _("Unable to open sigtarget %s: %s\n"),
|
1999-11-13 01:20:49 +08:00
|
|
|
sigtarget, Fstrerror(ifd));
|
2000-11-07 21:16:43 +08:00
|
|
|
goto exit;
|
1999-11-13 01:20:49 +08:00
|
|
|
}
|
2000-12-03 05:53:44 +08:00
|
|
|
|
|
|
|
/* Add signatures to header, and write header into the package. */
|
2002-03-04 07:09:49 +08:00
|
|
|
/* XXX header+payload digests/signatures might be checked again here. */
|
2000-12-03 05:53:44 +08:00
|
|
|
{ Header nh = headerRead(ifd, HEADER_MAGIC_YES);
|
|
|
|
|
|
|
|
if (nh == NULL) {
|
2001-08-01 02:13:22 +08:00
|
|
|
rc = RPMERR_READ;
|
2001-01-16 07:09:42 +08:00
|
|
|
rpmError(RPMERR_READ, _("Unable to read header from %s: %s\n"),
|
2000-12-03 05:53:44 +08:00
|
|
|
sigtarget, Fstrerror(ifd));
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NOTYET
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) headerMergeLegacySigs(nh, sig);
|
2000-12-03 05:53:44 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
rc = headerWrite(fd, nh, HEADER_MAGIC_YES);
|
2001-11-02 04:15:10 +08:00
|
|
|
nh = headerFree(nh, "writeRPM nh");
|
2000-12-03 05:53:44 +08:00
|
|
|
|
|
|
|
if (rc) {
|
2001-08-01 02:13:22 +08:00
|
|
|
rc = RPMERR_NOSPACE;
|
2001-01-16 07:09:42 +08:00
|
|
|
rpmError(RPMERR_NOSPACE, _("Unable to write header to %s: %s\n"),
|
2000-12-03 05:53:44 +08:00
|
|
|
fileName, Fstrerror(fd));
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write the payload into the package. */
|
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) {
|
2001-08-01 02:13:22 +08:00
|
|
|
rc = RPMERR_READ;
|
2001-01-16 07:09:42 +08:00
|
|
|
rpmError(RPMERR_READ, _("Unable to read payload from %s: %s\n"),
|
1999-11-13 01:20:49 +08:00
|
|
|
sigtarget, Fstrerror(ifd));
|
2000-11-07 21:16:43 +08:00
|
|
|
goto exit;
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
2001-04-18 02:30:23 +08:00
|
|
|
if (Fwrite(buf, sizeof(buf[0]), count, fd) != count) {
|
2001-08-01 02:13:22 +08:00
|
|
|
rc = RPMERR_NOSPACE;
|
2001-01-16 07:09:42 +08:00
|
|
|
rpmError(RPMERR_NOSPACE, _("Unable to write payload to %s: %s\n"),
|
1999-11-13 01:20:49 +08:00
|
|
|
fileName, Fstrerror(fd));
|
2000-11-07 21:16:43 +08:00
|
|
|
goto exit;
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
1996-02-19 10:24:47 +08:00
|
|
|
}
|
2000-11-07 21:16:43 +08:00
|
|
|
rc = 0;
|
1996-06-28 01:21:31 +08:00
|
|
|
|
2000-11-07 21:16:43 +08:00
|
|
|
exit:
|
2001-06-12 12:10:21 +08:00
|
|
|
sha1 = _free(sha1);
|
2001-11-02 04:15:10 +08:00
|
|
|
h = headerFree(h, "writeRPM exit");
|
2001-05-23 22:25:19 +08:00
|
|
|
sig = rpmFreeSignature(sig);
|
2000-11-07 21:16:43 +08:00
|
|
|
if (ifd) {
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) Fclose(ifd);
|
2000-11-07 21:16:43 +08:00
|
|
|
ifd = NULL;
|
|
|
|
}
|
|
|
|
if (fd) {
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) Fclose(fd);
|
2000-11-07 21:16:43 +08:00
|
|
|
fd = NULL;
|
|
|
|
}
|
|
|
|
if (sigtarget) {
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) Unlink(sigtarget);
|
2001-04-29 09:05:43 +08:00
|
|
|
sigtarget = _free(sigtarget);
|
2000-11-07 21:16:43 +08:00
|
|
|
}
|
1995-12-21 06:49:40 +08:00
|
|
|
|
2000-11-07 21:16:43 +08:00
|
|
|
if (rc == 0)
|
|
|
|
rpmMessage(RPMMESS_NORMAL, _("Wrote: %s\n"), fileName);
|
|
|
|
else
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) Unlink(fileName);
|
2000-11-07 21:16:43 +08:00
|
|
|
|
|
|
|
return rc;
|
1995-12-21 06:49:40 +08:00
|
|
|
}
|
|
|
|
|
2001-10-15 11:22:10 +08:00
|
|
|
/*@unchecked@*/
|
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
|
|
|
{
|
2001-05-04 05:00:18 +08:00
|
|
|
struct cpioSourceArchive_s csabuf;
|
|
|
|
CSA_t 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) {
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) headerAddEntry(pkg->header, RPMTAG_COOKIE,
|
2000-01-25 04:02:32 +08:00
|
|
|
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);
|
|
|
|
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) headerAddEntry(pkg->header, RPMTAG_RPMVERSION,
|
2000-01-25 04:02:32 +08:00
|
|
|
RPM_STRING_TYPE, VERSION, 1);
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) headerAddEntry(pkg->header, RPMTAG_BUILDHOST,
|
2000-01-25 04:02:32 +08:00
|
|
|
RPM_STRING_TYPE, buildHost(), 1);
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) headerAddEntry(pkg->header, RPMTAG_BUILDTIME,
|
2000-01-25 04:02:32 +08:00
|
|
|
RPM_INT32_TYPE, getBuildTime(), 1);
|
1999-11-13 01:20:49 +08:00
|
|
|
|
2000-04-14 01:59:10 +08:00
|
|
|
providePackageNVR(pkg->header);
|
|
|
|
|
2000-06-21 05:45:50 +08:00
|
|
|
{ const char * optflags = rpmExpand("%{optflags}", NULL);
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) headerAddEntry(pkg->header, RPMTAG_OPTFLAGS, RPM_STRING_TYPE,
|
2000-06-21 05:45:50 +08:00
|
|
|
optflags, 1);
|
2001-04-29 09:05:43 +08:00
|
|
|
optflags = _free(optflags);
|
2000-06-21 05:45:50 +08:00
|
|
|
}
|
|
|
|
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) genSourceRpmName(spec);
|
|
|
|
(void) headerAddEntry(pkg->header, RPMTAG_SOURCERPM, RPM_STRING_TYPE,
|
2000-01-25 04:02:32 +08:00
|
|
|
spec->sourceRpmName, 1);
|
|
|
|
|
|
|
|
{ const char *binFormat = rpmGetPath("%{_rpmfilename}", NULL);
|
|
|
|
char *binRpm, *binDir;
|
|
|
|
binRpm = headerSprintf(pkg->header, binFormat, rpmTagTable,
|
|
|
|
rpmHeaderFormats, &errorString);
|
2001-04-29 09:05:43 +08:00
|
|
|
binFormat = _free(binFormat);
|
2000-01-25 04:02:32 +08:00
|
|
|
if (binRpm == NULL) {
|
2000-04-14 00:00:34 +08:00
|
|
|
const char *name;
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) 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)
|
2001-10-14 06:01:38 +08:00
|
|
|
/*@switchbreak@*/ break;
|
2000-01-25 04:02:32 +08:00
|
|
|
/*@fallthrough@*/
|
|
|
|
default:
|
|
|
|
rpmError(RPMERR_BADFILENAME,_("cannot create %s: %s\n"),
|
|
|
|
dn, strerror(errno));
|
2001-10-14 06:01:38 +08:00
|
|
|
/*@switchbreak@*/ break;
|
2000-01-25 04:02:32 +08:00
|
|
|
}
|
|
|
|
}
|
2001-04-29 09:05:43 +08:00
|
|
|
dn = _free(dn);
|
2000-01-25 04:02:32 +08:00
|
|
|
}
|
2001-04-29 09:05:43 +08:00
|
|
|
binRpm = _free(binRpm);
|
2000-01-25 04:02:32 +08:00
|
|
|
}
|
1998-03-21 06:38:00 +08:00
|
|
|
|
2000-01-25 04:02:32 +08:00
|
|
|
memset(csa, 0, sizeof(*csa));
|
|
|
|
csa->cpioArchiveSize = 0;
|
2001-10-17 01:42:18 +08:00
|
|
|
/*@-type@*/ /* LCL: function typedefs */
|
2000-01-25 04:02:32 +08:00
|
|
|
csa->cpioFdIn = fdNew("init (packageBinaries)");
|
2001-10-29 06:17:47 +08:00
|
|
|
/*@-assignexpose -newreftrans@*/
|
|
|
|
/*@i@*/ csa->cpioList = pkg->cpioList;
|
|
|
|
/*@=assignexpose =newreftrans@*/
|
1998-03-21 06:38:00 +08:00
|
|
|
|
2000-11-07 21:16:43 +08:00
|
|
|
rc = writeRPM(&pkg->header, fn, RPMLEAD_BINARY,
|
2000-01-25 04:02:32 +08:00
|
|
|
csa, spec->passPhrase, NULL);
|
|
|
|
csa->cpioFdIn = fdFree(csa->cpioFdIn, "init (packageBinaries)");
|
2001-10-17 01:42:18 +08:00
|
|
|
/*@=type@*/
|
2001-04-29 09:05:43 +08:00
|
|
|
fn = _free(fn);
|
2000-01-25 04:02:32 +08:00
|
|
|
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
|
|
|
{
|
2001-05-04 05:00:18 +08:00
|
|
|
struct cpioSourceArchive_s csabuf;
|
|
|
|
CSA_t csa = &csabuf;
|
2000-01-25 04:02:32 +08:00
|
|
|
int rc;
|
1998-03-21 06:38:00 +08:00
|
|
|
|
2000-01-25 04:02:32 +08:00
|
|
|
/* Add some cruft */
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) headerAddEntry(spec->sourceHeader, RPMTAG_RPMVERSION,
|
2000-01-25 04:02:32 +08:00
|
|
|
RPM_STRING_TYPE, VERSION, 1);
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) headerAddEntry(spec->sourceHeader, RPMTAG_BUILDHOST,
|
2000-01-25 04:02:32 +08:00
|
|
|
RPM_STRING_TYPE, buildHost(), 1);
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) headerAddEntry(spec->sourceHeader, RPMTAG_BUILDTIME,
|
2000-01-25 04:02:32 +08:00
|
|
|
RPM_INT32_TYPE, getBuildTime(), 1);
|
1998-03-21 06:38:00 +08:00
|
|
|
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) genSourceRpmName(spec);
|
1998-03-21 06:38:00 +08:00
|
|
|
|
2001-04-29 09:05:43 +08:00
|
|
|
spec->cookie = _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;
|
2001-10-17 01:42:18 +08:00
|
|
|
/*@-type@*/ /* LCL: function typedefs */
|
2000-01-25 04:02:32 +08:00
|
|
|
csa->cpioFdIn = fdNew("init (packageSources)");
|
2001-10-29 06:17:47 +08:00
|
|
|
/*@-assignexpose -newreftrans@*/
|
|
|
|
/*@i@*/ csa->cpioList = spec->sourceCpioList;
|
|
|
|
/*@=assignexpose =newreftrans@*/
|
1998-03-21 06:38:00 +08:00
|
|
|
|
2000-11-07 21:16:43 +08:00
|
|
|
rc = writeRPM(&spec->sourceHeader, fn, RPMLEAD_SOURCE,
|
2000-01-25 04:02:32 +08:00
|
|
|
csa, spec->passPhrase, &(spec->cookie));
|
|
|
|
csa->cpioFdIn = fdFree(csa->cpioFdIn, "init (packageSources)");
|
2001-10-17 01:42:18 +08:00
|
|
|
/*@=type@*/
|
2001-04-29 09:05:43 +08:00
|
|
|
fn = _free(fn);
|
2000-01-25 04:02:32 +08:00
|
|
|
}
|
|
|
|
return rc;
|
1995-12-21 06:49:40 +08:00
|
|
|
}
|