2000-08-28 03:27:03 +08:00
|
|
|
/** \ingroup rpmtrans payload
|
2001-02-11 00:47:40 +08:00
|
|
|
* \file lib/psm.c
|
2000-08-28 03:27:03 +08:00
|
|
|
*/
|
|
|
|
|
1998-07-26 05:00:26 +08:00
|
|
|
#include "system.h"
|
1997-01-18 00:22:57 +08:00
|
|
|
|
1999-07-14 05:37:57 +08:00
|
|
|
#include <rpmlib.h>
|
1999-11-13 01:20:49 +08:00
|
|
|
#include <rpmmacro.h>
|
|
|
|
#include <rpmurl.h>
|
1996-01-09 03:31:44 +08:00
|
|
|
|
2001-02-11 00:47:40 +08:00
|
|
|
#include "psm.h"
|
2001-02-12 06:02:29 +08:00
|
|
|
#include "rpmlead.h" /* writeLead proto */
|
|
|
|
#include "signature.h" /* signature constants */
|
1996-02-15 06:20:08 +08:00
|
|
|
#include "misc.h"
|
2000-12-13 04:03:45 +08:00
|
|
|
#include "debug.h"
|
1996-01-09 03:31:44 +08:00
|
|
|
|
2001-02-11 00:47:40 +08:00
|
|
|
/*@access Header @*/ /* compared with NULL */
|
|
|
|
/*@access rpmTransactionSet @*/ /* compared with NULL */
|
|
|
|
/*@access TFI_t @*/ /* compared with NULL */
|
|
|
|
|
|
|
|
extern int _fsm_debug;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
|
|
|
|
* @param this memory to free
|
|
|
|
* @retval NULL always
|
|
|
|
*/
|
|
|
|
static /*@null@*/ void * _free(/*@only@*/ /*@null@*/ const void * this) {
|
|
|
|
if (this) free((void *)this);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void loadFi(Header h, TFI_t fi)
|
|
|
|
{
|
|
|
|
HGE_t hge;
|
|
|
|
HFD_t hfd;
|
|
|
|
uint_32 * uip;
|
|
|
|
int len;
|
|
|
|
int rc;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (fi->fsm == NULL)
|
|
|
|
fi->fsm = newFSM();
|
|
|
|
|
|
|
|
/* XXX avoid gcc noise on pointer (4th arg) cast(s) */
|
|
|
|
hge = (fi->type == TR_ADDED)
|
|
|
|
? (HGE_t) headerGetEntryMinMemory : (HGE_t) headerGetEntry;
|
|
|
|
fi->hge = hge;
|
|
|
|
|
|
|
|
fi->hfd = hfd = headerFreeData;
|
|
|
|
|
|
|
|
if (h && fi->h == NULL) fi->h = headerLink(h);
|
|
|
|
|
|
|
|
/* Duplicate name-version-release so that headers can be free'd. */
|
|
|
|
hge(fi->h, RPMTAG_NAME, NULL, (void **) &fi->name, NULL);
|
|
|
|
fi->name = xstrdup(fi->name);
|
|
|
|
hge(fi->h, RPMTAG_VERSION, NULL, (void **) &fi->version, NULL);
|
|
|
|
fi->version = xstrdup(fi->version);
|
|
|
|
hge(fi->h, RPMTAG_RELEASE, NULL, (void **) &fi->release, NULL);
|
|
|
|
fi->release = xstrdup(fi->release);
|
|
|
|
|
|
|
|
/* -1 means not found */
|
|
|
|
rc = hge(fi->h, RPMTAG_EPOCH, NULL, (void **) &uip, NULL);
|
|
|
|
fi->epoch = (rc ? *uip : -1);
|
|
|
|
/* 0 means unknown */
|
|
|
|
rc = hge(fi->h, RPMTAG_ARCHIVESIZE, NULL, (void **) &uip, NULL);
|
|
|
|
fi->archiveSize = (rc ? *uip : 0);
|
|
|
|
|
|
|
|
if (!hge(fi->h, RPMTAG_BASENAMES, NULL, (void **) &fi->bnl, &fi->fc)) {
|
|
|
|
fi->dc = 0;
|
|
|
|
fi->fc = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
hge(fi->h, RPMTAG_DIRINDEXES, NULL, (void **) &fi->dil, NULL);
|
|
|
|
hge(fi->h, RPMTAG_DIRNAMES, NULL, (void **) &fi->dnl, &fi->dc);
|
|
|
|
hge(fi->h, RPMTAG_FILEMODES, NULL, (void **) &fi->fmodes, NULL);
|
|
|
|
hge(fi->h, RPMTAG_FILEFLAGS, NULL, (void **) &fi->fflags, NULL);
|
|
|
|
hge(fi->h, RPMTAG_FILESIZES, NULL, (void **) &fi->fsizes, NULL);
|
|
|
|
hge(fi->h, RPMTAG_FILESTATES, NULL, (void **) &fi->fstates, NULL);
|
|
|
|
|
|
|
|
fi->action = FA_UNKNOWN;
|
|
|
|
fi->flags = 0;
|
|
|
|
|
|
|
|
/* actions is initialized earlier for added packages */
|
|
|
|
if (fi->actions == NULL)
|
|
|
|
fi->actions = xcalloc(fi->fc, sizeof(*fi->actions));
|
|
|
|
|
|
|
|
switch (fi->type) {
|
|
|
|
case TR_ADDED:
|
|
|
|
fi->mapflags = CPIO_MAP_PATH | CPIO_MAP_MODE | CPIO_MAP_UID | CPIO_MAP_GID;
|
|
|
|
hge(fi->h, RPMTAG_FILEMD5S, NULL, (void **) &fi->fmd5s, NULL);
|
|
|
|
hge(fi->h, RPMTAG_FILELINKTOS, NULL, (void **) &fi->flinks, NULL);
|
|
|
|
hge(fi->h, RPMTAG_FILELANGS, NULL, (void **) &fi->flangs, NULL);
|
|
|
|
hge(fi->h, RPMTAG_FILEMTIMES, NULL, (void **) &fi->fmtimes, NULL);
|
|
|
|
|
|
|
|
/* 0 makes for noops */
|
|
|
|
fi->replacedSizes = xcalloc(fi->fc, sizeof(*fi->replacedSizes));
|
|
|
|
|
|
|
|
break;
|
|
|
|
case TR_REMOVED:
|
2001-02-12 06:02:29 +08:00
|
|
|
fi->mapflags = CPIO_MAP_ABSOLUTE | CPIO_MAP_ADDDOT | CPIO_MAP_PATH | CPIO_MAP_MODE;
|
2001-02-11 00:47:40 +08:00
|
|
|
hge(fi->h, RPMTAG_FILEMD5S, NULL, (void **) &fi->fmd5s, NULL);
|
|
|
|
hge(fi->h, RPMTAG_FILELINKTOS, NULL, (void **) &fi->flinks, NULL);
|
|
|
|
fi->fsizes = memcpy(xmalloc(fi->fc * sizeof(*fi->fsizes)),
|
|
|
|
fi->fsizes, fi->fc * sizeof(*fi->fsizes));
|
|
|
|
fi->fflags = memcpy(xmalloc(fi->fc * sizeof(*fi->fflags)),
|
|
|
|
fi->fflags, fi->fc * sizeof(*fi->fflags));
|
|
|
|
fi->fmodes = memcpy(xmalloc(fi->fc * sizeof(*fi->fmodes)),
|
|
|
|
fi->fmodes, fi->fc * sizeof(*fi->fmodes));
|
|
|
|
/* XXX there's a tedious segfault here for some version(s) of rpm */
|
|
|
|
if (fi->fstates)
|
|
|
|
fi->fstates = memcpy(xmalloc(fi->fc * sizeof(*fi->fstates)),
|
|
|
|
fi->fstates, fi->fc * sizeof(*fi->fstates));
|
|
|
|
else
|
|
|
|
fi->fstates = xcalloc(1, fi->fc * sizeof(*fi->fstates));
|
|
|
|
fi->dil = memcpy(xmalloc(fi->fc * sizeof(*fi->dil)),
|
|
|
|
fi->dil, fi->fc * sizeof(*fi->dil));
|
|
|
|
headerFree(fi->h);
|
|
|
|
fi->h = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
fi->dnlmax = -1;
|
|
|
|
for (i = 0; i < fi->dc; i++) {
|
|
|
|
if ((len = strlen(fi->dnl[i])) > fi->dnlmax)
|
|
|
|
fi->dnlmax = len;
|
|
|
|
}
|
|
|
|
|
|
|
|
fi->bnlmax = -1;
|
|
|
|
for (i = 0; i < fi->fc; i++) {
|
|
|
|
if ((len = strlen(fi->bnl[i])) > fi->bnlmax)
|
|
|
|
fi->bnlmax = len;
|
|
|
|
}
|
|
|
|
|
|
|
|
fi->dperms = 0755;
|
|
|
|
fi->fperms = 0644;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void freeFi(TFI_t fi)
|
|
|
|
{
|
|
|
|
HFD_t hfd = (fi->hfd ? fi->hfd : headerFreeData);
|
|
|
|
|
|
|
|
fi->name = _free(fi->name);
|
|
|
|
fi->version = _free(fi->version);
|
|
|
|
fi->release = _free(fi->release);
|
|
|
|
fi->actions = _free(fi->actions);
|
|
|
|
fi->replacedSizes = _free(fi->replacedSizes);
|
|
|
|
fi->replaced = _free(fi->replaced);
|
|
|
|
|
|
|
|
fi->bnl = hfd(fi->bnl, -1);
|
|
|
|
fi->dnl = hfd(fi->dnl, -1);
|
|
|
|
fi->obnl = hfd(fi->obnl, -1);
|
|
|
|
fi->odnl = hfd(fi->odnl, -1);
|
|
|
|
fi->flinks = hfd(fi->flinks, -1);
|
|
|
|
fi->fmd5s = hfd(fi->fmd5s, -1);
|
|
|
|
fi->fuser = hfd(fi->fuser, -1);
|
|
|
|
fi->fgroup = hfd(fi->fgroup, -1);
|
|
|
|
fi->flangs = hfd(fi->flangs, -1);
|
|
|
|
|
|
|
|
fi->apath = _free(fi->apath);
|
|
|
|
fi->fuids = _free(fi->fuids);
|
|
|
|
fi->fgids = _free(fi->fgids);
|
|
|
|
fi->fmapflags = _free(fi->fmapflags);
|
|
|
|
|
|
|
|
fi->fsm = freeFSM(fi->fsm);
|
|
|
|
|
|
|
|
switch (fi->type) {
|
|
|
|
case TR_ADDED:
|
|
|
|
break;
|
|
|
|
case TR_REMOVED:
|
|
|
|
fi->fsizes = hfd(fi->fsizes, -1);
|
|
|
|
fi->fflags = hfd(fi->fflags, -1);
|
|
|
|
fi->fmodes = hfd(fi->fmodes, -1);
|
|
|
|
fi->fstates = hfd(fi->fstates, -1);
|
|
|
|
fi->dil = hfd(fi->dil, -1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (fi->h) {
|
|
|
|
headerFree(fi->h); fi->h = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*@observer@*/ const char *const fiTypeString(TFI_t fi) {
|
|
|
|
switch(fi->type) {
|
|
|
|
case TR_ADDED: return " install";
|
|
|
|
case TR_REMOVED: return " erase";
|
|
|
|
default: return "???";
|
|
|
|
}
|
|
|
|
/*@noteached@*/
|
|
|
|
}
|
|
|
|
|
|
|
|
/*@obserever@*/ const char *const fileActionString(fileAction a)
|
|
|
|
{
|
|
|
|
switch (a) {
|
|
|
|
case FA_UNKNOWN: return "unknown";
|
|
|
|
case FA_CREATE: return "create";
|
2001-02-12 06:02:29 +08:00
|
|
|
case FA_COPYOUT: return "copyout";
|
|
|
|
case FA_COPYIN: return "copyin";
|
2001-02-11 00:47:40 +08:00
|
|
|
case FA_BACKUP: return "backup";
|
|
|
|
case FA_SAVE: return "save";
|
|
|
|
case FA_SKIP: return "skip";
|
|
|
|
case FA_ALTNAME: return "altname";
|
|
|
|
case FA_ERASE: return "erase";
|
|
|
|
case FA_SKIPNSTATE: return "skipnstate";
|
|
|
|
case FA_SKIPNETSHARED: return "skipnetshared";
|
|
|
|
case FA_SKIPMULTILIB: return "skipmultilib";
|
|
|
|
default: return "???";
|
|
|
|
}
|
|
|
|
/*@notreached@*/
|
|
|
|
}
|
|
|
|
|
2000-08-23 21:02:13 +08:00
|
|
|
/**
|
|
|
|
* Macros to be defined from per-header tag values.
|
2001-01-26 04:26:35 +08:00
|
|
|
* @todo Should other macros be added from header when installing a package?
|
2000-08-23 21:02:13 +08:00
|
|
|
*/
|
1999-04-03 08:05:03 +08:00
|
|
|
static struct tagMacro {
|
2000-08-23 21:02:13 +08:00
|
|
|
const char * macroname; /*!< Macro name to define. */
|
|
|
|
int tag; /*!< Header tag to use for value. */
|
1999-04-03 08:05:03 +08:00
|
|
|
} tagMacros[] = {
|
|
|
|
{ "name", RPMTAG_NAME },
|
|
|
|
{ "version", RPMTAG_VERSION },
|
|
|
|
{ "release", RPMTAG_RELEASE },
|
1999-08-09 22:28:13 +08:00
|
|
|
#if 0
|
|
|
|
{ "epoch", RPMTAG_EPOCH },
|
|
|
|
#endif
|
1999-04-03 08:05:03 +08:00
|
|
|
{ NULL, 0 }
|
|
|
|
};
|
|
|
|
|
2000-08-23 21:02:13 +08:00
|
|
|
/**
|
|
|
|
* Define per-header macros.
|
|
|
|
* @param h header
|
|
|
|
* @return 0 always
|
|
|
|
*/
|
2001-02-06 06:22:43 +08:00
|
|
|
static int rpmInstallLoadMacros(TFI_t fi, Header h)
|
1999-07-14 06:53:46 +08:00
|
|
|
{
|
2001-02-06 06:22:43 +08:00
|
|
|
HGE_t hge = (HGE_t)fi->hge;
|
1999-04-03 08:05:03 +08:00
|
|
|
struct tagMacro *tagm;
|
2000-05-13 07:30:28 +08:00
|
|
|
union {
|
|
|
|
const char * ptr;
|
2001-01-21 23:43:32 +08:00
|
|
|
int_32 * i32p;
|
2000-05-13 07:30:28 +08:00
|
|
|
} body;
|
1999-08-09 22:28:13 +08:00
|
|
|
char numbuf[32];
|
2001-01-22 07:48:09 +08:00
|
|
|
int_32 type;
|
1999-04-03 08:05:03 +08:00
|
|
|
|
|
|
|
for (tagm = tagMacros; tagm->macroname != NULL; tagm++) {
|
2001-02-06 06:22:43 +08:00
|
|
|
if (!hge(h, tagm->tag, &type, (void **) &body, NULL))
|
1999-08-09 22:28:13 +08:00
|
|
|
continue;
|
|
|
|
switch (type) {
|
|
|
|
case RPM_INT32_TYPE:
|
2001-01-21 23:43:32 +08:00
|
|
|
sprintf(numbuf, "%d", *body.i32p);
|
2000-05-13 07:30:28 +08:00
|
|
|
addMacro(NULL, tagm->macroname, NULL, numbuf, -1);
|
|
|
|
break;
|
1999-08-09 22:28:13 +08:00
|
|
|
case RPM_STRING_TYPE:
|
2000-05-13 07:30:28 +08:00
|
|
|
addMacro(NULL, tagm->macroname, NULL, body.ptr, -1);
|
1999-08-09 22:28:13 +08:00
|
|
|
break;
|
1999-04-03 08:05:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-08-23 21:02:13 +08:00
|
|
|
/**
|
2000-10-24 21:46:51 +08:00
|
|
|
* Localize user/group id's.
|
2001-01-24 07:03:28 +08:00
|
|
|
* @param fi transaction element file info
|
2001-03-02 23:03:29 +08:00
|
|
|
* @return 0 always
|
2000-08-23 21:02:13 +08:00
|
|
|
*/
|
2001-03-02 23:03:29 +08:00
|
|
|
static int setFileOwners(TFI_t fi)
|
1999-07-14 06:53:46 +08:00
|
|
|
{
|
2001-01-24 23:58:35 +08:00
|
|
|
uid_t uid;
|
|
|
|
gid_t gid;
|
1997-10-29 04:59:16 +08:00
|
|
|
int i;
|
|
|
|
|
2001-01-24 23:58:35 +08:00
|
|
|
for (i = 0; i < fi->fc; i++) {
|
|
|
|
if (unameToUid(fi->fuser[i], &uid)) {
|
2000-12-20 01:43:56 +08:00
|
|
|
rpmMessage(RPMMESS_WARNING,
|
2001-01-24 07:03:28 +08:00
|
|
|
_("user %s does not exist - using root\n"), fi->fuser[i]);
|
2001-01-24 23:58:35 +08:00
|
|
|
uid = 0;
|
2001-01-24 07:03:28 +08:00
|
|
|
/* XXX this diddles header memory. */
|
|
|
|
fi->fmodes[i] &= ~S_ISUID; /* turn off the suid bit */
|
1997-05-06 04:46:58 +08:00
|
|
|
}
|
|
|
|
|
2001-01-24 23:58:35 +08:00
|
|
|
if (gnameToGid(fi->fgroup[i], &gid)) {
|
2000-12-20 01:43:56 +08:00
|
|
|
rpmMessage(RPMMESS_WARNING,
|
2001-01-24 07:03:28 +08:00
|
|
|
_("group %s does not exist - using root\n"), fi->fgroup[i]);
|
2001-01-24 23:58:35 +08:00
|
|
|
gid = 0;
|
2001-01-24 07:03:28 +08:00
|
|
|
/* XXX this diddles header memory. */
|
|
|
|
fi->fmodes[i] &= ~S_ISGID; /* turn off the sgid bit */
|
1997-05-06 04:46:58 +08:00
|
|
|
}
|
2001-01-24 23:58:35 +08:00
|
|
|
fi->fuids[i] = uid;
|
|
|
|
fi->fgids[i] = gid;
|
1997-05-06 04:46:58 +08:00
|
|
|
}
|
2001-03-02 23:03:29 +08:00
|
|
|
return 0;
|
1997-05-06 04:46:58 +08:00
|
|
|
}
|
|
|
|
|
2000-08-23 21:02:13 +08:00
|
|
|
/**
|
2000-10-24 21:46:51 +08:00
|
|
|
* Copy file data from h to newH.
|
|
|
|
* @param h header from
|
|
|
|
* @param newH header to
|
|
|
|
* @param actions array of file dispositions
|
2001-01-04 04:19:27 +08:00
|
|
|
* @return 0 on success, 1 on failure
|
2000-08-23 21:02:13 +08:00
|
|
|
*/
|
2001-02-06 06:22:43 +08:00
|
|
|
static int mergeFiles(TFI_t fi, Header h, Header newH)
|
2000-07-06 04:39:15 +08:00
|
|
|
{
|
2001-02-06 06:22:43 +08:00
|
|
|
HGE_t hge = (HGE_t)fi->hge;
|
|
|
|
HFD_t hfd = fi->hfd;
|
2001-01-28 01:42:24 +08:00
|
|
|
fileAction * actions = fi->actions;
|
2001-01-24 07:03:28 +08:00
|
|
|
int i, j, k, fc;
|
2001-01-27 01:06:09 +08:00
|
|
|
int_32 type = 0;
|
|
|
|
int_32 count = 0;
|
|
|
|
int_32 dirNamesCount, dirCount;
|
2000-07-06 04:39:15 +08:00
|
|
|
void * data, * newdata;
|
|
|
|
int_32 * dirIndexes, * newDirIndexes;
|
|
|
|
uint_32 * fileSizes, fileSize;
|
2001-01-27 01:06:09 +08:00
|
|
|
const char ** dirNames;
|
|
|
|
const char ** newDirNames;
|
2000-07-06 04:39:15 +08:00
|
|
|
static int_32 mergeTags[] = {
|
|
|
|
RPMTAG_FILESIZES,
|
|
|
|
RPMTAG_FILESTATES,
|
|
|
|
RPMTAG_FILEMODES,
|
|
|
|
RPMTAG_FILERDEVS,
|
|
|
|
RPMTAG_FILEMTIMES,
|
|
|
|
RPMTAG_FILEMD5S,
|
|
|
|
RPMTAG_FILELINKTOS,
|
|
|
|
RPMTAG_FILEFLAGS,
|
|
|
|
RPMTAG_FILEUSERNAME,
|
|
|
|
RPMTAG_FILEGROUPNAME,
|
|
|
|
RPMTAG_FILEVERIFYFLAGS,
|
|
|
|
RPMTAG_FILEDEVICES,
|
|
|
|
RPMTAG_FILEINODES,
|
|
|
|
RPMTAG_FILELANGS,
|
|
|
|
RPMTAG_BASENAMES,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
static int_32 requireTags[] = {
|
|
|
|
RPMTAG_REQUIRENAME, RPMTAG_REQUIREVERSION, RPMTAG_REQUIREFLAGS,
|
|
|
|
RPMTAG_PROVIDENAME, RPMTAG_PROVIDEVERSION, RPMTAG_PROVIDEFLAGS,
|
|
|
|
RPMTAG_CONFLICTNAME, RPMTAG_CONFLICTVERSION, RPMTAG_CONFLICTFLAGS
|
|
|
|
};
|
|
|
|
|
2001-02-06 06:22:43 +08:00
|
|
|
hge(h, RPMTAG_SIZE, NULL, (void **) &fileSizes, NULL);
|
2000-07-06 04:39:15 +08:00
|
|
|
fileSize = *fileSizes;
|
2001-02-06 06:22:43 +08:00
|
|
|
hge(newH, RPMTAG_FILESIZES, NULL, (void **) &fileSizes, &count);
|
2001-01-24 07:03:28 +08:00
|
|
|
for (i = 0, fc = 0; i < count; i++)
|
2000-07-06 04:39:15 +08:00
|
|
|
if (actions[i] != FA_SKIPMULTILIB) {
|
2001-01-24 07:03:28 +08:00
|
|
|
fc++;
|
2000-07-06 04:39:15 +08:00
|
|
|
fileSize += fileSizes[i];
|
|
|
|
}
|
|
|
|
headerModifyEntry(h, RPMTAG_SIZE, RPM_INT32_TYPE, &fileSize, 1);
|
2001-02-06 06:22:43 +08:00
|
|
|
|
2000-12-03 05:53:44 +08:00
|
|
|
for (i = 0; mergeTags[i]; i++) {
|
2001-02-06 06:22:43 +08:00
|
|
|
if (!hge(newH, mergeTags[i], &type, (void **) &data, &count))
|
2000-12-03 05:53:44 +08:00
|
|
|
continue;
|
|
|
|
switch (type) {
|
|
|
|
case RPM_CHAR_TYPE:
|
|
|
|
case RPM_INT8_TYPE:
|
2001-01-24 07:03:28 +08:00
|
|
|
newdata = xmalloc(fc * sizeof(int_8));
|
2000-12-03 05:53:44 +08:00
|
|
|
for (j = 0, k = 0; j < count; j++)
|
|
|
|
if (actions[j] != FA_SKIPMULTILIB)
|
2000-07-06 04:39:15 +08:00
|
|
|
((int_8 *) newdata)[k++] = ((int_8 *) data)[j];
|
2001-01-24 07:03:28 +08:00
|
|
|
headerAddOrAppendEntry(h, mergeTags[i], type, newdata, fc);
|
2000-12-03 05:53:44 +08:00
|
|
|
free (newdata);
|
|
|
|
break;
|
|
|
|
case RPM_INT16_TYPE:
|
2001-01-24 07:03:28 +08:00
|
|
|
newdata = xmalloc(fc * sizeof(int_16));
|
2000-12-03 05:53:44 +08:00
|
|
|
for (j = 0, k = 0; j < count; j++)
|
|
|
|
if (actions[j] != FA_SKIPMULTILIB)
|
|
|
|
((int_16 *) newdata)[k++] = ((int_16 *) data)[j];
|
2001-01-24 07:03:28 +08:00
|
|
|
headerAddOrAppendEntry(h, mergeTags[i], type, newdata, fc);
|
2000-12-03 05:53:44 +08:00
|
|
|
free (newdata);
|
|
|
|
break;
|
|
|
|
case RPM_INT32_TYPE:
|
2001-01-24 07:03:28 +08:00
|
|
|
newdata = xmalloc(fc * sizeof(int_32));
|
2000-12-03 05:53:44 +08:00
|
|
|
for (j = 0, k = 0; j < count; j++)
|
|
|
|
if (actions[j] != FA_SKIPMULTILIB)
|
|
|
|
((int_32 *) newdata)[k++] = ((int_32 *) data)[j];
|
2001-01-24 07:03:28 +08:00
|
|
|
headerAddOrAppendEntry(h, mergeTags[i], type, newdata, fc);
|
2000-12-03 05:53:44 +08:00
|
|
|
free (newdata);
|
|
|
|
break;
|
|
|
|
case RPM_STRING_ARRAY_TYPE:
|
2001-01-24 07:03:28 +08:00
|
|
|
newdata = xmalloc(fc * sizeof(char *));
|
2000-12-03 05:53:44 +08:00
|
|
|
for (j = 0, k = 0; j < count; j++)
|
|
|
|
if (actions[j] != FA_SKIPMULTILIB)
|
|
|
|
((char **) newdata)[k++] = ((char **) data)[j];
|
2001-01-24 07:03:28 +08:00
|
|
|
headerAddOrAppendEntry(h, mergeTags[i], type, newdata, fc);
|
2000-12-03 05:53:44 +08:00
|
|
|
free (newdata);
|
|
|
|
break;
|
|
|
|
default:
|
2001-01-04 04:19:27 +08:00
|
|
|
rpmError(RPMERR_DATATYPE, _("Data type %d not supported\n"),
|
|
|
|
(int) type);
|
|
|
|
return 1;
|
|
|
|
/*@notreached@*/ break;
|
2000-12-03 05:53:44 +08:00
|
|
|
}
|
2001-02-06 06:22:43 +08:00
|
|
|
data = hfd(data, type);
|
2000-12-03 05:53:44 +08:00
|
|
|
}
|
2001-02-06 06:22:43 +08:00
|
|
|
hge(newH, RPMTAG_DIRINDEXES, NULL, (void **) &newDirIndexes, &count);
|
|
|
|
hge(newH, RPMTAG_DIRNAMES, NULL, (void **) &newDirNames, NULL);
|
|
|
|
hge(h, RPMTAG_DIRINDEXES, NULL, (void **) &dirIndexes, NULL);
|
|
|
|
hge(h, RPMTAG_DIRNAMES, NULL, (void **) &data, &dirNamesCount);
|
2000-07-06 04:39:15 +08:00
|
|
|
|
2001-01-24 07:03:28 +08:00
|
|
|
dirNames = xcalloc(dirNamesCount + fc, sizeof(char *));
|
2000-07-06 04:39:15 +08:00
|
|
|
for (i = 0; i < dirNamesCount; i++)
|
|
|
|
dirNames[i] = ((char **) data)[i];
|
|
|
|
dirCount = dirNamesCount;
|
2001-01-24 07:03:28 +08:00
|
|
|
newdata = xmalloc(fc * sizeof(int_32));
|
2000-12-03 05:53:44 +08:00
|
|
|
for (i = 0, k = 0; i < count; i++) {
|
|
|
|
if (actions[i] == FA_SKIPMULTILIB)
|
|
|
|
continue;
|
|
|
|
for (j = 0; j < dirCount; j++)
|
|
|
|
if (!strcmp(dirNames[j], newDirNames[newDirIndexes[i]]))
|
|
|
|
break;
|
|
|
|
if (j == dirCount)
|
|
|
|
dirNames[dirCount++] = newDirNames[newDirIndexes[i]];
|
|
|
|
((int_32 *) newdata)[k++] = j;
|
|
|
|
}
|
2001-01-24 07:03:28 +08:00
|
|
|
headerAddOrAppendEntry(h, RPMTAG_DIRINDEXES, RPM_INT32_TYPE, newdata, fc);
|
2000-07-06 04:39:15 +08:00
|
|
|
if (dirCount > dirNamesCount)
|
|
|
|
headerAddOrAppendEntry(h, RPMTAG_DIRNAMES, RPM_STRING_ARRAY_TYPE,
|
|
|
|
dirNames + dirNamesCount,
|
|
|
|
dirCount - dirNamesCount);
|
2001-02-06 06:22:43 +08:00
|
|
|
data = hfd(data, -1);
|
|
|
|
newDirNames = hfd(newDirNames, -1);
|
2000-07-06 04:39:15 +08:00
|
|
|
free (newdata);
|
|
|
|
free (dirNames);
|
|
|
|
|
|
|
|
for (i = 0; i < 9; i += 3) {
|
2001-01-27 01:06:09 +08:00
|
|
|
const char **Names, **EVR, **newNames, **newEVR;
|
2001-02-06 06:22:43 +08:00
|
|
|
int nnt, nvt, rnt;
|
2000-07-06 04:39:15 +08:00
|
|
|
uint_32 *Flags, *newFlags;
|
|
|
|
int Count = 0, newCount = 0;
|
|
|
|
|
2001-02-06 06:22:43 +08:00
|
|
|
if (!hge(newH, requireTags[i], &nnt, (void **) &newNames, &newCount))
|
2000-12-03 05:53:44 +08:00
|
|
|
continue;
|
|
|
|
|
2001-02-06 06:22:43 +08:00
|
|
|
hge(newH, requireTags[i+1], &nvt, (void **) &newEVR, NULL);
|
|
|
|
hge(newH, requireTags[i+2], NULL, (void **) &newFlags, NULL);
|
|
|
|
if (hge(h, requireTags[i], &rnt, (void **) &Names, &Count))
|
2000-12-03 05:53:44 +08:00
|
|
|
{
|
2001-02-06 06:22:43 +08:00
|
|
|
hge(h, requireTags[i+1], NULL, (void **) &EVR, NULL);
|
|
|
|
hge(h, requireTags[i+2], NULL, (void **) &Flags, NULL);
|
2000-12-03 05:53:44 +08:00
|
|
|
for (j = 0; j < newCount; j++)
|
|
|
|
for (k = 0; k < Count; k++)
|
|
|
|
if (!strcmp (newNames[j], Names[k])
|
|
|
|
&& !strcmp (newEVR[j], EVR[k])
|
|
|
|
&& (newFlags[j] & RPMSENSE_SENSEMASK) ==
|
|
|
|
(Flags[k] & RPMSENSE_SENSEMASK))
|
|
|
|
{
|
|
|
|
newNames[j] = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (j = 0, k = 0; j < newCount; j++) {
|
|
|
|
if (!newNames[j] || !isDependsMULTILIB(newFlags[j]))
|
|
|
|
continue;
|
|
|
|
if (j != k) {
|
|
|
|
newNames[k] = newNames[j];
|
|
|
|
newEVR[k] = newEVR[j];
|
|
|
|
newFlags[k] = newFlags[j];
|
2000-07-06 04:39:15 +08:00
|
|
|
}
|
2000-12-03 05:53:44 +08:00
|
|
|
k++;
|
|
|
|
}
|
|
|
|
if (k) {
|
|
|
|
headerAddOrAppendEntry(h, requireTags[i],
|
2000-07-06 04:39:15 +08:00
|
|
|
RPM_STRING_ARRAY_TYPE, newNames, k);
|
2000-12-03 05:53:44 +08:00
|
|
|
headerAddOrAppendEntry(h, requireTags[i+1],
|
2000-07-06 04:39:15 +08:00
|
|
|
RPM_STRING_ARRAY_TYPE, newEVR, k);
|
2000-12-03 05:53:44 +08:00
|
|
|
headerAddOrAppendEntry(h, requireTags[i+2], RPM_INT32_TYPE,
|
2000-07-06 04:39:15 +08:00
|
|
|
newFlags, k);
|
|
|
|
}
|
2001-02-06 06:22:43 +08:00
|
|
|
newNames = hfd(newNames, nnt);
|
|
|
|
newEVR = hfd(newEVR, nvt);
|
|
|
|
Names = hfd(Names, rnt);
|
2000-07-06 04:39:15 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-10-24 21:46:51 +08:00
|
|
|
/**
|
2001-01-22 07:48:09 +08:00
|
|
|
* Mark files in database shared with this package as "replaced".
|
2001-03-03 00:17:03 +08:00
|
|
|
* @param psm package state machine data
|
2000-10-24 21:46:51 +08:00
|
|
|
* @return 0 always
|
|
|
|
*/
|
2001-03-03 00:17:03 +08:00
|
|
|
static int markReplacedFiles(PSM_t psm)
|
1999-07-14 06:53:46 +08:00
|
|
|
{
|
2001-03-03 00:17:03 +08:00
|
|
|
const rpmTransactionSet ts = psm->ts;
|
|
|
|
TFI_t fi = psm->fi;
|
2001-02-06 06:22:43 +08:00
|
|
|
HGE_t hge = (HGE_t)fi->hge;
|
2001-01-22 07:48:09 +08:00
|
|
|
const struct sharedFileInfo * replaced = fi->replaced;
|
|
|
|
const struct sharedFileInfo * sfi;
|
2000-04-27 20:50:54 +08:00
|
|
|
rpmdbMatchIterator mi;
|
|
|
|
Header h;
|
|
|
|
unsigned int * offsets;
|
2000-07-16 00:00:14 +08:00
|
|
|
unsigned int prev;
|
2000-04-27 20:50:54 +08:00
|
|
|
int num;
|
|
|
|
|
2001-01-22 07:48:09 +08:00
|
|
|
if (!(fi->fc > 0 && fi->replaced))
|
|
|
|
return 0;
|
|
|
|
|
2000-07-16 00:00:14 +08:00
|
|
|
num = prev = 0;
|
2001-01-22 07:48:09 +08:00
|
|
|
for (sfi = replaced; sfi->otherPkg; sfi++) {
|
|
|
|
if (prev && prev == sfi->otherPkg)
|
2000-07-16 00:00:14 +08:00
|
|
|
continue;
|
2001-01-22 07:48:09 +08:00
|
|
|
prev = sfi->otherPkg;
|
2000-04-27 20:50:54 +08:00
|
|
|
num++;
|
2000-07-16 00:00:14 +08:00
|
|
|
}
|
2000-07-16 02:15:23 +08:00
|
|
|
if (num == 0)
|
|
|
|
return 0;
|
2000-07-16 00:00:14 +08:00
|
|
|
|
2000-04-27 20:50:54 +08:00
|
|
|
offsets = alloca(num * sizeof(*offsets));
|
2000-07-16 00:00:14 +08:00
|
|
|
num = prev = 0;
|
2001-01-22 07:48:09 +08:00
|
|
|
for (sfi = replaced; sfi->otherPkg; sfi++) {
|
|
|
|
if (prev && prev == sfi->otherPkg)
|
2000-07-16 00:00:14 +08:00
|
|
|
continue;
|
2001-01-22 07:48:09 +08:00
|
|
|
prev = sfi->otherPkg;
|
|
|
|
offsets[num++] = sfi->otherPkg;
|
2000-07-16 00:00:14 +08:00
|
|
|
}
|
2000-04-27 20:50:54 +08:00
|
|
|
|
2001-03-03 00:17:03 +08:00
|
|
|
mi = rpmdbInitIterator(ts->rpmdb, RPMDBI_PACKAGES, NULL, 0);
|
2000-05-07 08:53:11 +08:00
|
|
|
rpmdbAppendIterator(mi, offsets, num);
|
2000-04-27 20:50:54 +08:00
|
|
|
|
2001-01-22 07:48:09 +08:00
|
|
|
sfi = replaced;
|
2000-04-27 20:50:54 +08:00
|
|
|
while ((h = rpmdbNextIterator(mi)) != NULL) {
|
|
|
|
char * secStates;
|
|
|
|
int modified;
|
|
|
|
int count;
|
|
|
|
|
|
|
|
modified = 0;
|
2000-07-17 08:40:17 +08:00
|
|
|
|
2001-02-06 06:22:43 +08:00
|
|
|
if (!hge(h, RPMTAG_FILESTATES, NULL, (void **)&secStates, &count))
|
2000-07-17 08:40:17 +08:00
|
|
|
continue;
|
|
|
|
|
2000-07-16 00:00:14 +08:00
|
|
|
prev = rpmdbGetIteratorOffset(mi);
|
2000-07-16 02:15:23 +08:00
|
|
|
num = 0;
|
2001-01-22 07:48:09 +08:00
|
|
|
while (sfi->otherPkg && sfi->otherPkg == prev) {
|
|
|
|
assert(sfi->otherFileNum < count);
|
|
|
|
if (secStates[sfi->otherFileNum] != RPMFILE_STATE_REPLACED) {
|
|
|
|
secStates[sfi->otherFileNum] = RPMFILE_STATE_REPLACED;
|
2000-07-17 08:40:17 +08:00
|
|
|
if (modified == 0) {
|
|
|
|
/* Modified header will be rewritten. */
|
|
|
|
modified = 1;
|
|
|
|
rpmdbSetIteratorModified(mi, modified);
|
|
|
|
}
|
2000-07-16 02:15:23 +08:00
|
|
|
num++;
|
|
|
|
}
|
2001-01-22 07:48:09 +08:00
|
|
|
sfi++;
|
1999-07-14 06:53:46 +08:00
|
|
|
}
|
1997-07-16 09:44:27 +08:00
|
|
|
}
|
2000-04-27 20:50:54 +08:00
|
|
|
rpmdbFreeIterator(mi);
|
1997-07-16 09:44:27 +08:00
|
|
|
|
1999-07-14 06:53:46 +08:00
|
|
|
return 0;
|
|
|
|
}
|
1998-01-29 00:49:43 +08:00
|
|
|
|
2000-08-23 21:02:13 +08:00
|
|
|
/**
|
2000-10-24 21:46:51 +08:00
|
|
|
* Setup payload map and install payload archive.
|
2000-11-17 06:55:10 +08:00
|
|
|
*
|
2001-01-25 20:58:03 +08:00
|
|
|
* @todo Add endian tag so that srpm MD5 sums can be verified when installed.
|
2000-11-17 06:55:10 +08:00
|
|
|
*
|
2001-03-02 01:04:27 +08:00
|
|
|
* @param psm package state machine data
|
2001-01-25 20:58:03 +08:00
|
|
|
* @param allFiles install all files?
|
2000-10-24 21:46:51 +08:00
|
|
|
* @return 0 on success
|
2000-08-23 21:02:13 +08:00
|
|
|
*/
|
2001-03-02 00:01:16 +08:00
|
|
|
static int installArchive(PSM_t psm, int allFiles)
|
1999-07-14 06:53:46 +08:00
|
|
|
{
|
2001-03-02 00:01:16 +08:00
|
|
|
const rpmTransactionSet ts = psm->ts;
|
|
|
|
TFI_t fi = psm->fi;
|
2001-01-22 07:48:09 +08:00
|
|
|
int rc;
|
1999-07-14 06:53:46 +08:00
|
|
|
|
2001-01-25 20:58:03 +08:00
|
|
|
if (allFiles) {
|
1999-07-14 06:53:46 +08:00
|
|
|
/* install all files */
|
2001-01-24 07:03:28 +08:00
|
|
|
} else if (fi->fc == 0) {
|
1999-07-14 06:53:46 +08:00
|
|
|
/* no files to install */
|
1996-01-15 03:32:17 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-03-02 16:28:18 +08:00
|
|
|
rc = psmStage(psm, PSM_PROCESS);
|
2001-03-02 23:03:29 +08:00
|
|
|
|
2001-03-02 01:04:27 +08:00
|
|
|
if (!rc)
|
2001-03-02 23:03:29 +08:00
|
|
|
rc = psmStage(psm, PSM_COMMIT);
|
1996-01-30 03:37:59 +08:00
|
|
|
|
1999-07-14 06:53:46 +08:00
|
|
|
if (rc) {
|
2001-01-24 23:58:35 +08:00
|
|
|
/*
|
|
|
|
* This would probably be a good place to check if disk space
|
|
|
|
* was used up - if so, we should return a different error.
|
|
|
|
*/
|
2001-01-16 07:09:42 +08:00
|
|
|
rpmError(RPMERR_CPIO, _("unpacking of archive failed%s%s: %s\n"),
|
2001-03-02 00:01:16 +08:00
|
|
|
(psm->failedFile != NULL ? _(" on file ") : ""),
|
|
|
|
(psm->failedFile != NULL ? psm->failedFile : ""),
|
1999-07-14 06:53:46 +08:00
|
|
|
cpioStrerror(rc));
|
1999-09-18 06:59:31 +08:00
|
|
|
rc = 1;
|
2001-01-30 06:53:48 +08:00
|
|
|
} else {
|
|
|
|
if (ts && ts->notify) {
|
|
|
|
unsigned int archiveSize = (fi->archiveSize ? fi->archiveSize : 100);
|
|
|
|
(void)ts->notify(fi->h, RPMCALLBACK_INST_PROGRESS,
|
|
|
|
archiveSize, archiveSize,
|
|
|
|
(fi->ap ? fi->ap->key : NULL), ts->notifyData);
|
|
|
|
}
|
1997-05-06 23:27:46 +08:00
|
|
|
}
|
1996-01-23 05:13:12 +08:00
|
|
|
|
1999-09-18 06:59:31 +08:00
|
|
|
return rc;
|
1996-01-09 03:31:44 +08:00
|
|
|
}
|
1996-01-15 03:32:17 +08:00
|
|
|
|
2001-02-13 03:02:15 +08:00
|
|
|
/**
|
|
|
|
*/
|
2001-02-28 21:59:29 +08:00
|
|
|
static rpmRC chkdir (const char * dpath, const char * dname)
|
2001-01-24 00:07:28 +08:00
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if ((rc = Stat(dpath, &st)) < 0) {
|
|
|
|
int ut = urlPath(dpath, NULL);
|
|
|
|
switch (ut) {
|
|
|
|
case URL_IS_PATH:
|
|
|
|
case URL_IS_UNKNOWN:
|
|
|
|
if (errno != ENOENT)
|
|
|
|
break;
|
|
|
|
/*@fallthrough@*/
|
|
|
|
case URL_IS_FTP:
|
|
|
|
case URL_IS_HTTP:
|
|
|
|
/* XXX this will only create last component of directory path */
|
|
|
|
rc = Mkdir(dpath, 0755);
|
|
|
|
break;
|
|
|
|
case URL_IS_DASH:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (rc < 0) {
|
|
|
|
rpmError(RPMERR_CREATE, _("cannot create %s %s\n"),
|
|
|
|
dname, dpath);
|
2001-02-13 03:02:15 +08:00
|
|
|
return RPMRC_FAIL;
|
2001-01-24 00:07:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((rc = Access(dpath, W_OK))) {
|
|
|
|
rpmError(RPMERR_CREATE, _("cannot write to %s\n"), dpath);
|
2001-02-13 03:02:15 +08:00
|
|
|
return RPMRC_FAIL;
|
2001-01-24 00:07:28 +08:00
|
|
|
}
|
2001-02-13 03:02:15 +08:00
|
|
|
return RPMRC_OK;
|
2001-01-24 00:07:28 +08:00
|
|
|
}
|
2001-01-25 20:58:03 +08:00
|
|
|
|
2000-08-23 21:02:13 +08:00
|
|
|
/**
|
2001-01-25 20:58:03 +08:00
|
|
|
* @param ts transaction set
|
|
|
|
* @param fi transaction element file info
|
2000-10-24 21:46:51 +08:00
|
|
|
* @retval specFilePtr address of spec file name
|
2001-02-13 03:02:15 +08:00
|
|
|
* @return rpmRC return code
|
2000-08-23 21:02:13 +08:00
|
|
|
*/
|
2001-02-13 03:02:15 +08:00
|
|
|
static rpmRC installSources(const rpmTransactionSet ts, TFI_t fi,
|
2001-01-25 20:58:03 +08:00
|
|
|
/*@out@*/ const char ** specFilePtr)
|
1999-07-14 06:53:46 +08:00
|
|
|
{
|
2001-02-13 03:02:15 +08:00
|
|
|
HFD_t hfd = fi->hfd;
|
2001-01-25 20:58:03 +08:00
|
|
|
const char * _sourcedir = rpmGenPath(ts->rootDir, "%{_sourcedir}", "");
|
|
|
|
const char * _specdir = rpmGenPath(ts->rootDir, "%{_specdir}", "");
|
1999-09-18 06:01:34 +08:00
|
|
|
const char * specFile = NULL;
|
2001-02-13 03:02:15 +08:00
|
|
|
rpmRC rc = RPMRC_OK;
|
2001-01-24 23:58:35 +08:00
|
|
|
int i;
|
1996-02-15 01:54:37 +08:00
|
|
|
|
1998-09-28 06:03:52 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, _("installing a source package\n"));
|
1996-02-15 04:09:14 +08:00
|
|
|
|
2001-01-24 00:07:28 +08:00
|
|
|
rc = chkdir(_sourcedir, "sourcedir");
|
|
|
|
if (rc) {
|
2001-02-13 03:02:15 +08:00
|
|
|
rc = RPMRC_FAIL;
|
1999-01-06 07:13:56 +08:00
|
|
|
goto exit;
|
1997-02-12 13:05:13 +08:00
|
|
|
}
|
|
|
|
|
2001-01-24 00:07:28 +08:00
|
|
|
rc = chkdir(_specdir, "specdir");
|
|
|
|
if (rc) {
|
2001-02-13 03:02:15 +08:00
|
|
|
rc = RPMRC_FAIL;
|
1999-01-06 07:13:56 +08:00
|
|
|
goto exit;
|
1997-02-12 13:05:13 +08:00
|
|
|
}
|
1996-02-15 01:54:37 +08:00
|
|
|
|
2001-01-24 07:03:28 +08:00
|
|
|
i = fi->fc;
|
2001-01-25 20:58:03 +08:00
|
|
|
if (headerIsEntry(fi->h, RPMTAG_COOKIE))
|
2001-01-24 23:58:35 +08:00
|
|
|
for (i = 0; i < fi->fc; i++)
|
|
|
|
if (fi->fflags[i] & RPMFILE_SPECFILE) break;
|
1997-10-29 23:53:35 +08:00
|
|
|
|
2001-01-24 07:03:28 +08:00
|
|
|
if (i == fi->fc) {
|
2001-02-02 23:04:44 +08:00
|
|
|
/* Find the spec file by name. */
|
2001-01-24 23:58:35 +08:00
|
|
|
for (i = 0; i < fi->fc; i++) {
|
2001-01-24 07:03:28 +08:00
|
|
|
const char * t = fi->apath[i];
|
|
|
|
t += strlen(fi->apath[i]) - 5;
|
|
|
|
if (!strcmp(t, ".spec")) break;
|
1997-05-07 02:19:19 +08:00
|
|
|
}
|
2001-01-24 00:07:28 +08:00
|
|
|
}
|
1997-05-07 02:19:19 +08:00
|
|
|
|
2001-01-26 04:26:35 +08:00
|
|
|
/* Build dnl/dil with {_sourcedir, _specdir} as values. */
|
2001-01-24 07:03:28 +08:00
|
|
|
if (i < fi->fc) {
|
2001-01-26 04:26:35 +08:00
|
|
|
int speclen = strlen(_specdir) + 2;
|
|
|
|
int sourcelen = strlen(_sourcedir) + 2;
|
|
|
|
char * t;
|
|
|
|
|
2001-02-13 03:02:15 +08:00
|
|
|
fi->dnl = hfd(fi->dnl, -1);
|
2001-01-26 04:26:35 +08:00
|
|
|
|
|
|
|
fi->dc = 2;
|
|
|
|
fi->dnl = xmalloc(fi->dc * sizeof(*fi->dnl) + fi->fc * sizeof(*fi->dil) +
|
|
|
|
speclen + sourcelen);
|
|
|
|
fi->dil = (int *)(fi->dnl + fi->dc);
|
|
|
|
memset(fi->dil, 0, fi->fc * sizeof(*fi->dil));
|
|
|
|
fi->dil[i] = 1;
|
|
|
|
fi->dnl[0] = t = (char *)(fi->dil + fi->fc);
|
|
|
|
fi->dnl[1] = t = stpcpy( stpcpy(t, _sourcedir), "/") + 1;
|
|
|
|
(void) stpcpy( stpcpy(t, _specdir), "/");
|
|
|
|
|
|
|
|
t = xmalloc(speclen + strlen(fi->bnl[i]) + 1);
|
|
|
|
(void) stpcpy( stpcpy( stpcpy(t, _specdir), "/"), fi->bnl[i]);
|
|
|
|
specFile = t;
|
2001-01-24 00:07:28 +08:00
|
|
|
} else {
|
|
|
|
rpmError(RPMERR_NOSPEC, _("source package contains no .spec file\n"));
|
|
|
|
rc = 2;
|
|
|
|
goto exit;
|
1997-05-07 02:19:19 +08:00
|
|
|
}
|
1996-07-26 00:39:01 +08:00
|
|
|
|
2001-03-02 00:01:16 +08:00
|
|
|
{ struct psm_s psmbuf;
|
|
|
|
PSM_t psm = &psmbuf;
|
|
|
|
memset(psm, 0, sizeof(*psm));
|
|
|
|
psm->ts = ts;
|
|
|
|
psm->fi = fi;
|
|
|
|
|
|
|
|
rc = installArchive(psm, 1);
|
2001-03-02 23:03:29 +08:00
|
|
|
|
|
|
|
(void) psmStage(psm, PSM_FINI);
|
2001-03-02 00:01:16 +08:00
|
|
|
}
|
2001-01-22 07:48:09 +08:00
|
|
|
|
2001-01-26 04:26:35 +08:00
|
|
|
if (rc) {
|
2001-02-13 03:02:15 +08:00
|
|
|
rc = RPMRC_FAIL;
|
2001-01-26 04:26:35 +08:00
|
|
|
goto exit;
|
1997-05-07 02:19:19 +08:00
|
|
|
}
|
1996-02-15 04:09:14 +08:00
|
|
|
|
1999-01-06 07:13:56 +08:00
|
|
|
exit:
|
2001-02-13 03:02:15 +08:00
|
|
|
if (rc == RPMRC_OK && specFile && specFilePtr)
|
2001-01-26 04:26:35 +08:00
|
|
|
*specFilePtr = specFile;
|
|
|
|
else
|
2001-02-13 03:02:15 +08:00
|
|
|
specFile = _free(specFile);
|
|
|
|
_specdir = _free(_specdir);
|
|
|
|
_sourcedir = _free(_sourcedir);
|
1999-01-06 07:13:56 +08:00
|
|
|
return rc;
|
1996-02-15 01:54:37 +08:00
|
|
|
}
|
1996-02-16 05:08:48 +08:00
|
|
|
|
1999-07-14 06:53:46 +08:00
|
|
|
int rpmVersionCompare(Header first, Header second)
|
|
|
|
{
|
2000-02-17 03:10:42 +08:00
|
|
|
const char * one, * two;
|
1999-07-14 06:53:46 +08:00
|
|
|
int_32 * epochOne, * epochTwo;
|
|
|
|
int rc;
|
1996-02-16 05:08:48 +08:00
|
|
|
|
1999-07-14 06:53:46 +08:00
|
|
|
if (!headerGetEntry(first, RPMTAG_EPOCH, NULL, (void **) &epochOne, NULL))
|
|
|
|
epochOne = NULL;
|
1999-11-30 22:49:45 +08:00
|
|
|
if (!headerGetEntry(second, RPMTAG_EPOCH, NULL, (void **) &epochTwo,
|
1999-07-14 06:53:46 +08:00
|
|
|
NULL))
|
|
|
|
epochTwo = NULL;
|
1997-01-16 00:24:14 +08:00
|
|
|
|
1999-11-30 22:49:45 +08:00
|
|
|
if (epochOne && !epochTwo)
|
1997-01-16 00:24:14 +08:00
|
|
|
return 1;
|
1999-11-30 22:49:45 +08:00
|
|
|
else if (!epochOne && epochTwo)
|
1997-07-24 22:41:55 +08:00
|
|
|
return -1;
|
1998-08-19 10:30:02 +08:00
|
|
|
else if (epochOne && epochTwo) {
|
|
|
|
if (*epochOne < *epochTwo)
|
1997-10-15 23:44:57 +08:00
|
|
|
return -1;
|
1998-08-19 10:30:02 +08:00
|
|
|
else if (*epochOne > *epochTwo)
|
1997-10-15 23:44:57 +08:00
|
|
|
return 1;
|
|
|
|
}
|
1999-11-30 22:49:45 +08:00
|
|
|
|
1997-01-16 00:24:14 +08:00
|
|
|
headerGetEntry(first, RPMTAG_VERSION, NULL, (void **) &one, NULL);
|
1997-01-17 00:18:48 +08:00
|
|
|
headerGetEntry(second, RPMTAG_VERSION, NULL, (void **) &two, NULL);
|
1996-02-26 06:11:00 +08:00
|
|
|
|
1997-01-16 00:24:14 +08:00
|
|
|
rc = rpmvercmp(one, two);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
headerGetEntry(first, RPMTAG_RELEASE, NULL, (void **) &one, NULL);
|
1997-01-17 00:18:48 +08:00
|
|
|
headerGetEntry(second, RPMTAG_RELEASE, NULL, (void **) &two, NULL);
|
1999-11-30 22:49:45 +08:00
|
|
|
|
1997-01-16 00:24:14 +08:00
|
|
|
return rpmvercmp(one, two);
|
|
|
|
}
|
|
|
|
|
2001-02-13 03:02:15 +08:00
|
|
|
rpmRC rpmInstallSourcePackage(const char * rootDir, FD_t fd,
|
2000-08-30 06:04:33 +08:00
|
|
|
const char ** specFile,
|
|
|
|
rpmCallbackFunction notify, rpmCallbackData notifyData,
|
|
|
|
char ** cookie)
|
1999-07-14 06:53:46 +08:00
|
|
|
{
|
2001-01-25 20:58:03 +08:00
|
|
|
rpmdb rpmdb = NULL;
|
|
|
|
rpmTransactionSet ts = rpmtransCreateSet(rpmdb, rootDir);
|
|
|
|
TFI_t fi = xcalloc(sizeof(*fi), 1);
|
|
|
|
int isSource;
|
1999-07-14 06:53:46 +08:00
|
|
|
Header h;
|
|
|
|
int major, minor;
|
2001-02-13 03:02:15 +08:00
|
|
|
rpmRC rc;
|
2001-01-25 20:58:03 +08:00
|
|
|
int i;
|
|
|
|
|
|
|
|
ts->notify = notify;
|
|
|
|
ts->notifyData = notifyData;
|
1999-07-14 06:53:46 +08:00
|
|
|
|
|
|
|
rc = rpmReadPackageHeader(fd, &h, &isSource, &major, &minor);
|
2001-01-25 20:58:03 +08:00
|
|
|
if (rc)
|
|
|
|
goto exit;
|
1999-07-14 06:53:46 +08:00
|
|
|
|
|
|
|
if (!isSource) {
|
2001-01-16 07:09:42 +08:00
|
|
|
rpmError(RPMERR_NOTSRPM, _("source package expected, binary found\n"));
|
2001-02-13 03:02:15 +08:00
|
|
|
rc = RPMRC_FAIL;
|
2001-01-25 20:58:03 +08:00
|
|
|
goto exit;
|
1999-07-14 06:53:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cookie) {
|
|
|
|
*cookie = NULL;
|
2001-01-25 20:58:03 +08:00
|
|
|
if (headerGetEntry(h, RPMTAG_COOKIE, NULL, (void **) cookie, NULL))
|
1999-09-21 11:22:53 +08:00
|
|
|
*cookie = xstrdup(*cookie);
|
1999-07-14 06:53:46 +08:00
|
|
|
}
|
|
|
|
|
2001-02-13 03:02:15 +08:00
|
|
|
(void) rpmtransAddPackage(ts, h, fd, NULL, 0, NULL);
|
1999-11-30 22:49:45 +08:00
|
|
|
|
2001-01-25 20:58:03 +08:00
|
|
|
fi->type = TR_ADDED;
|
|
|
|
fi->ap = ts->addedPackages.list;
|
|
|
|
loadFi(h, fi);
|
2001-02-05 06:15:30 +08:00
|
|
|
headerFree(h); /* XXX reference held by transaction set */
|
|
|
|
|
2001-01-25 20:58:03 +08:00
|
|
|
if (fi->fmd5s) { /* DYING */
|
|
|
|
free((void **)fi->fmd5s); fi->fmd5s = NULL;
|
|
|
|
}
|
|
|
|
if (fi->fmapflags) { /* DYING */
|
|
|
|
free((void **)fi->fmapflags); fi->fmapflags = NULL;
|
|
|
|
}
|
|
|
|
fi->uid = getuid();
|
|
|
|
fi->gid = getgid();
|
2001-02-04 04:07:39 +08:00
|
|
|
fi->astriplen = 0;
|
2001-01-25 20:58:03 +08:00
|
|
|
fi->striplen = 0;
|
|
|
|
fi->mapflags = CPIO_MAP_PATH | CPIO_MAP_MODE | CPIO_MAP_UID | CPIO_MAP_GID;
|
1999-11-30 22:49:45 +08:00
|
|
|
|
2001-01-25 20:58:03 +08:00
|
|
|
fi->fuids = xcalloc(sizeof(*fi->fuids), fi->fc);
|
|
|
|
fi->fgids = xcalloc(sizeof(*fi->fgids), fi->fc);
|
|
|
|
for (i = 0; i < fi->fc; i++) {
|
|
|
|
fi->fuids[i] = fi->uid;
|
|
|
|
fi->fgids[i] = fi->gid;
|
|
|
|
}
|
|
|
|
|
2001-02-02 23:04:44 +08:00
|
|
|
for (i = 0; i < fi->fc; i++) {
|
|
|
|
fi->actions[i] = FA_CREATE;
|
|
|
|
}
|
|
|
|
|
2001-01-25 20:58:03 +08:00
|
|
|
rpmBuildFileList(fi->h, &fi->apath, NULL);
|
|
|
|
|
2001-02-06 06:22:43 +08:00
|
|
|
rpmInstallLoadMacros(fi, fi->h);
|
2001-01-25 20:58:03 +08:00
|
|
|
|
|
|
|
rc = installSources(ts, fi, specFile);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
if (fi) {
|
|
|
|
freeFi(fi);
|
|
|
|
free(fi);
|
|
|
|
}
|
|
|
|
if (ts)
|
|
|
|
rpmtransFree(ts);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2001-02-28 23:49:23 +08:00
|
|
|
static char * SCRIPT_PATH = "PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return scriptlet name from tag.
|
|
|
|
* @param tag scriptlet tag
|
|
|
|
* @return name of scriptlet
|
|
|
|
*/
|
|
|
|
static /*@observer@*/ const char * const tag2sln(int tag)
|
|
|
|
{
|
|
|
|
switch (tag) {
|
|
|
|
case RPMTAG_PREIN: return "%pre";
|
|
|
|
case RPMTAG_POSTIN: return "%post";
|
|
|
|
case RPMTAG_PREUN: return "%preun";
|
|
|
|
case RPMTAG_POSTUN: return "%postun";
|
|
|
|
case RPMTAG_VERIFYSCRIPT: return "%verify";
|
|
|
|
}
|
|
|
|
return "%unknownscript";
|
|
|
|
}
|
|
|
|
|
2001-02-13 00:33:08 +08:00
|
|
|
/**
|
2001-02-28 23:49:23 +08:00
|
|
|
* Run scriptlet with args.
|
|
|
|
*
|
|
|
|
* Run a script with an interpreter. If the interpreter is not specified,
|
|
|
|
* /bin/sh will be used. If the interpreter is /bin/sh, then the args from
|
|
|
|
* the header will be ignored, passing instead arg1 and arg2.
|
|
|
|
*
|
2001-02-28 07:12:30 +08:00
|
|
|
* @param psm package state machine data
|
2001-02-28 23:49:23 +08:00
|
|
|
* @param h header
|
|
|
|
* @param sln name of scriptlet section
|
|
|
|
* @param progArgc no. of args from header
|
|
|
|
* @param progArgv args from header, progArgv[0] is the interpreter to use
|
|
|
|
* @param script scriptlet from header
|
|
|
|
* @param arg1 no. instances of package installed after scriptlet exec
|
|
|
|
* (-1 is no arg)
|
|
|
|
* @param arg2 ditto, but for the target package
|
|
|
|
* @return 0 on success, 1 on error
|
2001-02-13 00:33:08 +08:00
|
|
|
*/
|
2001-02-28 23:49:23 +08:00
|
|
|
static int runScript(PSM_t psm, Header h,
|
|
|
|
const char * sln,
|
|
|
|
int progArgc, const char ** progArgv,
|
|
|
|
const char * script, int arg1, int arg2)
|
2001-02-13 00:33:08 +08:00
|
|
|
{
|
2001-02-28 07:12:30 +08:00
|
|
|
const rpmTransactionSet ts = psm->ts;
|
|
|
|
TFI_t fi = psm->fi;
|
2001-02-28 23:49:23 +08:00
|
|
|
HGE_t hge = fi->hge;
|
|
|
|
HFD_t hfd = fi->hfd;
|
|
|
|
const char ** argv = NULL;
|
|
|
|
int argc = 0;
|
|
|
|
const char ** prefixes = NULL;
|
|
|
|
int numPrefixes;
|
|
|
|
int_32 ipt;
|
|
|
|
const char * oldPrefix;
|
|
|
|
int maxPrefixLength;
|
|
|
|
int len;
|
|
|
|
char * prefixBuf = NULL;
|
|
|
|
pid_t child;
|
|
|
|
int status = 0;
|
|
|
|
const char * fn = NULL;
|
|
|
|
int i;
|
|
|
|
int freePrefixes = 0;
|
|
|
|
FD_t out;
|
2001-02-13 00:33:08 +08:00
|
|
|
int rc = 0;
|
2001-02-28 23:49:23 +08:00
|
|
|
const char *n, *v, *r;
|
2001-02-13 00:33:08 +08:00
|
|
|
|
2001-02-28 23:49:23 +08:00
|
|
|
if (!progArgv && !script)
|
|
|
|
return 0;
|
2001-02-13 00:33:08 +08:00
|
|
|
|
2001-02-28 23:49:23 +08:00
|
|
|
if (!progArgv) {
|
|
|
|
argv = alloca(5 * sizeof(char *));
|
|
|
|
argv[0] = "/bin/sh";
|
|
|
|
argc = 1;
|
|
|
|
} else {
|
|
|
|
argv = alloca((progArgc + 4) * sizeof(char *));
|
|
|
|
memcpy(argv, progArgv, progArgc * sizeof(char *));
|
|
|
|
argc = progArgc;
|
|
|
|
}
|
|
|
|
|
|
|
|
headerNVR(h, &n, &v, &r);
|
|
|
|
if (hge(h, RPMTAG_INSTPREFIXES, &ipt, (void **) &prefixes, &numPrefixes)) {
|
|
|
|
freePrefixes = 1;
|
|
|
|
} else if (hge(h, RPMTAG_INSTALLPREFIX, NULL, (void **) &oldPrefix, NULL)) {
|
|
|
|
prefixes = &oldPrefix;
|
|
|
|
numPrefixes = 1;
|
|
|
|
} else {
|
|
|
|
numPrefixes = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
maxPrefixLength = 0;
|
|
|
|
for (i = 0; i < numPrefixes; i++) {
|
|
|
|
len = strlen(prefixes[i]);
|
|
|
|
if (len > maxPrefixLength) maxPrefixLength = len;
|
|
|
|
}
|
|
|
|
prefixBuf = alloca(maxPrefixLength + 50);
|
|
|
|
|
|
|
|
if (script) {
|
|
|
|
FD_t fd;
|
|
|
|
if (makeTempFile((!ts->chrootDone ? ts->rootDir : "/"), &fn, &fd)) {
|
|
|
|
if (freePrefixes) free(prefixes);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rpmIsDebug() &&
|
|
|
|
(!strcmp(argv[0], "/bin/sh") || !strcmp(argv[0], "/bin/bash")))
|
|
|
|
(void)Fwrite("set -x\n", sizeof(char), 7, fd);
|
|
|
|
|
|
|
|
(void)Fwrite(script, sizeof(script[0]), strlen(script), fd);
|
|
|
|
Fclose(fd);
|
|
|
|
|
|
|
|
{ const char * sn = fn;
|
|
|
|
if (!ts->chrootDone &&
|
|
|
|
!(ts->rootDir[0] == '/' && ts->rootDir[1] == '\0'))
|
|
|
|
{
|
|
|
|
sn += strlen(ts->rootDir)-1;
|
|
|
|
}
|
|
|
|
argv[argc++] = sn;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (arg1 >= 0) {
|
|
|
|
char *av = alloca(20);
|
|
|
|
sprintf(av, "%d", arg1);
|
|
|
|
argv[argc++] = av;
|
|
|
|
}
|
|
|
|
if (arg2 >= 0) {
|
|
|
|
char *av = alloca(20);
|
|
|
|
sprintf(av, "%d", arg2);
|
|
|
|
argv[argc++] = av;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
argv[argc] = NULL;
|
|
|
|
|
|
|
|
if (ts->scriptFd != NULL) {
|
|
|
|
if (rpmIsVerbose()) {
|
|
|
|
out = fdDup(Fileno(ts->scriptFd));
|
|
|
|
} else {
|
|
|
|
out = Fopen("/dev/null", "w.fdio");
|
|
|
|
if (Ferror(out)) {
|
|
|
|
out = fdDup(Fileno(ts->scriptFd));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
out = fdDup(STDOUT_FILENO);
|
|
|
|
out = fdLink(out, "runScript persist");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(child = fork())) {
|
|
|
|
const char * rootDir;
|
|
|
|
int pipes[2];
|
|
|
|
|
|
|
|
pipes[0] = pipes[1] = 0;
|
|
|
|
/* make stdin inaccessible */
|
|
|
|
pipe(pipes);
|
|
|
|
close(pipes[1]);
|
|
|
|
dup2(pipes[0], STDIN_FILENO);
|
|
|
|
close(pipes[0]);
|
|
|
|
|
|
|
|
if (ts->scriptFd != NULL) {
|
|
|
|
if (Fileno(ts->scriptFd) != STDERR_FILENO)
|
|
|
|
dup2(Fileno(ts->scriptFd), STDERR_FILENO);
|
|
|
|
if (Fileno(out) != STDOUT_FILENO)
|
|
|
|
dup2(Fileno(out), STDOUT_FILENO);
|
|
|
|
/* make sure we don't close stdin/stderr/stdout by mistake! */
|
|
|
|
if (Fileno(out) > STDERR_FILENO && Fileno(out) != Fileno(ts->scriptFd)) {
|
|
|
|
Fclose (out);
|
|
|
|
}
|
|
|
|
if (Fileno(ts->scriptFd) > STDERR_FILENO) {
|
|
|
|
Fclose (ts->scriptFd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{ const char *ipath = rpmExpand("PATH=%{_install_script_path}", NULL);
|
|
|
|
const char *path = SCRIPT_PATH;
|
|
|
|
|
|
|
|
if (ipath && ipath[5] != '%')
|
|
|
|
path = ipath;
|
|
|
|
doputenv(path);
|
|
|
|
if (ipath) free((void *)ipath);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < numPrefixes; i++) {
|
|
|
|
sprintf(prefixBuf, "RPM_INSTALL_PREFIX%d=%s", i, prefixes[i]);
|
|
|
|
doputenv(prefixBuf);
|
|
|
|
|
|
|
|
/* backwards compatibility */
|
|
|
|
if (i == 0) {
|
|
|
|
sprintf(prefixBuf, "RPM_INSTALL_PREFIX=%s", prefixes[i]);
|
|
|
|
doputenv(prefixBuf);
|
2001-02-13 00:33:08 +08:00
|
|
|
}
|
2001-02-28 23:49:23 +08:00
|
|
|
}
|
2001-02-13 00:33:08 +08:00
|
|
|
|
2001-02-28 23:49:23 +08:00
|
|
|
rootDir = ts->rootDir;
|
|
|
|
switch(urlIsURL(rootDir)) {
|
|
|
|
case URL_IS_PATH:
|
|
|
|
rootDir += sizeof("file://") - 1;
|
|
|
|
rootDir = strchr(rootDir, '/');
|
|
|
|
/*@fallthrough@*/
|
|
|
|
case URL_IS_UNKNOWN:
|
|
|
|
if (!ts->chrootDone && !(rootDir[0] == '/' && rootDir[1] == '\0')) {
|
|
|
|
/*@-unrecog@*/ chroot(rootDir); /*@=unrecog@*/
|
|
|
|
}
|
2001-02-13 00:33:08 +08:00
|
|
|
chdir("/");
|
2001-02-28 23:49:23 +08:00
|
|
|
execv(argv[0], (char *const *)argv);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2001-02-13 00:33:08 +08:00
|
|
|
}
|
2001-02-28 23:49:23 +08:00
|
|
|
|
|
|
|
_exit(-1);
|
|
|
|
/*@notreached@*/
|
|
|
|
}
|
|
|
|
|
|
|
|
if (waitpid(child, &status, 0) < 0) {
|
|
|
|
rpmError(RPMERR_SCRIPT,
|
|
|
|
_("execution of %s scriptlet from %s-%s-%s failed, waitpid returned %s\n"),
|
|
|
|
sln, n, v, r, strerror (errno));
|
|
|
|
/* XXX what to do here? */
|
|
|
|
rc = 0;
|
2001-02-13 00:33:08 +08:00
|
|
|
} else {
|
2001-02-28 23:49:23 +08:00
|
|
|
if (!WIFEXITED(status) || WEXITSTATUS(status)) {
|
|
|
|
rpmError(RPMERR_SCRIPT,
|
|
|
|
_("execution of %s scriptlet from %s-%s-%s failed, exit status %d\n"),
|
|
|
|
sln, n, v, r, WEXITSTATUS(status));
|
|
|
|
rc = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (freePrefixes) prefixes = hfd(prefixes, ipt);
|
|
|
|
|
|
|
|
Fclose(out); /* XXX dup'd STDOUT_FILENO */
|
|
|
|
|
|
|
|
if (script) {
|
|
|
|
if (!rpmIsDebug()) unlink(fn);
|
|
|
|
free((void *)fn);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve and run scriptlet from header.
|
|
|
|
* @param psm package state machine data
|
|
|
|
* @return 0 on success
|
|
|
|
*/
|
|
|
|
static int runInstScript(PSM_t psm)
|
|
|
|
{
|
|
|
|
const rpmTransactionSet ts = psm->ts;
|
|
|
|
TFI_t fi = psm->fi;
|
|
|
|
HGE_t hge = fi->hge;
|
|
|
|
HFD_t hfd = fi->hfd;
|
|
|
|
void ** programArgv;
|
|
|
|
int programArgc;
|
|
|
|
const char ** argv;
|
|
|
|
int_32 ptt, stt;
|
|
|
|
const char * script;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (ts->transFlags & RPMTRANS_FLAG_NOSCRIPTS)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* headerGetEntry() sets the data pointer to NULL if the entry does
|
|
|
|
* not exist.
|
|
|
|
*/
|
|
|
|
hge(fi->h, psm->progTag, &ptt, (void **) &programArgv, &programArgc);
|
|
|
|
hge(fi->h, psm->scriptTag, &stt, (void **) &script, NULL);
|
|
|
|
|
|
|
|
if (programArgv && ptt == RPM_STRING_TYPE) {
|
|
|
|
argv = alloca(sizeof(char *));
|
|
|
|
*argv = (const char *) programArgv;
|
|
|
|
} else {
|
|
|
|
argv = (const char **) programArgv;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = runScript(psm, fi->h, tag2sln(psm->scriptTag), programArgc, argv,
|
|
|
|
script, psm->scriptArg, -1);
|
|
|
|
programArgv = hfd(programArgv, ptt);
|
|
|
|
script = hfd(script, stt);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param psm package state machine data
|
|
|
|
* @param sourceH
|
|
|
|
* @param triggeredH
|
|
|
|
* @param arg2
|
|
|
|
* @param triggersAlreadyRun
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
static int handleOneTrigger(PSM_t psm, Header sourceH, Header triggeredH,
|
|
|
|
int arg2, char * triggersAlreadyRun)
|
|
|
|
{
|
|
|
|
const rpmTransactionSet ts = psm->ts;
|
|
|
|
TFI_t fi = psm->fi;
|
|
|
|
HGE_t hge = fi->hge;
|
|
|
|
HFD_t hfd = fi->hfd;
|
|
|
|
const char ** triggerNames;
|
|
|
|
const char ** triggerEVR;
|
|
|
|
const char ** triggerScripts;
|
|
|
|
const char ** triggerProgs;
|
|
|
|
int_32 * triggerFlags;
|
|
|
|
int_32 * triggerIndices;
|
|
|
|
int_32 tnt, tvt, tft;
|
|
|
|
const char * triggerPackageName;
|
|
|
|
const char * sourceName;
|
|
|
|
int numTriggers;
|
|
|
|
int rc = 0;
|
|
|
|
int i;
|
|
|
|
int skip;
|
|
|
|
|
|
|
|
if (!hge(triggeredH, RPMTAG_TRIGGERNAME, &tnt,
|
|
|
|
(void **) &triggerNames, &numTriggers))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
headerNVR(sourceH, &sourceName, NULL, NULL);
|
|
|
|
|
|
|
|
hge(triggeredH, RPMTAG_TRIGGERFLAGS, &tft, (void **) &triggerFlags, NULL);
|
|
|
|
hge(triggeredH, RPMTAG_TRIGGERVERSION, &tvt, (void **) &triggerEVR, NULL);
|
|
|
|
|
|
|
|
for (i = 0; i < numTriggers; i++) {
|
|
|
|
int_32 tit, tst, tpt;
|
|
|
|
|
|
|
|
if (!(triggerFlags[i] & psm->sense)) continue;
|
|
|
|
if (strcmp(triggerNames[i], sourceName)) continue;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For some reason, the TRIGGERVERSION stuff includes the name of
|
|
|
|
* the package which the trigger is based on. We need to skip
|
|
|
|
* over that here. I suspect that we'll change our minds on this
|
|
|
|
* and remove that, so I'm going to just 'do the right thing'.
|
|
|
|
*/
|
|
|
|
skip = strlen(triggerNames[i]);
|
|
|
|
if (!strncmp(triggerEVR[i], triggerNames[i], skip) &&
|
|
|
|
(triggerEVR[i][skip] == '-'))
|
|
|
|
skip++;
|
|
|
|
else
|
|
|
|
skip = 0;
|
|
|
|
|
|
|
|
if (!headerMatchesDepFlags(sourceH, triggerNames[i],
|
|
|
|
triggerEVR[i] + skip, triggerFlags[i]))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
hge(triggeredH, RPMTAG_TRIGGERINDEX, &tit,
|
|
|
|
(void **) &triggerIndices, NULL);
|
|
|
|
hge(triggeredH, RPMTAG_TRIGGERSCRIPTS, &tst,
|
|
|
|
(void **) &triggerScripts, NULL);
|
|
|
|
hge(triggeredH, RPMTAG_TRIGGERSCRIPTPROG, &tpt,
|
|
|
|
(void **) &triggerProgs, NULL);
|
|
|
|
|
|
|
|
headerNVR(triggeredH, &triggerPackageName, NULL, NULL);
|
|
|
|
|
|
|
|
{ int arg1;
|
|
|
|
int index;
|
|
|
|
|
|
|
|
arg1 = rpmdbCountPackages(ts->rpmdb, triggerPackageName);
|
|
|
|
if (arg1 < 0) {
|
|
|
|
rc = 1; /* XXX W2DO? same as "execution of script failed" */
|
|
|
|
} else {
|
|
|
|
arg1 += psm->countCorrection;
|
|
|
|
index = triggerIndices[i];
|
|
|
|
if (!triggersAlreadyRun || !triggersAlreadyRun[index]) {
|
|
|
|
rc = runScript(psm, triggeredH, "%trigger", 1,
|
|
|
|
triggerProgs + index, triggerScripts[index],
|
|
|
|
arg1, arg2);
|
|
|
|
if (triggersAlreadyRun) triggersAlreadyRun[index] = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
triggerIndices = hfd(triggerIndices, tit);
|
|
|
|
triggerScripts = hfd(triggerScripts, tst);
|
|
|
|
triggerProgs = hfd(triggerProgs, tpt);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Each target/source header pair can only result in a single
|
|
|
|
* script being run.
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
triggerNames = hfd(triggerNames, tnt);
|
|
|
|
triggerFlags = hfd(triggerFlags, tft);
|
|
|
|
triggerEVR = hfd(triggerEVR, tvt);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Run trigger scripts in the database that are fired by this header.
|
|
|
|
* @param psm package state machine data
|
|
|
|
* @return 0 on success, 1 on error
|
|
|
|
*/
|
|
|
|
static int runTriggers(PSM_t psm)
|
|
|
|
{
|
|
|
|
const rpmTransactionSet ts = psm->ts;
|
|
|
|
TFI_t fi = psm->fi;
|
|
|
|
int numPackage;
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
numPackage = rpmdbCountPackages(ts->rpmdb, fi->name) + psm->countCorrection;
|
|
|
|
if (numPackage < 0)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
{ Header triggeredH;
|
|
|
|
rpmdbMatchIterator mi;
|
|
|
|
int countCorrection = psm->countCorrection;
|
|
|
|
|
|
|
|
psm->countCorrection = 0;
|
|
|
|
mi = rpmdbInitIterator(ts->rpmdb, RPMTAG_TRIGGERNAME, fi->name, 0);
|
|
|
|
while((triggeredH = rpmdbNextIterator(mi)) != NULL) {
|
|
|
|
rc |= handleOneTrigger(psm, fi->h, triggeredH, numPackage, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
rpmdbFreeIterator(mi);
|
|
|
|
psm->countCorrection = countCorrection;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Run triggers from this header that are fired by headers in the database.
|
|
|
|
* @param psm package state machine data
|
|
|
|
* @return 0 on success, 1 on error
|
|
|
|
*/
|
|
|
|
static int runImmedTriggers(PSM_t psm)
|
|
|
|
{
|
|
|
|
const rpmTransactionSet ts = psm->ts;
|
|
|
|
TFI_t fi = psm->fi;
|
|
|
|
HGE_t hge = fi->hge;
|
|
|
|
HFD_t hfd = fi->hfd;
|
|
|
|
const char ** triggerNames;
|
|
|
|
int numTriggers;
|
|
|
|
int_32 * triggerIndices;
|
|
|
|
int_32 tnt, tit;
|
|
|
|
int numTriggerIndices;
|
|
|
|
char * triggersRun;
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
if (!hge(fi->h, RPMTAG_TRIGGERNAME, &tnt,
|
|
|
|
(void **) &triggerNames, &numTriggers))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
hge(fi->h, RPMTAG_TRIGGERINDEX, &tit, (void **) &triggerIndices,
|
|
|
|
&numTriggerIndices);
|
|
|
|
triggersRun = alloca(sizeof(*triggersRun) * numTriggerIndices);
|
|
|
|
memset(triggersRun, 0, sizeof(*triggersRun) * numTriggerIndices);
|
|
|
|
|
|
|
|
{ Header sourceH = NULL;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < numTriggers; i++) {
|
|
|
|
rpmdbMatchIterator mi;
|
|
|
|
|
|
|
|
if (triggersRun[triggerIndices[i]]) continue;
|
|
|
|
|
|
|
|
mi = rpmdbInitIterator(ts->rpmdb, RPMTAG_NAME, triggerNames[i], 0);
|
|
|
|
|
|
|
|
while((sourceH = rpmdbNextIterator(mi)) != NULL) {
|
|
|
|
rc |= handleOneTrigger(psm, sourceH, fi->h,
|
|
|
|
rpmdbGetIteratorCount(mi),
|
|
|
|
triggersRun);
|
|
|
|
}
|
|
|
|
|
|
|
|
rpmdbFreeIterator(mi);
|
2001-02-13 00:33:08 +08:00
|
|
|
}
|
|
|
|
}
|
2001-02-28 23:49:23 +08:00
|
|
|
triggerIndices = hfd(triggerNames, tit);
|
|
|
|
triggerNames = hfd(triggerNames, tnt);
|
2001-02-13 00:33:08 +08:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2001-02-28 23:49:23 +08:00
|
|
|
int psmStage(PSM_t psm, pkgStage stage)
|
2001-02-28 06:08:53 +08:00
|
|
|
{
|
2001-02-28 23:49:23 +08:00
|
|
|
const rpmTransactionSet ts = psm->ts;
|
|
|
|
TFI_t fi = psm->fi;
|
2001-03-02 00:01:16 +08:00
|
|
|
HGE_t hge = (HGE_t)fi->hge;
|
2001-03-03 00:17:03 +08:00
|
|
|
HFD_t hfd = fi->hfd;
|
2001-02-28 06:08:53 +08:00
|
|
|
int rc = psm->rc;
|
2001-03-02 23:03:29 +08:00
|
|
|
int saveerrno;
|
2001-02-28 06:08:53 +08:00
|
|
|
|
|
|
|
switch (stage) {
|
2001-02-28 23:49:23 +08:00
|
|
|
case PSM_UNKNOWN:
|
2001-02-28 06:08:53 +08:00
|
|
|
break;
|
2001-02-28 23:49:23 +08:00
|
|
|
case PSM_INIT:
|
2001-03-02 16:28:18 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, _("%s: %s-%s-%s has %d files, test = %d\n"),
|
|
|
|
psm->stepName, fi->name, fi->version, fi->release,
|
|
|
|
fi->fc, (ts->transFlags & RPMTRANS_FLAG_TEST));
|
2001-03-03 00:17:03 +08:00
|
|
|
if (psm->goal == PSM_PKGINSTALL) {
|
|
|
|
/*
|
|
|
|
* When we run scripts, we pass an argument which is the number of
|
|
|
|
* versions of this package that will be installed when we are
|
|
|
|
* finished.
|
|
|
|
*/
|
|
|
|
psm->scriptArg = rpmdbCountPackages(ts->rpmdb, fi->name) + 1;
|
|
|
|
if (psm->scriptArg < 1) {
|
|
|
|
rc = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
{ rpmdbMatchIterator mi;
|
|
|
|
Header oh;
|
|
|
|
|
|
|
|
mi = rpmdbInitIterator(ts->rpmdb, RPMTAG_NAME, fi->name, 0);
|
|
|
|
rpmdbSetIteratorVersion(mi, fi->version);
|
|
|
|
rpmdbSetIteratorRelease(mi, fi->release);
|
|
|
|
while ((oh = rpmdbNextIterator(mi))) {
|
|
|
|
fi->record = rpmdbGetIteratorOffset(mi);
|
|
|
|
psm->oh = (ts->transFlags & RPMTRANS_FLAG_MULTILIB)
|
|
|
|
? headerCopy(oh) : NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
rpmdbFreeIterator(mi);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (psm->goal == PSM_PKGERASE) {
|
|
|
|
/*
|
|
|
|
* When we run scripts, we pass an argument which is the number of
|
|
|
|
* versions of this package that will be installed when we are
|
|
|
|
* finished.
|
|
|
|
*/
|
|
|
|
psm->scriptArg = rpmdbCountPackages(ts->rpmdb, fi->name) - 1;
|
|
|
|
if (psm->scriptArg < 0) {
|
|
|
|
rc = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Retrieve installed header. */
|
|
|
|
rc = psmStage(psm, PSM_RPMDB_LOAD);
|
|
|
|
if (rc) break;
|
|
|
|
}
|
|
|
|
if (psm->goal == PSM_PKGSAVE) {
|
|
|
|
/* Retrieve installed header. */
|
|
|
|
rc = psmStage(psm, PSM_RPMDB_LOAD);
|
|
|
|
}
|
2001-02-28 06:08:53 +08:00
|
|
|
break;
|
2001-02-28 23:49:23 +08:00
|
|
|
case PSM_PRE:
|
2001-03-02 16:28:18 +08:00
|
|
|
if (psm->goal == PSM_PKGINSTALL) {
|
|
|
|
psm->scriptTag = RPMTAG_PREIN;
|
|
|
|
psm->progTag = RPMTAG_PREINPROG;
|
|
|
|
rc = psmStage(psm, PSM_SCRIPT);
|
2001-03-02 23:03:29 +08:00
|
|
|
if (rc) {
|
|
|
|
rpmError(RPMERR_SCRIPT,
|
|
|
|
_("%s: %s scriptlet failed (%d), skipping %s-%s-%s\n"),
|
|
|
|
psm->stepName, tag2sln(psm->scriptTag), rc,
|
|
|
|
fi->name, fi->version, fi->release);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Change root directory if requested and not already done. */
|
|
|
|
(void) psmStage(psm, PSM_CHROOT_IN);
|
2001-03-02 16:28:18 +08:00
|
|
|
}
|
|
|
|
if (psm->goal == PSM_PKGERASE) {
|
|
|
|
psm->scriptTag = RPMTAG_PREUN;
|
|
|
|
psm->progTag = RPMTAG_PREUNPROG;
|
|
|
|
psm->sense = RPMSENSE_TRIGGERUN;
|
|
|
|
psm->countCorrection = -1;
|
2001-03-02 23:03:29 +08:00
|
|
|
|
|
|
|
/* Change root directory if requested and not already done. */
|
|
|
|
rc = psmStage(psm, PSM_CHROOT_IN);
|
|
|
|
if (rc) break;
|
|
|
|
|
2001-03-02 16:28:18 +08:00
|
|
|
rc = psmStage(psm, PSM_TRIGGERS);
|
|
|
|
if (rc) break;
|
|
|
|
|
|
|
|
rc = psmStage(psm, PSM_IMMED_TRIGGERS);
|
|
|
|
if (rc) break;
|
|
|
|
|
|
|
|
rc = psmStage(psm, PSM_SCRIPT);
|
|
|
|
}
|
2001-03-02 23:03:29 +08:00
|
|
|
if (psm->goal == PSM_PKGSAVE) {
|
2001-03-03 00:17:03 +08:00
|
|
|
/* Regenerate original header. */
|
|
|
|
{ void * uh = NULL;
|
|
|
|
int_32 uht, uhc;
|
|
|
|
|
|
|
|
if (headerGetEntry(fi->h, RPMTAG_HEADERIMMUTABLE, &uht, &uh, &uhc)) {
|
|
|
|
psm->oh = headerCopyLoad(uh);
|
|
|
|
uh = hfd(uh, uht);
|
|
|
|
} else {
|
|
|
|
psm->oh = headerLink(fi->h);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Open output package for writing. */
|
|
|
|
{ const char * bfmt = rpmGetPath("%{_repackage_name_fmt}", NULL);
|
|
|
|
const char * pkgbn =
|
|
|
|
headerSprintf(fi->h, bfmt, rpmTagTable, rpmHeaderFormats, NULL);
|
|
|
|
|
|
|
|
bfmt = _free(bfmt);
|
|
|
|
psm->pkgURL = rpmGenPath("%{?_repackage_root:%{_repackage_root}}",
|
|
|
|
"%{?_repackage_dir:%{_repackage_dir}}",
|
|
|
|
pkgbn);
|
|
|
|
pkgbn = _free(pkgbn);
|
|
|
|
(void) urlPath(psm->pkgURL, &psm->pkgfn);
|
|
|
|
psm->fd = Fopen(psm->pkgfn, "w.ufdio");
|
|
|
|
if (psm->fd == NULL || Ferror(psm->fd)) {
|
|
|
|
rc = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Retrieve type of payload compression. */
|
|
|
|
rc = psmStage(psm, PSM_RPMIO_FLAGS);
|
|
|
|
|
|
|
|
/* Write the lead section into the package. */
|
|
|
|
{ int archnum = -1;
|
|
|
|
int osnum = -1;
|
|
|
|
struct rpmlead lead;
|
|
|
|
|
|
|
|
#ifndef DYING
|
|
|
|
rpmGetArchInfo(NULL, &archnum);
|
|
|
|
rpmGetOsInfo(NULL, &osnum);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
memset(&lead, 0, sizeof(lead));
|
|
|
|
/* XXX Set package version conditioned on noDirTokens. */
|
|
|
|
lead.major = 4;
|
|
|
|
lead.minor = 0;
|
|
|
|
lead.type = RPMLEAD_BINARY;
|
|
|
|
lead.archnum = archnum;
|
|
|
|
lead.osnum = osnum;
|
|
|
|
lead.signature_type = RPMSIGTYPE_HEADERSIG;
|
|
|
|
|
|
|
|
{ char buf[256];
|
|
|
|
sprintf(buf, "%s-%s-%s", fi->name, fi->version, fi->release);
|
|
|
|
strncpy(lead.name, buf, sizeof(lead.name));
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = writeLead(psm->fd, &lead);
|
|
|
|
if (rc) {
|
|
|
|
rpmError(RPMERR_NOSPACE, _("Unable to write package: %s\n"),
|
|
|
|
Fstrerror(psm->fd));
|
|
|
|
rc = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write the signature section into the package. */
|
|
|
|
{ Header sig = headerRegenSigHeader(fi->h);
|
|
|
|
rc = rpmWriteSignature(psm->fd, sig);
|
|
|
|
headerFree(sig);
|
|
|
|
if (rc) break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write the metadata section into the package. */
|
|
|
|
rc = headerWrite(psm->fd, psm->oh, HEADER_MAGIC_YES);
|
|
|
|
if (rc) break;
|
|
|
|
|
2001-03-02 23:03:29 +08:00
|
|
|
/* Change root directory if requested and not already done. */
|
|
|
|
rc = psmStage(psm, PSM_CHROOT_IN);
|
|
|
|
}
|
2001-02-28 06:08:53 +08:00
|
|
|
break;
|
2001-02-28 23:49:23 +08:00
|
|
|
case PSM_PROCESS:
|
2001-03-02 16:28:18 +08:00
|
|
|
if (psm->goal == PSM_PKGINSTALL) {
|
2001-03-02 23:03:29 +08:00
|
|
|
struct availablePackage * alp = fi->ap;
|
|
|
|
|
|
|
|
/* Retrieve type of payload compression. */
|
|
|
|
rc = psmStage(psm, PSM_RPMIO_FLAGS);
|
|
|
|
|
|
|
|
psm->cfd = Fdopen(fdDup(Fileno(alp->fd)), psm->rpmio_flags);
|
|
|
|
|
2001-03-02 16:28:18 +08:00
|
|
|
rc = fsmSetup(fi->fsm, FSM_PKGINSTALL, ts, fi,
|
|
|
|
psm->cfd, NULL, &psm->failedFile);
|
|
|
|
(void) fsmTeardown(fi->fsm);
|
2001-03-02 23:03:29 +08:00
|
|
|
|
|
|
|
saveerrno = errno; /* XXX FIXME: Fclose with libio destroys errno */
|
|
|
|
Fclose(psm->cfd);
|
|
|
|
psm->cfd = NULL;
|
|
|
|
errno = saveerrno; /* XXX FIXME: Fclose with libio destroys errno */
|
2001-03-02 16:28:18 +08:00
|
|
|
}
|
|
|
|
if (psm->goal == PSM_PKGERASE) {
|
|
|
|
const void * pkgKey = NULL;
|
|
|
|
|
|
|
|
if (fi->fc <= 0) break;
|
|
|
|
if (ts->transFlags & RPMTRANS_FLAG_JUSTDB) break;
|
|
|
|
|
|
|
|
if (ts->notify)
|
|
|
|
(void) ts->notify(fi->h, RPMCALLBACK_UNINST_START,
|
|
|
|
fi->fc, fi->fc, pkgKey, ts->notifyData);
|
|
|
|
|
|
|
|
rc = fsmSetup(fi->fsm, FSM_PKGERASE, ts, fi,
|
|
|
|
NULL, NULL, &psm->failedFile);
|
|
|
|
(void) fsmTeardown(fi->fsm);
|
|
|
|
|
|
|
|
if (ts->notify)
|
|
|
|
(void) ts->notify(fi->h, RPMCALLBACK_UNINST_STOP,
|
|
|
|
0, fi->fc, pkgKey, ts->notifyData);
|
|
|
|
}
|
|
|
|
if (psm->goal == PSM_PKGSAVE) {
|
|
|
|
fileAction * actions = fi->actions;
|
|
|
|
fileAction action = fi->action;
|
|
|
|
|
|
|
|
fi->action = FA_COPYOUT;
|
|
|
|
fi->actions = NULL;
|
|
|
|
|
2001-03-02 23:03:29 +08:00
|
|
|
Fflush(psm->fd);
|
|
|
|
psm->cfd = Fdopen(fdDup(Fileno(psm->fd)), psm->rpmio_flags);
|
|
|
|
|
2001-03-02 16:28:18 +08:00
|
|
|
/* XXX failedFile? */
|
|
|
|
rc = fsmSetup(fi->fsm, FSM_PKGBUILD, ts, fi, psm->cfd, NULL, NULL);
|
|
|
|
(void) fsmTeardown(fi->fsm);
|
|
|
|
|
2001-03-02 23:03:29 +08:00
|
|
|
saveerrno = errno; /* XXX FIXME: Fclose with libio destroys errno */
|
|
|
|
Fclose(psm->cfd);
|
|
|
|
psm->cfd = NULL;
|
|
|
|
errno = saveerrno;
|
|
|
|
|
2001-03-02 16:28:18 +08:00
|
|
|
fi->action = action;
|
|
|
|
fi->actions = actions;
|
|
|
|
}
|
2001-02-28 06:08:53 +08:00
|
|
|
break;
|
2001-02-28 23:49:23 +08:00
|
|
|
case PSM_POST:
|
2001-03-02 16:28:18 +08:00
|
|
|
if (psm->goal == PSM_PKGINSTALL) {
|
2001-03-03 00:17:03 +08:00
|
|
|
int_32 installTime = time(NULL);
|
|
|
|
|
|
|
|
/* Restore root directory if changed. */
|
|
|
|
(void) psmStage(psm, PSM_CHROOT_OUT);
|
|
|
|
|
|
|
|
if (fi->fc > 0 && fi->fstates)
|
|
|
|
headerAddEntry(fi->h, RPMTAG_FILESTATES, RPM_CHAR_TYPE,
|
|
|
|
fi->fstates, fi->fc);
|
|
|
|
|
|
|
|
headerAddEntry(fi->h, RPMTAG_INSTALLTIME, RPM_INT32_TYPE,
|
|
|
|
&installTime, 1);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If this package has already been installed, remove it from
|
|
|
|
* the database before adding the new one.
|
|
|
|
*/
|
|
|
|
if (fi->record) {
|
|
|
|
rc = psmStage(psm, PSM_RPMDB_REMOVE);
|
|
|
|
if (rc) break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ts->transFlags & RPMTRANS_FLAG_MULTILIB) {
|
|
|
|
uint_32 multiLib, * newMultiLib, * p;
|
|
|
|
|
|
|
|
if (hge(fi->h, RPMTAG_MULTILIBS, NULL, (void **) &newMultiLib, NULL) &&
|
|
|
|
hge(psm->oh, RPMTAG_MULTILIBS, NULL, (void **) &p, NULL)) {
|
|
|
|
multiLib = *p;
|
|
|
|
multiLib |= *newMultiLib;
|
|
|
|
headerModifyEntry(psm->oh, RPMTAG_MULTILIBS, RPM_INT32_TYPE,
|
|
|
|
&multiLib, 1);
|
|
|
|
}
|
|
|
|
rc = mergeFiles(fi, psm->oh, fi->h);
|
|
|
|
if (rc) break;
|
|
|
|
}
|
|
|
|
|
2001-03-02 16:28:18 +08:00
|
|
|
psm->scriptTag = RPMTAG_POSTIN;
|
|
|
|
psm->progTag = RPMTAG_POSTINPROG;
|
|
|
|
psm->sense = RPMSENSE_TRIGGERIN;
|
|
|
|
psm->countCorrection = 0;
|
|
|
|
|
|
|
|
rc = psmStage(psm, PSM_RPMDB_ADD);
|
|
|
|
if (rc) break;
|
|
|
|
|
|
|
|
rc = psmStage(psm, PSM_SCRIPT);
|
|
|
|
if (rc) break;
|
|
|
|
|
|
|
|
rc = psmStage(psm, PSM_TRIGGERS);
|
|
|
|
if (rc) break;
|
|
|
|
|
|
|
|
rc = psmStage(psm, PSM_IMMED_TRIGGERS);
|
|
|
|
if (rc) break;
|
|
|
|
|
2001-03-03 00:17:03 +08:00
|
|
|
rc = markReplacedFiles(psm);
|
2001-03-02 23:03:29 +08:00
|
|
|
|
2001-03-02 16:28:18 +08:00
|
|
|
}
|
|
|
|
if (psm->goal == PSM_PKGERASE) {
|
|
|
|
psm->scriptTag = RPMTAG_POSTUN;
|
|
|
|
psm->progTag = RPMTAG_POSTUNPROG;
|
|
|
|
psm->sense = RPMSENSE_TRIGGERPOSTUN;
|
|
|
|
psm->countCorrection = -1;
|
|
|
|
|
2001-03-02 23:03:29 +08:00
|
|
|
rc = psmStage(psm, PSM_SCRIPT);
|
2001-03-02 16:28:18 +08:00
|
|
|
/* XXX WTFO? postun failures are not cause for erasure failure. */
|
|
|
|
|
|
|
|
rc = psmStage(psm, PSM_TRIGGERS);
|
2001-03-02 23:03:29 +08:00
|
|
|
if (rc) break;
|
|
|
|
|
|
|
|
rc = psmStage(psm, PSM_RPMDB_REMOVE);
|
2001-03-02 16:28:18 +08:00
|
|
|
}
|
2001-02-28 06:08:53 +08:00
|
|
|
break;
|
2001-02-28 23:49:23 +08:00
|
|
|
case PSM_UNDO:
|
2001-02-28 06:08:53 +08:00
|
|
|
break;
|
2001-02-28 23:49:23 +08:00
|
|
|
case PSM_FINI:
|
2001-03-02 23:03:29 +08:00
|
|
|
if (psm->fd) {
|
|
|
|
saveerrno = errno; /* XXX FIXME: Fclose with libio destroys errno */
|
|
|
|
Fclose(psm->fd);
|
|
|
|
psm->fd = NULL;
|
|
|
|
errno = saveerrno;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (psm->goal == PSM_PKGSAVE) {
|
|
|
|
if (!rc)
|
|
|
|
rpmMessage(RPMMESS_VERBOSE, _("Wrote: %s\n"), psm->pkgURL);
|
|
|
|
}
|
|
|
|
|
2001-03-02 16:28:18 +08:00
|
|
|
/* Restore root directory if changed. */
|
|
|
|
(void) psmStage(psm, PSM_CHROOT_OUT);
|
|
|
|
|
|
|
|
if (fi->h && (psm->goal == PSM_PKGERASE || psm->goal == PSM_PKGSAVE)) {
|
|
|
|
headerFree(fi->h);
|
|
|
|
fi->h = NULL;
|
|
|
|
}
|
2001-03-02 23:03:29 +08:00
|
|
|
if (psm->oh) {
|
|
|
|
headerFree(psm->oh);
|
|
|
|
psm->oh = NULL;
|
|
|
|
}
|
2001-03-02 16:28:18 +08:00
|
|
|
psm->pkgURL = _free(psm->pkgURL);
|
|
|
|
psm->rpmio_flags = _free(psm->rpmio_flags);
|
|
|
|
psm->failedFile = _free(psm->failedFile);
|
2001-02-28 06:08:53 +08:00
|
|
|
break;
|
2001-03-02 00:01:16 +08:00
|
|
|
|
|
|
|
case PSM_PKGINSTALL:
|
2001-02-28 06:08:53 +08:00
|
|
|
break;
|
2001-03-02 00:01:16 +08:00
|
|
|
case PSM_PKGERASE:
|
2001-03-02 16:28:18 +08:00
|
|
|
break;
|
2001-03-02 00:01:16 +08:00
|
|
|
case PSM_PKGCOMMIT:
|
2001-02-28 06:08:53 +08:00
|
|
|
break;
|
2001-03-02 00:01:16 +08:00
|
|
|
case PSM_PKGSAVE:
|
2001-03-02 16:28:18 +08:00
|
|
|
break;
|
2001-03-02 00:01:16 +08:00
|
|
|
|
2001-02-28 23:49:23 +08:00
|
|
|
case PSM_CREATE:
|
2001-02-28 06:08:53 +08:00
|
|
|
break;
|
2001-03-02 00:01:16 +08:00
|
|
|
case PSM_NOTIFY:
|
|
|
|
break;
|
2001-02-28 23:49:23 +08:00
|
|
|
case PSM_DESTROY:
|
2001-02-28 06:08:53 +08:00
|
|
|
break;
|
2001-03-02 00:01:16 +08:00
|
|
|
case PSM_COMMIT:
|
2001-03-02 23:03:29 +08:00
|
|
|
if (!(ts->transFlags & RPMTRANS_FLAG_PKGCOMMIT)) break;
|
|
|
|
rc = fsmSetup(fi->fsm, FSM_PKGCOMMIT, ts, fi,
|
|
|
|
NULL, NULL, &psm->failedFile);
|
|
|
|
(void) fsmTeardown(fi->fsm);
|
2001-03-02 00:01:16 +08:00
|
|
|
break;
|
2001-02-28 23:49:23 +08:00
|
|
|
|
|
|
|
case PSM_CHROOT_IN:
|
|
|
|
/* Change root directory if requested and not already done. */
|
|
|
|
if (ts->rootDir && !ts->chrootDone && !psm->chrootDone) {
|
|
|
|
static int _loaded = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This loads all of the name services libraries, in case we
|
|
|
|
* don't have access to them in the chroot().
|
|
|
|
*/
|
|
|
|
if (!_loaded) {
|
|
|
|
(void)getpwnam("root");
|
|
|
|
endpwent();
|
|
|
|
_loaded++;
|
|
|
|
}
|
|
|
|
|
|
|
|
chdir("/");
|
|
|
|
/*@-unrecog@*/
|
|
|
|
rc = chroot(ts->rootDir);
|
|
|
|
/*@=unrecog@*/
|
|
|
|
psm->chrootDone = ts->chrootDone = 1;
|
|
|
|
}
|
2001-02-28 06:08:53 +08:00
|
|
|
break;
|
2001-02-28 23:49:23 +08:00
|
|
|
case PSM_CHROOT_OUT:
|
|
|
|
/* Restore root directory if changed. */
|
|
|
|
if (psm->chrootDone) {
|
|
|
|
/*@-unrecog@*/
|
|
|
|
rc = chroot(".");
|
|
|
|
/*@=unrecog@*/
|
|
|
|
psm->chrootDone = ts->chrootDone = 0;
|
|
|
|
chdir(ts->currDir);
|
|
|
|
}
|
2001-02-28 06:08:53 +08:00
|
|
|
break;
|
2001-02-28 23:49:23 +08:00
|
|
|
case PSM_SCRIPT:
|
2001-03-01 00:41:19 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, _("%s: running %s script(s) (if any)\n"),
|
|
|
|
psm->stepName, tag2sln(psm->scriptTag));
|
2001-02-28 23:49:23 +08:00
|
|
|
rc = runInstScript(psm);
|
2001-02-28 06:08:53 +08:00
|
|
|
break;
|
2001-03-01 00:41:19 +08:00
|
|
|
case PSM_TRIGGERS:
|
2001-03-02 00:01:16 +08:00
|
|
|
if (ts->transFlags & RPMTRANS_FLAG_NOTRIGGERS) break;
|
|
|
|
rc = runTriggers(psm);
|
2001-03-01 00:41:19 +08:00
|
|
|
break;
|
|
|
|
case PSM_IMMED_TRIGGERS:
|
2001-03-02 00:01:16 +08:00
|
|
|
if (ts->transFlags & RPMTRANS_FLAG_NOTRIGGERS) break;
|
|
|
|
rc = runImmedTriggers(psm);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PSM_RPMIO_FLAGS:
|
|
|
|
{ const char * payload_compressor = NULL;
|
|
|
|
char * t;
|
|
|
|
|
|
|
|
if (!hge(fi->h, RPMTAG_PAYLOADCOMPRESSOR, NULL,
|
|
|
|
(void **) &payload_compressor, NULL))
|
|
|
|
payload_compressor = "gzip";
|
|
|
|
psm->rpmio_flags = t = xmalloc(sizeof("w9.gzdio"));
|
2001-03-02 16:28:18 +08:00
|
|
|
*t = '\0';
|
|
|
|
t = stpcpy(t, ((psm->goal == PSM_PKGSAVE) ? "w9" : "r"));
|
2001-03-02 00:01:16 +08:00
|
|
|
if (!strcmp(payload_compressor, "gzip"))
|
|
|
|
t = stpcpy(t, ".gzdio");
|
|
|
|
if (!strcmp(payload_compressor, "bzip2"))
|
|
|
|
t = stpcpy(t, ".bzdio");
|
2001-03-02 16:28:18 +08:00
|
|
|
rc = 0;
|
2001-03-02 00:01:16 +08:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case PSM_RPMDB_LOAD:
|
|
|
|
{ rpmdbMatchIterator mi = NULL;
|
|
|
|
|
|
|
|
mi = rpmdbInitIterator(ts->rpmdb, RPMDBI_PACKAGES,
|
|
|
|
&fi->record, sizeof(fi->record));
|
|
|
|
|
|
|
|
fi->h = rpmdbNextIterator(mi);
|
|
|
|
if (fi->h)
|
|
|
|
fi->h = headerLink(fi->h);
|
|
|
|
rpmdbFreeIterator(mi);
|
2001-03-03 00:17:03 +08:00
|
|
|
rc = (fi->h ? 0 : 2);
|
2001-03-02 00:01:16 +08:00
|
|
|
} break;
|
|
|
|
case PSM_RPMDB_ADD:
|
|
|
|
if (ts->transFlags & RPMTRANS_FLAG_TEST) break;
|
|
|
|
rc = rpmdbAdd(ts->rpmdb, ts->id, fi->h);
|
|
|
|
break;
|
|
|
|
case PSM_RPMDB_REMOVE:
|
|
|
|
if (ts->transFlags & RPMTRANS_FLAG_TEST) break;
|
|
|
|
rc = rpmdbRemove(ts->rpmdb, ts->id, fi->record);
|
2001-02-28 06:08:53 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2001-01-25 05:35:52 +08:00
|
|
|
/**
|
|
|
|
* @todo Packages w/o files never get a callback, hence don't get displayed
|
|
|
|
* on install with -v.
|
|
|
|
*/
|
2001-02-28 06:08:53 +08:00
|
|
|
int installBinaryPackage(PSM_t psm)
|
1999-07-14 06:53:46 +08:00
|
|
|
{
|
2001-02-28 06:08:53 +08:00
|
|
|
const rpmTransactionSet ts = psm->ts;
|
|
|
|
TFI_t fi = psm->fi;
|
2001-02-06 06:22:43 +08:00
|
|
|
HGE_t hge = (HGE_t)fi->hge;
|
2001-01-22 07:48:09 +08:00
|
|
|
int ec = 2; /* assume error return */
|
2001-01-21 23:43:32 +08:00
|
|
|
int rc;
|
|
|
|
|
2001-03-02 00:01:16 +08:00
|
|
|
psm->goal = PSM_PKGINSTALL;
|
2001-03-02 16:28:18 +08:00
|
|
|
psm->stepName = " install";
|
2001-03-01 00:41:19 +08:00
|
|
|
|
2001-03-02 16:28:18 +08:00
|
|
|
rc = psmStage(psm, PSM_INIT);
|
2001-03-03 00:17:03 +08:00
|
|
|
if (rc)
|
2000-04-08 00:09:25 +08:00
|
|
|
goto exit;
|
1999-07-14 06:53:46 +08:00
|
|
|
|
2001-01-25 20:58:03 +08:00
|
|
|
if (fi->fc > 0 && fi->fstates == NULL) {
|
|
|
|
fi->fstates = xmalloc(sizeof(*fi->fstates) * fi->fc);
|
|
|
|
memset(fi->fstates, RPMFILE_STATE_NORMAL, fi->fc);
|
|
|
|
}
|
2001-01-24 23:58:35 +08:00
|
|
|
|
2001-01-25 20:58:03 +08:00
|
|
|
if (fi->fc > 0 && !(ts->transFlags & RPMTRANS_FLAG_JUSTDB)) {
|
2001-01-22 07:48:09 +08:00
|
|
|
const char * p;
|
1999-07-14 06:53:46 +08:00
|
|
|
|
2001-01-22 07:48:09 +08:00
|
|
|
/*
|
|
|
|
* Old format relocateable packages need the entire default
|
|
|
|
* prefix stripped to form the cpio list, while all other packages
|
|
|
|
* need the leading / stripped.
|
|
|
|
*/
|
2001-02-06 06:22:43 +08:00
|
|
|
rc = hge(fi->h, RPMTAG_DEFAULTPREFIX, NULL, (void **) &p, NULL);
|
2001-01-24 07:03:28 +08:00
|
|
|
fi->striplen = (rc ? strlen(p) + 1 : 1);
|
|
|
|
fi->mapflags =
|
|
|
|
CPIO_MAP_PATH | CPIO_MAP_MODE | CPIO_MAP_UID | CPIO_MAP_GID;
|
2001-01-25 20:58:03 +08:00
|
|
|
|
|
|
|
if (headerIsEntry(fi->h, RPMTAG_ORIGBASENAMES))
|
|
|
|
buildOrigFileList(fi->h, &fi->apath, NULL);
|
|
|
|
else
|
|
|
|
rpmBuildFileList(fi->h, &fi->apath, NULL);
|
|
|
|
|
|
|
|
if (fi->fuser == NULL)
|
2001-02-06 06:22:43 +08:00
|
|
|
hge(fi->h, RPMTAG_FILEUSERNAME, NULL, (void **) &fi->fuser, NULL);
|
2001-01-25 20:58:03 +08:00
|
|
|
if (fi->fgroup == NULL)
|
2001-02-06 06:22:43 +08:00
|
|
|
hge(fi->h, RPMTAG_FILEGROUPNAME, NULL, (void **) &fi->fgroup, NULL);
|
2001-01-25 20:58:03 +08:00
|
|
|
if (fi->fuids == NULL)
|
|
|
|
fi->fuids = xcalloc(sizeof(*fi->fuids), fi->fc);
|
|
|
|
if (fi->fgids == NULL)
|
|
|
|
fi->fgids = xcalloc(sizeof(*fi->fgids), fi->fc);
|
|
|
|
|
1999-07-14 06:53:46 +08:00
|
|
|
}
|
1999-11-30 22:49:45 +08:00
|
|
|
|
2001-01-25 05:35:52 +08:00
|
|
|
if (ts->transFlags & RPMTRANS_FLAG_TEST) {
|
2001-01-22 07:48:09 +08:00
|
|
|
ec = 0;
|
1999-09-18 06:01:34 +08:00
|
|
|
goto exit;
|
1999-07-14 06:53:46 +08:00
|
|
|
}
|
|
|
|
|
2001-03-02 16:28:18 +08:00
|
|
|
rc = psmStage(psm, PSM_PRE);
|
2001-03-02 23:03:29 +08:00
|
|
|
if (rc)
|
1999-09-18 06:01:34 +08:00
|
|
|
goto exit;
|
2000-12-20 01:43:56 +08:00
|
|
|
|
2001-01-25 20:58:03 +08:00
|
|
|
if (fi->fc > 0 && !(ts->transFlags & RPMTRANS_FLAG_JUSTDB)) {
|
2001-01-24 23:58:35 +08:00
|
|
|
|
2001-03-02 23:03:29 +08:00
|
|
|
rc = setFileOwners(fi);
|
2001-01-22 07:48:09 +08:00
|
|
|
|
2001-03-02 00:01:16 +08:00
|
|
|
rc = installArchive(psm, 0);
|
2001-01-22 07:48:09 +08:00
|
|
|
|
2001-01-25 20:58:03 +08:00
|
|
|
if (rc)
|
|
|
|
goto exit;
|
1999-09-18 06:01:34 +08:00
|
|
|
}
|
1999-07-14 06:53:46 +08:00
|
|
|
|
2001-03-02 16:28:18 +08:00
|
|
|
rc = psmStage(psm, PSM_POST);
|
2001-03-01 00:41:19 +08:00
|
|
|
if (rc)
|
|
|
|
goto exit;
|
1999-07-14 06:53:46 +08:00
|
|
|
|
2001-01-22 07:48:09 +08:00
|
|
|
ec = 0;
|
1999-09-18 06:01:34 +08:00
|
|
|
|
|
|
|
exit:
|
2001-03-02 16:28:18 +08:00
|
|
|
(void) psmStage(psm, PSM_FINI);
|
2001-02-13 00:33:08 +08:00
|
|
|
|
2001-01-22 07:48:09 +08:00
|
|
|
return ec;
|
1999-07-14 06:53:46 +08:00
|
|
|
}
|
2001-02-11 00:47:40 +08:00
|
|
|
|
2001-02-28 06:08:53 +08:00
|
|
|
int removeBinaryPackage(PSM_t psm)
|
2001-02-11 00:47:40 +08:00
|
|
|
{
|
|
|
|
int rc = 0;
|
|
|
|
|
2001-03-02 00:01:16 +08:00
|
|
|
psm->goal = PSM_PKGERASE;
|
2001-03-02 16:28:18 +08:00
|
|
|
psm->stepName = " erase";
|
|
|
|
|
|
|
|
rc = psmStage(psm, PSM_INIT);
|
2001-03-03 00:17:03 +08:00
|
|
|
if (rc)
|
2001-02-13 00:33:08 +08:00
|
|
|
goto exit;
|
2001-02-11 00:47:40 +08:00
|
|
|
|
2001-03-02 16:28:18 +08:00
|
|
|
rc = psmStage(psm, PSM_PRE);
|
2001-03-03 00:17:03 +08:00
|
|
|
if (rc)
|
2001-03-01 00:41:19 +08:00
|
|
|
goto exit;
|
2001-02-11 00:47:40 +08:00
|
|
|
|
2001-03-02 16:28:18 +08:00
|
|
|
rc = psmStage(psm, PSM_PROCESS);
|
|
|
|
/* XXX WTFO? erase failures are not cause for stopping. */
|
|
|
|
|
|
|
|
rc = psmStage(psm, PSM_POST);
|
2001-03-03 00:17:03 +08:00
|
|
|
if (rc)
|
2001-02-13 00:33:08 +08:00
|
|
|
goto exit;
|
2001-02-11 00:47:40 +08:00
|
|
|
|
2001-02-13 00:33:08 +08:00
|
|
|
exit:
|
2001-03-02 16:28:18 +08:00
|
|
|
(void) psmStage(psm, PSM_FINI);
|
2001-02-28 07:12:30 +08:00
|
|
|
|
2001-02-13 00:33:08 +08:00
|
|
|
return rc;
|
2001-02-11 00:47:40 +08:00
|
|
|
}
|
2001-02-12 06:02:29 +08:00
|
|
|
|
2001-02-28 06:08:53 +08:00
|
|
|
int repackage(PSM_t psm)
|
2001-02-12 06:02:29 +08:00
|
|
|
{
|
|
|
|
int rc = 0;
|
|
|
|
|
2001-03-02 00:01:16 +08:00
|
|
|
psm->goal = PSM_PKGSAVE;
|
2001-03-02 16:28:18 +08:00
|
|
|
psm->stepName = "repackage";
|
|
|
|
|
|
|
|
rc = psmStage(psm, PSM_INIT);
|
2001-03-03 00:17:03 +08:00
|
|
|
if (rc)
|
2001-03-02 01:04:27 +08:00
|
|
|
goto exit;
|
2001-02-12 06:02:29 +08:00
|
|
|
|
2001-03-03 00:17:03 +08:00
|
|
|
/* Write the lead, signature, and header into the package. */
|
2001-03-02 23:03:29 +08:00
|
|
|
rc = psmStage(psm, PSM_PRE);
|
2001-03-03 00:17:03 +08:00
|
|
|
if (rc)
|
|
|
|
goto exit;
|
2001-02-12 06:02:29 +08:00
|
|
|
|
|
|
|
/* Write the payload into the package. */
|
2001-03-02 16:28:18 +08:00
|
|
|
rc = psmStage(psm, PSM_PROCESS);
|
2001-02-12 06:02:29 +08:00
|
|
|
|
|
|
|
exit:
|
2001-03-02 16:28:18 +08:00
|
|
|
(void) psmStage(psm, PSM_FINI);
|
2001-02-12 06:02:29 +08:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|