2000-08-28 03:40:35 +08:00
|
|
|
/** \ingroup rpmtrans
|
|
|
|
* \file lib/transaction.c
|
|
|
|
*/
|
|
|
|
|
1998-12-19 03:09:38 +08:00
|
|
|
#include "system.h"
|
|
|
|
|
1999-07-14 05:37:57 +08:00
|
|
|
#include <rpmlib.h>
|
1999-10-30 00:06:01 +08:00
|
|
|
#include <rpmmacro.h> /* XXX for rpmExpand */
|
1998-12-19 03:09:38 +08:00
|
|
|
|
2001-02-11 00:47:40 +08:00
|
|
|
#include "psm.h"
|
1998-12-27 02:32:08 +08:00
|
|
|
#include "fprint.h"
|
1998-12-27 00:33:51 +08:00
|
|
|
#include "hash.h"
|
1999-01-01 03:16:31 +08:00
|
|
|
#include "md5.h"
|
1998-12-19 03:09:38 +08:00
|
|
|
#include "misc.h"
|
1998-12-31 07:03:43 +08:00
|
|
|
#include "rpmdb.h"
|
1998-12-19 03:09:38 +08:00
|
|
|
|
1999-03-23 02:36:23 +08:00
|
|
|
/* XXX FIXME: merge with existing (broken?) tests in system.h */
|
1999-04-04 01:13:35 +08:00
|
|
|
/* portability fiddles */
|
1999-04-17 07:05:00 +08:00
|
|
|
#if STATFS_IN_SYS_STATVFS
|
|
|
|
# include <sys/statvfs.h>
|
1999-03-23 02:36:23 +08:00
|
|
|
#else
|
1999-04-17 07:05:00 +08:00
|
|
|
# if STATFS_IN_SYS_VFS
|
|
|
|
# include <sys/vfs.h>
|
1999-03-23 02:36:23 +08:00
|
|
|
# else
|
1999-04-17 07:05:00 +08:00
|
|
|
# if STATFS_IN_SYS_MOUNT
|
|
|
|
# include <sys/mount.h>
|
|
|
|
# else
|
|
|
|
# if STATFS_IN_SYS_STATFS
|
|
|
|
# include <sys/statfs.h>
|
|
|
|
# endif
|
1999-03-23 02:36:23 +08:00
|
|
|
# endif
|
|
|
|
# endif
|
|
|
|
#endif
|
1999-03-19 11:39:17 +08:00
|
|
|
|
2000-12-13 04:03:45 +08:00
|
|
|
#include "debug.h"
|
|
|
|
|
2000-10-29 01:16:25 +08:00
|
|
|
/*@access FD_t@*/ /* XXX compared with NULL */
|
|
|
|
/*@access Header@*/ /* XXX compared with NULL */
|
|
|
|
/*@access dbiIndexSet@*/
|
1999-09-18 04:52:46 +08:00
|
|
|
/*@access rpmdb@*/
|
|
|
|
/*@access rpmTransactionSet@*/
|
2001-01-27 01:06:09 +08:00
|
|
|
/*@access TFI_t@*/
|
2001-02-28 06:08:53 +08:00
|
|
|
/*@access PSM_t@*/
|
1999-09-18 04:52:46 +08:00
|
|
|
/*@access rpmProblemSet@*/
|
|
|
|
/*@access rpmProblem@*/
|
|
|
|
|
1999-03-19 11:39:17 +08:00
|
|
|
struct diskspaceInfo {
|
2000-10-21 00:47:00 +08:00
|
|
|
dev_t dev; /*!< file system device number. */
|
|
|
|
signed long bneeded; /*!< no. of blocks needed. */
|
|
|
|
signed long ineeded; /*!< no. of inodes needed. */
|
|
|
|
int bsize; /*!< file system block size. */
|
|
|
|
signed long bavail; /*!< no. of blocks available. */
|
|
|
|
signed long iavail; /*!< no. of inodes available. */
|
1999-03-19 11:39:17 +08:00
|
|
|
};
|
|
|
|
|
1999-04-19 04:56:19 +08:00
|
|
|
/* Adjust for root only reserved space. On linux e2fs, this is 5%. */
|
|
|
|
#define adj_fs_blocks(_nb) (((_nb) * 21) / 20)
|
|
|
|
|
1999-08-07 05:35:15 +08:00
|
|
|
/* argon thought a shift optimization here was a waste of time... he's
|
1999-03-19 11:39:17 +08:00
|
|
|
probably right :-( */
|
|
|
|
#define BLOCK_ROUND(size, block) (((size) + (block) - 1) / (block))
|
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
#define XSTRCMP(a, b) ((!(a) && !(b)) || ((a) && (b) && !strcmp((a), (b))))
|
1998-12-19 03:09:38 +08:00
|
|
|
|
2001-04-30 06:43:01 +08:00
|
|
|
static /*@null@*/ void * freeFl(rpmTransactionSet ts, /*@only@*/ /*@null@*/ TFI_t flList)
|
1999-03-01 02:36:19 +08:00
|
|
|
{
|
2001-04-30 06:43:01 +08:00
|
|
|
if (flList) {
|
|
|
|
TFI_t fi;
|
|
|
|
int oc;
|
1999-03-01 02:36:19 +08:00
|
|
|
|
2001-04-30 06:43:01 +08:00
|
|
|
/*@-usereleased@*/
|
|
|
|
for (oc = 0, fi = flList; oc < ts->orderCount; oc++, fi++)
|
|
|
|
freeFi(fi);
|
|
|
|
flList = _free(flList);
|
|
|
|
/*@=usereleased@*/
|
1999-03-01 02:36:19 +08:00
|
|
|
}
|
2001-04-30 06:43:01 +08:00
|
|
|
return NULL;
|
1999-03-01 02:36:19 +08:00
|
|
|
}
|
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
void rpmtransSetScriptFd(rpmTransactionSet ts, FD_t fd)
|
|
|
|
{
|
1999-12-08 05:14:51 +08:00
|
|
|
ts->scriptFd = (fd ? fdLink(fd, "rpmtransSetScriptFd") : NULL);
|
1999-07-14 22:36:10 +08:00
|
|
|
}
|
1999-02-23 08:56:32 +08:00
|
|
|
|
2000-12-13 04:03:45 +08:00
|
|
|
int rpmtransGetKeys(const rpmTransactionSet ts, const void *** ep, int * nep)
|
|
|
|
{
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
if (nep) *nep = ts->orderCount;
|
|
|
|
if (ep) {
|
|
|
|
const void ** e;
|
|
|
|
int oc;
|
|
|
|
|
|
|
|
*ep = e = xmalloc(ts->orderCount * sizeof(*e));
|
|
|
|
for (oc = 0; oc < ts->orderCount; oc++, e++) {
|
|
|
|
struct availablePackage * alp;
|
|
|
|
switch (ts->order[oc].type) {
|
|
|
|
case TR_ADDED:
|
|
|
|
alp = ts->addedPackages.list + ts->order[oc].u.addedIndex;
|
|
|
|
*e = alp->key;
|
|
|
|
break;
|
|
|
|
case TR_REMOVED:
|
|
|
|
*e = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
static rpmProblemSet psCreate(void)
|
|
|
|
{
|
1998-12-19 03:09:38 +08:00
|
|
|
rpmProblemSet probs;
|
1999-03-19 11:39:17 +08:00
|
|
|
|
1999-09-22 01:21:57 +08:00
|
|
|
probs = xmalloc(sizeof(*probs)); /* XXX memory leak */
|
1999-07-14 22:36:10 +08:00
|
|
|
probs->numProblems = probs->numProblemsAlloced = 0;
|
|
|
|
probs->probs = NULL;
|
1999-03-19 11:39:17 +08:00
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
return probs;
|
|
|
|
}
|
1999-04-14 19:28:31 +08:00
|
|
|
|
1999-08-07 05:35:15 +08:00
|
|
|
static void psAppend(rpmProblemSet probs, rpmProblemType type,
|
2001-01-21 23:43:32 +08:00
|
|
|
const struct availablePackage * alp,
|
2000-12-13 04:03:45 +08:00
|
|
|
const char * dn, const char *bn,
|
1999-12-08 05:14:51 +08:00
|
|
|
Header altH, unsigned long ulong1)
|
1999-07-14 22:36:10 +08:00
|
|
|
{
|
2000-12-13 04:03:45 +08:00
|
|
|
rpmProblem p;
|
2001-01-21 23:43:32 +08:00
|
|
|
char *t;
|
2000-12-13 04:03:45 +08:00
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
if (probs->numProblems == probs->numProblemsAlloced) {
|
|
|
|
if (probs->numProblemsAlloced)
|
|
|
|
probs->numProblemsAlloced *= 2;
|
|
|
|
else
|
|
|
|
probs->numProblemsAlloced = 2;
|
1999-09-21 11:22:53 +08:00
|
|
|
probs->probs = xrealloc(probs->probs,
|
1999-07-14 22:36:10 +08:00
|
|
|
probs->numProblemsAlloced * sizeof(*probs->probs));
|
|
|
|
}
|
1999-03-19 11:39:17 +08:00
|
|
|
|
2000-12-13 04:03:45 +08:00
|
|
|
p = probs->probs + probs->numProblems++;
|
|
|
|
p->type = type;
|
2001-01-21 23:43:32 +08:00
|
|
|
p->key = alp->key;
|
2000-12-13 04:03:45 +08:00
|
|
|
p->ulong1 = ulong1;
|
|
|
|
p->ignoreProblem = 0;
|
|
|
|
|
|
|
|
if (dn || bn) {
|
|
|
|
p->str1 =
|
|
|
|
t = xmalloc((dn ? strlen(dn) : 0) + (bn ? strlen(bn) : 0) + 1);
|
|
|
|
if (dn) t = stpcpy(t, dn);
|
|
|
|
if (bn) t = stpcpy(t, bn);
|
|
|
|
} else
|
|
|
|
p->str1 = NULL;
|
|
|
|
|
2001-01-21 23:43:32 +08:00
|
|
|
if (alp) {
|
|
|
|
p->h = headerLink(alp->h);
|
2000-12-13 04:03:45 +08:00
|
|
|
p->pkgNEVR =
|
2001-01-21 23:43:32 +08:00
|
|
|
t = xmalloc(strlen(alp->name) +
|
|
|
|
strlen(alp->version) +
|
|
|
|
strlen(alp->release) + sizeof("--"));
|
|
|
|
t = stpcpy(t, alp->name);
|
2000-12-13 04:03:45 +08:00
|
|
|
t = stpcpy(t, "-");
|
2001-01-21 23:43:32 +08:00
|
|
|
t = stpcpy(t, alp->version);
|
2000-12-13 04:03:45 +08:00
|
|
|
t = stpcpy(t, "-");
|
2001-01-21 23:43:32 +08:00
|
|
|
t = stpcpy(t, alp->release);
|
2000-12-13 04:03:45 +08:00
|
|
|
} else {
|
|
|
|
p->h = NULL;
|
2001-01-21 23:43:32 +08:00
|
|
|
p->pkgNEVR = NULL;
|
2000-12-13 04:03:45 +08:00
|
|
|
}
|
1999-10-20 18:22:46 +08:00
|
|
|
|
2000-12-13 04:03:45 +08:00
|
|
|
if (altH) {
|
2001-04-21 14:02:09 +08:00
|
|
|
const char * n, * v, * r;
|
2000-12-13 04:03:45 +08:00
|
|
|
headerNVR(altH, &n, &v, &r);
|
|
|
|
p->altNEVR =
|
|
|
|
t = xmalloc(strlen(n) + strlen(v) + strlen(r) + sizeof("--"));
|
|
|
|
t = stpcpy(t, n);
|
|
|
|
t = stpcpy(t, "-");
|
|
|
|
t = stpcpy(t, v);
|
|
|
|
t = stpcpy(t, "-");
|
|
|
|
t = stpcpy(t, r);
|
|
|
|
} else
|
|
|
|
p->altNEVR = NULL;
|
1999-10-20 18:22:46 +08:00
|
|
|
}
|
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
static int archOkay(Header h)
|
|
|
|
{
|
|
|
|
void * pkgArch;
|
2000-08-28 03:40:35 +08:00
|
|
|
int type, count;
|
1998-12-19 03:09:38 +08:00
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
/* make sure we're trying to install this on the proper architecture */
|
|
|
|
headerGetEntry(h, RPMTAG_ARCH, &type, (void **) &pkgArch, &count);
|
2000-08-28 03:40:35 +08:00
|
|
|
#ifndef DYING
|
1999-07-14 22:36:10 +08:00
|
|
|
if (type == RPM_INT8_TYPE) {
|
2000-08-28 03:40:35 +08:00
|
|
|
int_8 * pkgArchNum;
|
|
|
|
int archNum;
|
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
/* old arch handling */
|
|
|
|
rpmGetArchInfo(NULL, &archNum);
|
|
|
|
pkgArchNum = pkgArch;
|
|
|
|
if (archNum != *pkgArchNum) {
|
|
|
|
return 0;
|
|
|
|
}
|
2000-08-28 03:40:35 +08:00
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
1999-07-14 22:36:10 +08:00
|
|
|
/* new arch handling */
|
|
|
|
if (!rpmMachineScore(RPM_MACHTABLE_INSTARCH, pkgArch)) {
|
|
|
|
return 0;
|
1998-12-19 03:09:38 +08:00
|
|
|
}
|
1999-07-14 22:36:10 +08:00
|
|
|
}
|
1998-12-19 03:09:38 +08:00
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
return 1;
|
|
|
|
}
|
1999-02-17 12:32:55 +08:00
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
static int osOkay(Header h)
|
|
|
|
{
|
|
|
|
void * pkgOs;
|
|
|
|
int type, count;
|
1999-02-17 12:32:55 +08:00
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
/* make sure we're trying to install this on the proper os */
|
|
|
|
headerGetEntry(h, RPMTAG_OS, &type, (void **) &pkgOs, &count);
|
2000-08-28 03:40:35 +08:00
|
|
|
#ifndef DYING
|
1999-07-14 22:36:10 +08:00
|
|
|
if (type == RPM_INT8_TYPE) {
|
|
|
|
/* v1 packages and v2 packages both used improper OS numbers, so just
|
|
|
|
deal with it hope things work */
|
|
|
|
return 1;
|
2000-08-28 03:40:35 +08:00
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
1999-07-14 22:36:10 +08:00
|
|
|
/* new os handling */
|
|
|
|
if (!rpmMachineScore(RPM_MACHTABLE_INSTOS, pkgOs)) {
|
|
|
|
return 0;
|
1998-12-19 03:09:38 +08:00
|
|
|
}
|
1998-12-27 00:33:51 +08:00
|
|
|
}
|
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
return 1;
|
|
|
|
}
|
1999-01-05 00:44:20 +08:00
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
void rpmProblemSetFree(rpmProblemSet probs)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < probs->numProblems; i++) {
|
2000-12-13 04:03:45 +08:00
|
|
|
rpmProblem p = probs->probs + i;
|
|
|
|
if (p->h) headerFree(p->h);
|
2001-04-04 04:41:09 +08:00
|
|
|
p->pkgNEVR = _free(p->pkgNEVR);
|
|
|
|
p->altNEVR = _free(p->altNEVR);
|
|
|
|
p->str1 = _free(p->str1);
|
1999-01-05 00:44:20 +08:00
|
|
|
}
|
1999-07-14 22:36:10 +08:00
|
|
|
free(probs);
|
|
|
|
}
|
1999-03-06 06:41:10 +08:00
|
|
|
|
2001-02-11 00:47:40 +08:00
|
|
|
static /*@observer@*/ const char *const ftstring (fileTypes ft)
|
1999-07-14 22:36:10 +08:00
|
|
|
{
|
2001-01-09 12:07:49 +08:00
|
|
|
switch (ft) {
|
|
|
|
case XDIR: return "directory";
|
|
|
|
case CDEV: return "char dev";
|
|
|
|
case BDEV: return "block dev";
|
|
|
|
case LINK: return "link";
|
|
|
|
case SOCK: return "sock";
|
|
|
|
case PIPE: return "fifo/pipe";
|
|
|
|
case REG: return "file";
|
2001-01-27 01:06:09 +08:00
|
|
|
default: return "unknown file type";
|
2001-01-09 12:07:49 +08:00
|
|
|
}
|
2001-01-27 01:06:09 +08:00
|
|
|
/*@notreached@*/
|
2001-01-09 12:07:49 +08:00
|
|
|
}
|
|
|
|
|
2001-02-11 00:47:40 +08:00
|
|
|
static fileTypes whatis(uint_16 mode)
|
2001-01-09 12:07:49 +08:00
|
|
|
{
|
|
|
|
if (S_ISDIR(mode)) return XDIR;
|
|
|
|
if (S_ISCHR(mode)) return CDEV;
|
|
|
|
if (S_ISBLK(mode)) return BDEV;
|
|
|
|
if (S_ISLNK(mode)) return LINK;
|
|
|
|
if (S_ISSOCK(mode)) return SOCK;
|
|
|
|
if (S_ISFIFO(mode)) return PIPE;
|
|
|
|
return REG;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define alloca_strdup(_s) strcpy(alloca(strlen(_s)+1), (_s))
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Relocate files in header.
|
|
|
|
* @todo multilib file dispositions need to be checked.
|
|
|
|
* @param ts transaction set
|
2001-04-03 21:41:56 +08:00
|
|
|
* @param fi transaction element file info
|
2001-01-09 12:07:49 +08:00
|
|
|
* @param alp available package
|
|
|
|
* @param origH package header
|
|
|
|
* @param actions file dispositions
|
|
|
|
* @return header with relocated files
|
|
|
|
*/
|
2001-04-03 21:41:56 +08:00
|
|
|
static Header relocateFileList(const rpmTransactionSet ts, TFI_t fi,
|
2001-01-09 12:07:49 +08:00
|
|
|
struct availablePackage * alp,
|
2001-01-28 01:42:24 +08:00
|
|
|
Header origH, fileAction * actions)
|
2001-01-09 12:07:49 +08:00
|
|
|
{
|
2001-04-03 21:41:56 +08:00
|
|
|
HGE_t hge = fi->hge;
|
|
|
|
HFD_t hfd = fi->hfd;
|
2001-01-09 12:07:49 +08:00
|
|
|
static int _printed = 0;
|
|
|
|
rpmProblemSet probs = ts->probs;
|
|
|
|
int allowBadRelocate = (ts->ignoreSet & RPMPROB_FILTER_FORCERELOCATE);
|
1999-07-14 22:36:10 +08:00
|
|
|
rpmRelocation * rawRelocations = alp->relocs;
|
1999-08-07 07:44:25 +08:00
|
|
|
rpmRelocation * relocations = NULL;
|
2001-01-09 12:07:49 +08:00
|
|
|
int numRelocations;
|
1999-08-07 06:52:49 +08:00
|
|
|
const char ** validRelocations;
|
2001-01-09 12:07:49 +08:00
|
|
|
int_32 validType;
|
|
|
|
int numValid;
|
|
|
|
const char ** baseNames;
|
|
|
|
const char ** dirNames;
|
1999-10-09 04:30:49 +08:00
|
|
|
int_32 * dirIndexes;
|
|
|
|
int_32 * newDirIndexes;
|
2001-01-09 12:07:49 +08:00
|
|
|
int_32 fileCount;
|
|
|
|
int_32 dirCount;
|
2000-07-06 04:39:15 +08:00
|
|
|
uint_32 * fFlags = NULL;
|
2001-01-09 12:07:49 +08:00
|
|
|
uint_16 * fModes = NULL;
|
1999-10-09 04:30:49 +08:00
|
|
|
char * skipDirList;
|
1999-07-14 22:36:10 +08:00
|
|
|
Header h;
|
2001-01-09 12:07:49 +08:00
|
|
|
int nrelocated = 0;
|
1999-10-09 04:30:49 +08:00
|
|
|
int fileAlloced = 0;
|
2001-01-09 12:07:49 +08:00
|
|
|
char * fn = NULL;
|
1999-10-09 04:30:49 +08:00
|
|
|
int haveRelocatedFile = 0;
|
2001-04-03 21:41:56 +08:00
|
|
|
int reldel = 0;
|
2001-01-09 12:07:49 +08:00
|
|
|
int len;
|
|
|
|
int i, j;
|
1998-12-27 00:33:51 +08:00
|
|
|
|
2001-04-03 21:41:56 +08:00
|
|
|
if (!hge(origH, RPMTAG_PREFIXES, &validType,
|
1999-07-14 22:36:10 +08:00
|
|
|
(void **) &validRelocations, &numValid))
|
|
|
|
numValid = 0;
|
1998-12-31 00:59:54 +08:00
|
|
|
|
2001-01-09 12:07:49 +08:00
|
|
|
numRelocations = 0;
|
|
|
|
if (rawRelocations)
|
|
|
|
while (rawRelocations[numRelocations].newPath ||
|
|
|
|
rawRelocations[numRelocations].oldPath)
|
|
|
|
numRelocations++;
|
|
|
|
|
2000-11-09 01:07:01 +08:00
|
|
|
/*
|
|
|
|
* If no relocations are specified (usually the case), then return the
|
|
|
|
* original header. If there are prefixes, however, then INSTPREFIXES
|
|
|
|
* should be added, but, since relocateFileList() can be called more
|
|
|
|
* than once for the same header, don't bother if already present.
|
|
|
|
*/
|
2001-01-09 12:07:49 +08:00
|
|
|
if (numRelocations == 0) {
|
|
|
|
if (numValid) {
|
2000-11-09 01:07:01 +08:00
|
|
|
if (!headerIsEntry(origH, RPMTAG_INSTPREFIXES))
|
|
|
|
headerAddEntry(origH, RPMTAG_INSTPREFIXES,
|
2001-01-09 12:07:49 +08:00
|
|
|
validType, validRelocations, numValid);
|
2001-04-03 21:41:56 +08:00
|
|
|
validRelocations = hfd(validRelocations, validType);
|
2000-11-09 01:07:01 +08:00
|
|
|
}
|
|
|
|
/* XXX FIXME multilib file actions need to be checked. */
|
|
|
|
return headerLink(origH);
|
1999-09-21 11:22:53 +08:00
|
|
|
}
|
1999-03-10 11:43:22 +08:00
|
|
|
|
2000-12-13 04:03:45 +08:00
|
|
|
#ifdef DYING
|
1999-07-14 22:36:10 +08:00
|
|
|
h = headerCopy(origH);
|
2000-12-13 04:03:45 +08:00
|
|
|
#else
|
|
|
|
h = headerLink(origH);
|
|
|
|
#endif
|
1999-04-05 05:26:36 +08:00
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
relocations = alloca(sizeof(*relocations) * numRelocations);
|
1999-04-05 05:26:36 +08:00
|
|
|
|
1999-08-07 07:44:25 +08:00
|
|
|
/* Build sorted relocation list from raw relocations. */
|
1999-07-14 22:36:10 +08:00
|
|
|
for (i = 0; i < numRelocations; i++) {
|
2001-04-03 21:41:56 +08:00
|
|
|
char * t;
|
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
/* FIXME: default relocations (oldPath == NULL) need to be handled
|
|
|
|
in the UI, not rpmlib */
|
|
|
|
|
1999-10-09 04:30:49 +08:00
|
|
|
/* FIXME: Trailing /'s will confuse us greatly. Internal ones will
|
|
|
|
too, but those are more trouble to fix up. :-( */
|
2001-04-03 21:41:56 +08:00
|
|
|
t = alloca_strdup(rawRelocations[i].oldPath);
|
|
|
|
relocations[i].oldPath = (t[0] == '/' && t[1] == '\0')
|
|
|
|
? t
|
|
|
|
: stripTrailingChar(t, '/');
|
1999-07-14 22:36:10 +08:00
|
|
|
|
1999-10-09 04:30:49 +08:00
|
|
|
/* An old path w/o a new path is valid, and indicates exclusion */
|
1999-07-14 22:36:10 +08:00
|
|
|
if (rawRelocations[i].newPath) {
|
2001-04-03 21:41:56 +08:00
|
|
|
int del;
|
|
|
|
|
|
|
|
t = alloca_strdup(rawRelocations[i].newPath);
|
|
|
|
relocations[i].newPath = (t[0] == '/' && t[1] == '\0')
|
|
|
|
? t
|
|
|
|
: stripTrailingChar(t, '/');
|
1999-01-19 11:01:52 +08:00
|
|
|
|
1999-08-07 07:44:25 +08:00
|
|
|
/* Verify that the relocation's old path is in the header. */
|
1999-08-07 05:35:15 +08:00
|
|
|
for (j = 0; j < numValid; j++)
|
1999-08-14 04:05:57 +08:00
|
|
|
if (!strcmp(validRelocations[j], relocations[i].oldPath)) break;
|
2001-01-09 12:07:49 +08:00
|
|
|
/* XXX actions check prevents problem from being appended twice. */
|
|
|
|
if (j == numValid && !allowBadRelocate && actions)
|
2001-01-21 23:43:32 +08:00
|
|
|
psAppend(probs, RPMPROB_BADRELOCATE, alp,
|
2000-12-13 04:03:45 +08:00
|
|
|
relocations[i].oldPath, NULL, NULL, 0);
|
2001-04-03 21:41:56 +08:00
|
|
|
del =
|
|
|
|
strlen(relocations[i].newPath) - strlen(relocations[i].oldPath);
|
|
|
|
if (del > reldel)
|
|
|
|
reldel = del;
|
1999-08-07 08:07:51 +08:00
|
|
|
} else {
|
|
|
|
relocations[i].newPath = NULL;
|
1999-04-05 05:26:36 +08:00
|
|
|
}
|
1999-07-14 22:36:10 +08:00
|
|
|
}
|
1999-02-23 06:15:19 +08:00
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
/* stupid bubble sort, but it's probably faster here */
|
|
|
|
for (i = 0; i < numRelocations; i++) {
|
1999-08-07 06:52:49 +08:00
|
|
|
int madeSwap;
|
1999-07-14 22:36:10 +08:00
|
|
|
madeSwap = 0;
|
|
|
|
for (j = 1; j < numRelocations; j++) {
|
1999-08-07 06:52:49 +08:00
|
|
|
rpmRelocation tmpReloc;
|
1999-08-14 04:05:57 +08:00
|
|
|
if (strcmp(relocations[j - 1].oldPath, relocations[j].oldPath) <= 0)
|
|
|
|
continue;
|
|
|
|
tmpReloc = relocations[j - 1];
|
|
|
|
relocations[j - 1] = relocations[j];
|
|
|
|
relocations[j] = tmpReloc;
|
|
|
|
madeSwap = 1;
|
1999-07-14 22:36:10 +08:00
|
|
|
}
|
|
|
|
if (!madeSwap) break;
|
|
|
|
}
|
1999-02-23 06:15:19 +08:00
|
|
|
|
2001-01-09 12:07:49 +08:00
|
|
|
if (!_printed) {
|
|
|
|
_printed = 1;
|
|
|
|
rpmMessage(RPMMESS_DEBUG, _("========== relocations\n"));
|
|
|
|
for (i = 0; i < numRelocations; i++) {
|
|
|
|
if (relocations[i].newPath == NULL)
|
|
|
|
rpmMessage(RPMMESS_DEBUG, _("%5d exclude %s\n"),
|
|
|
|
i, relocations[i].oldPath);
|
|
|
|
else
|
|
|
|
rpmMessage(RPMMESS_DEBUG, _("%5d relocate %s -> %s\n"),
|
|
|
|
i, relocations[i].oldPath, relocations[i].newPath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-08-07 07:44:25 +08:00
|
|
|
/* Add relocation values to the header */
|
1999-07-14 22:36:10 +08:00
|
|
|
if (numValid) {
|
1999-08-07 06:52:49 +08:00
|
|
|
const char ** actualRelocations;
|
2000-02-22 20:05:13 +08:00
|
|
|
int numActual;
|
1999-10-09 04:30:49 +08:00
|
|
|
|
2001-04-30 06:43:01 +08:00
|
|
|
actualRelocations = xmalloc(numValid * sizeof(*actualRelocations));
|
2000-02-22 20:05:13 +08:00
|
|
|
numActual = 0;
|
1999-07-14 22:36:10 +08:00
|
|
|
for (i = 0; i < numValid; i++) {
|
|
|
|
for (j = 0; j < numRelocations; j++) {
|
1999-08-14 04:05:57 +08:00
|
|
|
if (strcmp(validRelocations[i], relocations[j].oldPath))
|
|
|
|
continue;
|
2000-02-22 20:05:13 +08:00
|
|
|
/* On install, a relocate to NULL means skip the path. */
|
|
|
|
if (relocations[j].newPath) {
|
|
|
|
actualRelocations[numActual] = relocations[j].newPath;
|
|
|
|
numActual++;
|
|
|
|
}
|
1999-08-14 04:05:57 +08:00
|
|
|
break;
|
1999-07-14 22:36:10 +08:00
|
|
|
}
|
2000-02-22 20:05:13 +08:00
|
|
|
if (j == numRelocations) {
|
|
|
|
actualRelocations[numActual] = validRelocations[i];
|
|
|
|
numActual++;
|
|
|
|
}
|
1999-01-05 00:44:20 +08:00
|
|
|
}
|
1999-02-23 06:15:19 +08:00
|
|
|
|
2000-02-22 20:05:13 +08:00
|
|
|
if (numActual)
|
|
|
|
headerAddEntry(h, RPMTAG_INSTPREFIXES, RPM_STRING_ARRAY_TYPE,
|
|
|
|
(void **) actualRelocations, numActual);
|
1999-07-14 22:36:10 +08:00
|
|
|
|
2001-04-04 04:41:09 +08:00
|
|
|
actualRelocations = _free(actualRelocations);
|
2001-04-03 21:41:56 +08:00
|
|
|
validRelocations = hfd(validRelocations, validType);
|
1999-01-05 00:44:20 +08:00
|
|
|
}
|
1999-03-06 06:41:10 +08:00
|
|
|
|
2001-04-03 21:41:56 +08:00
|
|
|
hge(h, RPMTAG_BASENAMES, NULL, (void **) &baseNames, &fileCount);
|
|
|
|
hge(h, RPMTAG_DIRINDEXES, NULL, (void **) &dirIndexes, NULL);
|
|
|
|
hge(h, RPMTAG_DIRNAMES, NULL, (void **) &dirNames, &dirCount);
|
|
|
|
hge(h, RPMTAG_FILEFLAGS, NULL, (void **) &fFlags, NULL);
|
|
|
|
hge(h, RPMTAG_FILEMODES, NULL, (void **) &fModes, NULL);
|
2000-07-06 04:39:15 +08:00
|
|
|
|
2001-01-09 12:07:49 +08:00
|
|
|
skipDirList = alloca(dirCount * sizeof(*skipDirList));
|
|
|
|
memset(skipDirList, 0, dirCount * sizeof(*skipDirList));
|
1999-10-09 04:30:49 +08:00
|
|
|
|
|
|
|
newDirIndexes = alloca(sizeof(*newDirIndexes) * fileCount);
|
1999-10-18 04:59:39 +08:00
|
|
|
memcpy(newDirIndexes, dirIndexes, sizeof(*newDirIndexes) * fileCount);
|
1999-10-09 04:30:49 +08:00
|
|
|
dirIndexes = newDirIndexes;
|
|
|
|
|
2001-01-09 12:07:49 +08:00
|
|
|
/*
|
|
|
|
* For all relocations, we go through sorted file/relocation lists
|
|
|
|
* backwards so that /usr/local relocations take precedence over /usr
|
|
|
|
* ones.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Relocate individual paths. */
|
1999-10-09 04:30:49 +08:00
|
|
|
|
|
|
|
for (i = fileCount - 1; i >= 0; i--) {
|
2001-04-03 21:41:56 +08:00
|
|
|
fileTypes ft;
|
|
|
|
int fnlen;
|
2000-07-06 04:39:15 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If only adding libraries of different arch into an already
|
|
|
|
* installed package, skip all other files.
|
|
|
|
*/
|
2001-01-09 12:07:49 +08:00
|
|
|
if (alp->multiLib && !isFileMULTILIB((fFlags[i]))) {
|
|
|
|
if (actions) {
|
|
|
|
actions[i] = FA_SKIPMULTILIB;
|
|
|
|
rpmMessage(RPMMESS_DEBUG, _("excluding multilib path %s%s\n"),
|
|
|
|
dirNames[dirIndexes[i]], baseNames[i]);
|
|
|
|
}
|
2000-07-06 04:39:15 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2001-04-03 21:41:56 +08:00
|
|
|
len = reldel +
|
|
|
|
strlen(dirNames[dirIndexes[i]]) + strlen(baseNames[i]) + 1;
|
1999-10-09 04:30:49 +08:00
|
|
|
if (len >= fileAlloced) {
|
|
|
|
fileAlloced = len * 2;
|
2001-01-09 12:07:49 +08:00
|
|
|
fn = xrealloc(fn, fileAlloced);
|
1999-10-09 04:30:49 +08:00
|
|
|
}
|
2001-04-04 04:41:09 +08:00
|
|
|
*fn = '\0';
|
|
|
|
fnlen = stpcpy( stpcpy(fn, dirNames[dirIndexes[i]]), baseNames[i]) - fn;
|
1999-10-09 04:30:49 +08:00
|
|
|
|
2001-01-09 12:07:49 +08:00
|
|
|
/*
|
2001-04-03 21:41:56 +08:00
|
|
|
* See if this file path needs relocating.
|
2001-01-09 12:07:49 +08:00
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* XXX FIXME: Would a bsearch of the (already sorted)
|
|
|
|
* relocation list be a good idea?
|
|
|
|
*/
|
|
|
|
for (j = numRelocations - 1; j >= 0; j--) {
|
2001-04-03 21:41:56 +08:00
|
|
|
len = strcmp(relocations[j].oldPath, "/")
|
|
|
|
? strlen(relocations[j].oldPath)
|
|
|
|
: 0;
|
|
|
|
|
|
|
|
if (fnlen < len)
|
2001-01-09 12:07:49 +08:00
|
|
|
continue;
|
2001-04-03 21:41:56 +08:00
|
|
|
/*
|
|
|
|
* Only subdirectories or complete file paths may be relocated. We
|
|
|
|
* don't check for '\0' as our directory names all end in '/'.
|
|
|
|
*/
|
|
|
|
if (!(fn[len] == '/' || fnlen == len))
|
|
|
|
continue;
|
|
|
|
|
2001-01-09 12:07:49 +08:00
|
|
|
if (strncmp(relocations[j].oldPath, fn, len))
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
}
|
1999-10-09 04:30:49 +08:00
|
|
|
if (j < 0) continue;
|
|
|
|
|
2001-04-03 21:41:56 +08:00
|
|
|
ft = whatis(fModes[i]);
|
|
|
|
|
2001-01-09 12:07:49 +08:00
|
|
|
/* On install, a relocate to NULL means skip the path. */
|
|
|
|
if (relocations[j].newPath == NULL) {
|
|
|
|
if (ft == XDIR) {
|
|
|
|
/* Start with the parent, looking for directory to exclude. */
|
2001-04-04 04:41:09 +08:00
|
|
|
for (j = dirIndexes[i]; j < dirCount; j++) {
|
|
|
|
len = strlen(dirNames[j]) - 1;
|
|
|
|
while (len > 0 && dirNames[j][len-1] == '/') len--;
|
|
|
|
if (fnlen != len)
|
|
|
|
continue;
|
|
|
|
if (strncmp(fn, dirNames[j], fnlen))
|
|
|
|
continue;
|
|
|
|
break;
|
2001-01-09 12:07:49 +08:00
|
|
|
}
|
2001-04-04 04:41:09 +08:00
|
|
|
if (j < dirCount)
|
|
|
|
skipDirList[j] = 1;
|
2001-01-09 12:07:49 +08:00
|
|
|
}
|
|
|
|
if (actions) {
|
|
|
|
actions[i] = FA_SKIPNSTATE;
|
|
|
|
rpmMessage(RPMMESS_DEBUG, _("excluding %s %s\n"),
|
|
|
|
ftstring(ft), fn);
|
|
|
|
}
|
1999-10-09 04:30:49 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2001-04-04 04:41:09 +08:00
|
|
|
/* Relocation on full paths only, please. */
|
2001-04-03 21:41:56 +08:00
|
|
|
if (fnlen != len) continue;
|
|
|
|
|
2001-01-09 12:07:49 +08:00
|
|
|
if (actions)
|
|
|
|
rpmMessage(RPMMESS_DEBUG, _("relocating %s to %s\n"),
|
|
|
|
fn, relocations[j].newPath);
|
|
|
|
nrelocated++;
|
1999-10-09 04:30:49 +08:00
|
|
|
|
2001-01-09 12:07:49 +08:00
|
|
|
strcpy(fn, relocations[j].newPath);
|
2001-04-04 04:41:09 +08:00
|
|
|
{ char * te = strrchr(fn, '/');
|
|
|
|
if (te) {
|
|
|
|
if (te > fn) te++; /* root is special */
|
|
|
|
fnlen = te - fn;
|
|
|
|
} else
|
|
|
|
te = fn + strlen(fn);
|
|
|
|
if (strcmp(baseNames[i], te)) /* basename changed too? */
|
|
|
|
baseNames[i] = alloca_strdup(te);
|
|
|
|
*te = '\0'; /* terminate new directory name */
|
2001-04-21 14:02:09 +08:00
|
|
|
}
|
1999-10-09 04:30:49 +08:00
|
|
|
|
|
|
|
/* Does this directory already exist in the directory list? */
|
2001-04-04 04:41:09 +08:00
|
|
|
for (j = 0; j < dirCount; j++) {
|
|
|
|
if (fnlen != strlen(dirNames[j]))
|
|
|
|
continue;
|
|
|
|
if (strncmp(fn, dirNames[j], fnlen))
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
}
|
1999-10-09 04:30:49 +08:00
|
|
|
|
|
|
|
if (j < dirCount) {
|
|
|
|
dirIndexes[i] = j;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Creating new paths is a pita */
|
|
|
|
if (!haveRelocatedFile) {
|
2001-01-09 12:07:49 +08:00
|
|
|
const char ** newDirList;
|
1999-10-09 04:30:49 +08:00
|
|
|
|
|
|
|
haveRelocatedFile = 1;
|
2001-04-30 06:43:01 +08:00
|
|
|
newDirList = xmalloc((dirCount + 1) * sizeof(*newDirList));
|
2001-04-04 04:41:09 +08:00
|
|
|
for (j = 0; j < dirCount; j++)
|
|
|
|
newDirList[j] = alloca_strdup(dirNames[j]);
|
2001-04-03 21:41:56 +08:00
|
|
|
dirNames = hfd(dirNames, RPM_STRING_ARRAY_TYPE);
|
1999-10-09 04:30:49 +08:00
|
|
|
dirNames = newDirList;
|
|
|
|
} else {
|
1999-10-21 23:04:25 +08:00
|
|
|
dirNames = xrealloc(dirNames,
|
1999-10-09 04:30:49 +08:00
|
|
|
sizeof(*dirNames) * (dirCount + 1));
|
|
|
|
}
|
|
|
|
|
2001-01-09 12:07:49 +08:00
|
|
|
dirNames[dirCount] = alloca_strdup(fn);
|
1999-10-09 04:30:49 +08:00
|
|
|
dirIndexes[i] = dirCount;
|
|
|
|
dirCount++;
|
|
|
|
}
|
|
|
|
|
2001-01-09 12:07:49 +08:00
|
|
|
/* Finish off by relocating directories. */
|
1999-10-18 04:59:39 +08:00
|
|
|
for (i = dirCount - 1; i >= 0; i--) {
|
|
|
|
for (j = numRelocations - 1; j >= 0; j--) {
|
|
|
|
|
2001-04-03 21:41:56 +08:00
|
|
|
len = strcmp(relocations[j].oldPath, "/")
|
|
|
|
? strlen(relocations[j].oldPath)
|
|
|
|
: 0;
|
|
|
|
|
|
|
|
if (len && strncmp(relocations[j].oldPath, dirNames[i], len))
|
1999-10-18 04:59:39 +08:00
|
|
|
continue;
|
|
|
|
|
2001-01-09 12:07:49 +08:00
|
|
|
/*
|
|
|
|
* Only subdirectories or complete file paths may be relocated. We
|
|
|
|
* don't check for '\0' as our directory names all end in '/'.
|
|
|
|
*/
|
2001-04-03 21:41:56 +08:00
|
|
|
if (dirNames[i][len] != '/')
|
1999-10-18 04:59:39 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (relocations[j].newPath) { /* Relocate the path */
|
2001-04-04 04:41:09 +08:00
|
|
|
const char * s = relocations[j].newPath;
|
|
|
|
char * t = alloca(strlen(s) + strlen(dirNames[i]) - len + 1);
|
1999-10-18 04:59:39 +08:00
|
|
|
|
2001-04-03 21:41:56 +08:00
|
|
|
(void) stpcpy( stpcpy(t, s) , dirNames[i] + len);
|
2001-01-09 12:07:49 +08:00
|
|
|
if (actions)
|
|
|
|
rpmMessage(RPMMESS_DEBUG,
|
|
|
|
_("relocating directory %s to %s\n"), dirNames[i], t);
|
1999-10-18 04:59:39 +08:00
|
|
|
dirNames[i] = t;
|
2001-01-09 12:07:49 +08:00
|
|
|
nrelocated++;
|
1999-10-18 04:59:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-10-09 04:30:49 +08:00
|
|
|
|
1999-08-07 07:44:25 +08:00
|
|
|
/* Save original filenames in header and replace (relocated) filenames. */
|
2001-01-09 12:07:49 +08:00
|
|
|
if (nrelocated) {
|
1999-10-18 04:59:39 +08:00
|
|
|
int c;
|
|
|
|
void * p;
|
|
|
|
int t;
|
|
|
|
|
1999-12-08 05:14:51 +08:00
|
|
|
p = NULL;
|
2001-04-03 21:41:56 +08:00
|
|
|
hge(h, RPMTAG_BASENAMES, &t, &p, &c);
|
1999-12-09 03:04:50 +08:00
|
|
|
headerAddEntry(h, RPMTAG_ORIGBASENAMES, t, p, c);
|
2001-04-03 21:41:56 +08:00
|
|
|
p = hfd(p, t);
|
1999-10-18 04:59:39 +08:00
|
|
|
|
1999-12-08 05:14:51 +08:00
|
|
|
p = NULL;
|
2001-04-03 21:41:56 +08:00
|
|
|
hge(h, RPMTAG_DIRNAMES, &t, &p, &c);
|
1999-12-09 03:04:50 +08:00
|
|
|
headerAddEntry(h, RPMTAG_ORIGDIRNAMES, t, p, c);
|
2001-04-03 21:41:56 +08:00
|
|
|
p = hfd(p, t);
|
1999-12-08 05:14:51 +08:00
|
|
|
|
|
|
|
p = NULL;
|
2001-04-03 21:41:56 +08:00
|
|
|
hge(h, RPMTAG_DIRINDEXES, &t, &p, &c);
|
1999-12-09 03:04:50 +08:00
|
|
|
headerAddEntry(h, RPMTAG_ORIGDIRINDEXES, t, p, c);
|
2001-04-03 21:41:56 +08:00
|
|
|
p = hfd(p, t);
|
1999-10-09 04:30:49 +08:00
|
|
|
|
1999-12-09 03:04:50 +08:00
|
|
|
headerModifyEntry(h, RPMTAG_BASENAMES, RPM_STRING_ARRAY_TYPE,
|
1999-11-27 05:58:42 +08:00
|
|
|
baseNames, fileCount);
|
2001-04-03 21:41:56 +08:00
|
|
|
fi->bnl = hfd(fi->bnl, RPM_STRING_ARRAY_TYPE);
|
|
|
|
hge(h, RPMTAG_BASENAMES, NULL, (void **) &fi->bnl, &fi->fc);
|
2001-04-21 14:02:09 +08:00
|
|
|
|
1999-12-09 03:04:50 +08:00
|
|
|
headerModifyEntry(h, RPMTAG_DIRNAMES, RPM_STRING_ARRAY_TYPE,
|
1999-10-09 04:30:49 +08:00
|
|
|
dirNames, dirCount);
|
2001-04-03 21:41:56 +08:00
|
|
|
fi->dnl = hfd(fi->dnl, RPM_STRING_ARRAY_TYPE);
|
|
|
|
hge(h, RPMTAG_DIRNAMES, NULL, (void **) &fi->dnl, &fi->dc);
|
|
|
|
|
1999-12-09 03:04:50 +08:00
|
|
|
headerModifyEntry(h, RPMTAG_DIRINDEXES, RPM_INT32_TYPE,
|
1999-12-08 05:14:51 +08:00
|
|
|
dirIndexes, fileCount);
|
2001-04-03 21:41:56 +08:00
|
|
|
hge(h, RPMTAG_DIRINDEXES, NULL, (void **) &fi->dil, NULL);
|
1999-07-14 22:36:10 +08:00
|
|
|
}
|
1999-04-14 06:47:44 +08:00
|
|
|
|
2001-04-03 21:41:56 +08:00
|
|
|
baseNames = hfd(baseNames, RPM_STRING_ARRAY_TYPE);
|
|
|
|
dirNames = hfd(dirNames, RPM_STRING_ARRAY_TYPE);
|
2001-04-21 14:02:09 +08:00
|
|
|
fn = _free(fn);
|
1999-10-09 04:30:49 +08:00
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
return h;
|
|
|
|
}
|
1998-12-31 07:03:43 +08:00
|
|
|
|
2000-12-13 04:03:45 +08:00
|
|
|
/*
|
|
|
|
* As the problem sets are generated in an order solely dependent
|
|
|
|
* on the ordering of the packages in the transaction, and that
|
|
|
|
* ordering can't be changed, the problem sets must be parallel to
|
|
|
|
* one another. Additionally, the filter set must be a subset of the
|
|
|
|
* target set, given the operations available on transaction set.
|
|
|
|
* This is good, as it lets us perform this trim in linear time, rather
|
|
|
|
* then logarithmic or quadratic.
|
|
|
|
*/
|
1999-07-14 22:36:10 +08:00
|
|
|
static int psTrim(rpmProblemSet filter, rpmProblemSet target)
|
|
|
|
{
|
2000-12-13 04:03:45 +08:00
|
|
|
rpmProblem f = filter->probs;
|
|
|
|
rpmProblem t = target->probs;
|
1999-07-14 22:36:10 +08:00
|
|
|
int gotProblems = 0;
|
1998-12-31 07:03:43 +08:00
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
while ((f - filter->probs) < filter->numProblems) {
|
|
|
|
if (!f->ignoreProblem) {
|
|
|
|
f++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
while ((t - target->probs) < target->numProblems) {
|
|
|
|
if (f->h == t->h && f->type == t->type && t->key == f->key &&
|
|
|
|
XSTRCMP(f->str1, t->str1))
|
|
|
|
break;
|
|
|
|
t++;
|
|
|
|
gotProblems = 1;
|
1998-12-31 07:03:43 +08:00
|
|
|
}
|
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
if ((t - target->probs) == target->numProblems) {
|
|
|
|
/* this can't happen ;-) lets be sane if it doesn though */
|
|
|
|
break;
|
|
|
|
}
|
1999-01-05 00:44:20 +08:00
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
t->ignoreProblem = f->ignoreProblem;
|
|
|
|
t++, f++;
|
|
|
|
}
|
1998-12-31 00:59:54 +08:00
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
if ((t - target->probs) < target->numProblems)
|
|
|
|
gotProblems = 1;
|
1998-12-31 07:03:43 +08:00
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
return gotProblems;
|
|
|
|
}
|
1998-12-27 00:33:51 +08:00
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
static int sharedCmp(const void * one, const void * two)
|
|
|
|
{
|
|
|
|
const struct sharedFileInfo * a = one;
|
|
|
|
const struct sharedFileInfo * b = two;
|
1998-12-31 07:03:43 +08:00
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
if (a->otherPkg < b->otherPkg)
|
|
|
|
return -1;
|
|
|
|
else if (a->otherPkg > b->otherPkg)
|
|
|
|
return 1;
|
1999-03-19 11:39:17 +08:00
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
return 0;
|
|
|
|
}
|
1999-03-19 11:39:17 +08:00
|
|
|
|
2001-01-28 01:42:24 +08:00
|
|
|
static fileAction decideFileFate(const char * dirName,
|
1999-10-20 18:22:46 +08:00
|
|
|
const char * baseName, short dbMode,
|
1999-08-14 04:05:57 +08:00
|
|
|
const char * dbMd5, const char * dbLink, short newMode,
|
|
|
|
const char * newMd5, const char * newLink, int newFlags,
|
2000-08-30 06:04:33 +08:00
|
|
|
int brokenMd5, rpmtransFlags transFlags)
|
1999-07-14 22:36:10 +08:00
|
|
|
{
|
|
|
|
char buffer[1024];
|
1999-08-14 04:05:57 +08:00
|
|
|
const char * dbAttr, * newAttr;
|
2001-02-11 00:47:40 +08:00
|
|
|
fileTypes dbWhat, newWhat, diskWhat;
|
1999-07-14 22:36:10 +08:00
|
|
|
struct stat sb;
|
|
|
|
int i, rc;
|
|
|
|
int save = (newFlags & RPMFILE_NOREPLACE) ? FA_ALTNAME : FA_SAVE;
|
1999-10-21 10:40:57 +08:00
|
|
|
char * filespec = alloca(strlen(dirName) + strlen(baseName) + 1);
|
1999-10-20 18:22:46 +08:00
|
|
|
|
2000-10-21 00:47:00 +08:00
|
|
|
(void) stpcpy( stpcpy(filespec, dirName), baseName);
|
1998-12-27 02:32:08 +08:00
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
if (lstat(filespec, &sb)) {
|
1999-09-22 01:21:57 +08:00
|
|
|
/*
|
|
|
|
* The file doesn't exist on the disk. Create it unless the new
|
|
|
|
* package has marked it as missingok, or allfiles is requested.
|
|
|
|
*/
|
|
|
|
if (!(transFlags & RPMTRANS_FLAG_ALLFILES) &&
|
|
|
|
(newFlags & RPMFILE_MISSINGOK)) {
|
1999-07-14 22:36:10 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, _("%s skipped due to missingok flag\n"),
|
|
|
|
filespec);
|
|
|
|
return FA_SKIP;
|
1999-08-17 06:10:27 +08:00
|
|
|
} else {
|
1999-07-14 22:36:10 +08:00
|
|
|
return FA_CREATE;
|
1999-08-17 06:10:27 +08:00
|
|
|
}
|
1998-12-31 00:59:54 +08:00
|
|
|
}
|
1999-03-06 06:41:10 +08:00
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
diskWhat = whatis(sb.st_mode);
|
|
|
|
dbWhat = whatis(dbMode);
|
|
|
|
newWhat = whatis(newMode);
|
1999-01-01 03:16:31 +08:00
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
/* RPM >= 2.3.10 shouldn't create config directories -- we'll ignore
|
|
|
|
them in older packages as well */
|
1999-08-17 06:10:27 +08:00
|
|
|
if (newWhat == XDIR) {
|
1999-07-14 22:36:10 +08:00
|
|
|
return FA_CREATE;
|
1999-08-17 06:10:27 +08:00
|
|
|
}
|
1999-01-01 03:16:31 +08:00
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
if (diskWhat != newWhat) {
|
|
|
|
return save;
|
|
|
|
} else if (newWhat != dbWhat && diskWhat != dbWhat) {
|
|
|
|
return save;
|
|
|
|
} else if (dbWhat != newWhat) {
|
|
|
|
return FA_CREATE;
|
|
|
|
} else if (dbWhat != LINK && dbWhat != REG) {
|
|
|
|
return FA_CREATE;
|
1998-12-19 03:09:38 +08:00
|
|
|
}
|
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
if (dbWhat == REG) {
|
|
|
|
if (brokenMd5)
|
|
|
|
rc = mdfileBroken(filespec, buffer);
|
|
|
|
else
|
|
|
|
rc = mdfile(filespec, buffer);
|
1999-01-12 11:11:25 +08:00
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
if (rc) {
|
|
|
|
/* assume the file has been removed, don't freak */
|
|
|
|
return FA_CREATE;
|
|
|
|
}
|
|
|
|
dbAttr = dbMd5;
|
|
|
|
newAttr = newMd5;
|
|
|
|
} else /* dbWhat == LINK */ {
|
|
|
|
memset(buffer, 0, sizeof(buffer));
|
|
|
|
i = readlink(filespec, buffer, sizeof(buffer) - 1);
|
|
|
|
if (i == -1) {
|
|
|
|
/* assume the file has been removed, don't freak */
|
|
|
|
return FA_CREATE;
|
|
|
|
}
|
|
|
|
dbAttr = dbLink;
|
|
|
|
newAttr = newLink;
|
|
|
|
}
|
1999-01-01 03:16:31 +08:00
|
|
|
|
1999-08-07 05:35:15 +08:00
|
|
|
/* this order matters - we'd prefer to CREATE the file if at all
|
1999-07-14 22:36:10 +08:00
|
|
|
possible in case something else (like the timestamp) has changed */
|
1999-02-23 06:15:19 +08:00
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
if (!strcmp(dbAttr, buffer)) {
|
1999-09-22 01:21:57 +08:00
|
|
|
/* this config file has never been modified, so just replace it */
|
1999-07-14 22:36:10 +08:00
|
|
|
return FA_CREATE;
|
1999-02-25 07:55:00 +08:00
|
|
|
}
|
1999-03-06 06:41:10 +08:00
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
if (!strcmp(dbAttr, newAttr)) {
|
|
|
|
/* this file is the same in all versions of this package */
|
|
|
|
return FA_SKIP;
|
|
|
|
}
|
1999-03-01 02:36:19 +08:00
|
|
|
|
1999-09-22 01:21:57 +08:00
|
|
|
/*
|
|
|
|
* The config file on the disk has been modified, but
|
|
|
|
* the ones in the two packages are different. It would
|
|
|
|
* be nice if RPM was smart enough to at least try and
|
|
|
|
* merge the difference ala CVS, but...
|
|
|
|
*/
|
1999-07-14 22:36:10 +08:00
|
|
|
return save;
|
1998-12-19 03:09:38 +08:00
|
|
|
}
|
|
|
|
|
1999-08-14 04:05:57 +08:00
|
|
|
static int filecmp(short mode1, const char * md51, const char * link1,
|
|
|
|
short mode2, const char * md52, const char * link2)
|
1999-07-14 22:36:10 +08:00
|
|
|
{
|
2001-02-11 00:47:40 +08:00
|
|
|
fileTypes what1 = whatis(mode1);
|
|
|
|
fileTypes what2 = whatis(mode2);
|
1998-12-19 03:09:38 +08:00
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
if (what1 != what2) return 1;
|
1998-12-19 03:09:38 +08:00
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
if (what1 == LINK)
|
|
|
|
return strcmp(link1, link2);
|
|
|
|
else if (what1 == REG)
|
|
|
|
return strcmp(md51, md52);
|
|
|
|
|
|
|
|
return 0;
|
1998-12-19 03:09:38 +08:00
|
|
|
}
|
|
|
|
|
2001-01-21 23:43:32 +08:00
|
|
|
static int handleInstInstalledFiles(TFI_t fi, rpmdb db,
|
1999-07-14 22:36:10 +08:00
|
|
|
struct sharedFileInfo * shared,
|
|
|
|
int sharedCount, int reportConflicts,
|
2000-08-30 06:04:33 +08:00
|
|
|
rpmProblemSet probs,
|
|
|
|
rpmtransFlags transFlags)
|
1999-07-14 22:36:10 +08:00
|
|
|
{
|
2001-02-05 06:15:30 +08:00
|
|
|
HGE_t hge = fi->hge;
|
|
|
|
HFD_t hfd = fi->hfd;
|
|
|
|
int oltype, omtype;
|
1999-07-14 22:36:10 +08:00
|
|
|
Header h;
|
|
|
|
int i;
|
1999-08-14 04:05:57 +08:00
|
|
|
const char ** otherMd5s;
|
|
|
|
const char ** otherLinks;
|
|
|
|
const char * otherStates;
|
|
|
|
uint_32 * otherFlags;
|
|
|
|
uint_32 * otherSizes;
|
1999-07-14 22:36:10 +08:00
|
|
|
uint_16 * otherModes;
|
|
|
|
int numReplaced = 0;
|
1998-12-19 03:09:38 +08:00
|
|
|
|
2000-04-27 08:10:28 +08:00
|
|
|
rpmdbMatchIterator mi;
|
|
|
|
|
|
|
|
mi = rpmdbInitIterator(db, RPMDBI_PACKAGES, &shared->otherPkg, sizeof(shared->otherPkg));
|
|
|
|
h = rpmdbNextIterator(mi);
|
|
|
|
if (h == NULL) {
|
2001-04-30 06:43:01 +08:00
|
|
|
mi = rpmdbFreeIterator(mi);
|
2000-04-27 08:10:28 +08:00
|
|
|
return 1;
|
|
|
|
}
|
1999-01-06 11:16:35 +08:00
|
|
|
|
2001-02-05 06:15:30 +08:00
|
|
|
hge(h, RPMTAG_FILEMD5S, &omtype, (void **) &otherMd5s, NULL);
|
|
|
|
hge(h, RPMTAG_FILELINKTOS, &oltype, (void **) &otherLinks, NULL);
|
|
|
|
hge(h, RPMTAG_FILESTATES, NULL, (void **) &otherStates, NULL);
|
|
|
|
hge(h, RPMTAG_FILEMODES, NULL, (void **) &otherModes, NULL);
|
|
|
|
hge(h, RPMTAG_FILEFLAGS, NULL, (void **) &otherFlags, NULL);
|
|
|
|
hge(h, RPMTAG_FILESIZES, NULL, (void **) &otherSizes, NULL);
|
1999-01-06 11:16:35 +08:00
|
|
|
|
2001-04-30 06:43:01 +08:00
|
|
|
fi->replaced = xmalloc(sharedCount * sizeof(*fi->replaced));
|
1998-12-19 03:09:38 +08:00
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
for (i = 0; i < sharedCount; i++, shared++) {
|
1999-08-14 04:05:57 +08:00
|
|
|
int otherFileNum, fileNum;
|
1999-07-14 22:36:10 +08:00
|
|
|
otherFileNum = shared->otherFileNum;
|
|
|
|
fileNum = shared->pkgFileNum;
|
1999-08-14 04:05:57 +08:00
|
|
|
|
2000-12-14 06:00:33 +08:00
|
|
|
/* XXX another tedious segfault, assume file state normal. */
|
|
|
|
if (otherStates && otherStates[otherFileNum] != RPMFILE_STATE_NORMAL)
|
1999-08-14 04:05:57 +08:00
|
|
|
continue;
|
|
|
|
|
2001-01-09 12:07:49 +08:00
|
|
|
if (XFA_SKIPPING(fi->actions[fileNum]))
|
2000-07-06 04:39:15 +08:00
|
|
|
continue;
|
|
|
|
|
1999-08-14 04:05:57 +08:00
|
|
|
if (filecmp(otherModes[otherFileNum],
|
1999-07-14 22:36:10 +08:00
|
|
|
otherMd5s[otherFileNum],
|
|
|
|
otherLinks[otherFileNum],
|
|
|
|
fi->fmodes[fileNum],
|
|
|
|
fi->fmd5s[fileNum],
|
|
|
|
fi->flinks[fileNum])) {
|
1999-08-14 04:05:57 +08:00
|
|
|
if (reportConflicts)
|
2001-01-21 23:43:32 +08:00
|
|
|
psAppend(probs, RPMPROB_FILE_CONFLICT, fi->ap,
|
2000-12-13 04:03:45 +08:00
|
|
|
fi->dnl[fi->dil[fileNum]], fi->bnl[fileNum], h, 0);
|
1999-08-14 04:05:57 +08:00
|
|
|
if (!(otherFlags[otherFileNum] | fi->fflags[fileNum])
|
|
|
|
& RPMFILE_CONFIG) {
|
|
|
|
if (!shared->isRemoved)
|
|
|
|
fi->replaced[numReplaced++] = *shared;
|
1999-07-14 22:36:10 +08:00
|
|
|
}
|
1999-08-14 04:05:57 +08:00
|
|
|
}
|
1998-12-19 03:09:38 +08:00
|
|
|
|
1999-08-14 04:05:57 +08:00
|
|
|
if ((otherFlags[otherFileNum] | fi->fflags[fileNum]) & RPMFILE_CONFIG) {
|
1999-10-20 18:22:46 +08:00
|
|
|
fi->actions[fileNum] = decideFileFate(
|
|
|
|
fi->dnl[fi->dil[fileNum]],
|
|
|
|
fi->bnl[fileNum],
|
1999-08-07 05:35:15 +08:00
|
|
|
otherModes[otherFileNum],
|
1999-07-14 22:36:10 +08:00
|
|
|
otherMd5s[otherFileNum],
|
|
|
|
otherLinks[otherFileNum],
|
|
|
|
fi->fmodes[fileNum],
|
|
|
|
fi->fmd5s[fileNum],
|
|
|
|
fi->flinks[fileNum],
|
1999-08-07 05:35:15 +08:00
|
|
|
fi->fflags[fileNum],
|
1999-09-22 01:21:57 +08:00
|
|
|
!headerIsEntry(h, RPMTAG_RPMVERSION),
|
|
|
|
transFlags);
|
1998-12-19 03:09:38 +08:00
|
|
|
}
|
1999-08-14 04:05:57 +08:00
|
|
|
|
|
|
|
fi->replacedSizes[fileNum] = otherSizes[otherFileNum];
|
1998-12-19 03:09:38 +08:00
|
|
|
}
|
|
|
|
|
2001-02-05 06:15:30 +08:00
|
|
|
otherMd5s = hfd(otherMd5s, omtype);
|
|
|
|
otherLinks = hfd(otherLinks, oltype);
|
2001-04-30 06:43:01 +08:00
|
|
|
mi = rpmdbFreeIterator(mi);
|
1998-12-19 03:09:38 +08:00
|
|
|
|
1999-09-22 01:21:57 +08:00
|
|
|
fi->replaced = xrealloc(fi->replaced, /* XXX memory leak */
|
1999-07-14 22:36:10 +08:00
|
|
|
sizeof(*fi->replaced) * (numReplaced + 1));
|
|
|
|
fi->replaced[numReplaced].otherPkg = 0;
|
1998-12-19 03:09:38 +08:00
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
return 0;
|
1998-12-19 03:09:38 +08:00
|
|
|
}
|
|
|
|
|
2001-01-21 23:43:32 +08:00
|
|
|
static int handleRmvdInstalledFiles(TFI_t fi, rpmdb db,
|
1999-07-14 22:36:10 +08:00
|
|
|
struct sharedFileInfo * shared,
|
|
|
|
int sharedCount)
|
|
|
|
{
|
2001-02-05 06:15:30 +08:00
|
|
|
HGE_t hge = fi->hge;
|
1998-12-19 03:09:38 +08:00
|
|
|
Header h;
|
1999-08-14 04:05:57 +08:00
|
|
|
const char * otherStates;
|
1999-07-14 22:36:10 +08:00
|
|
|
int i;
|
1999-08-07 05:35:15 +08:00
|
|
|
|
2000-04-27 08:10:28 +08:00
|
|
|
rpmdbMatchIterator mi;
|
|
|
|
|
2001-02-05 06:15:30 +08:00
|
|
|
mi = rpmdbInitIterator(db, RPMDBI_PACKAGES,
|
|
|
|
&shared->otherPkg, sizeof(shared->otherPkg));
|
2000-04-27 08:10:28 +08:00
|
|
|
h = rpmdbNextIterator(mi);
|
|
|
|
if (h == NULL) {
|
2001-04-30 06:43:01 +08:00
|
|
|
mi = rpmdbFreeIterator(mi);
|
2000-04-27 08:10:28 +08:00
|
|
|
return 1;
|
|
|
|
}
|
1998-12-19 03:09:38 +08:00
|
|
|
|
2001-02-05 06:15:30 +08:00
|
|
|
hge(h, RPMTAG_FILESTATES, NULL, (void **) &otherStates, NULL);
|
1999-04-07 03:08:27 +08:00
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
for (i = 0; i < sharedCount; i++, shared++) {
|
1999-08-14 04:05:57 +08:00
|
|
|
int otherFileNum, fileNum;
|
1999-07-14 22:36:10 +08:00
|
|
|
otherFileNum = shared->otherFileNum;
|
|
|
|
fileNum = shared->pkgFileNum;
|
1999-04-07 03:08:27 +08:00
|
|
|
|
1999-08-15 04:01:38 +08:00
|
|
|
if (otherStates[otherFileNum] != RPMFILE_STATE_NORMAL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
fi->actions[fileNum] = FA_SKIP;
|
1999-04-07 03:08:27 +08:00
|
|
|
}
|
1998-12-19 03:09:38 +08:00
|
|
|
|
2001-04-30 06:43:01 +08:00
|
|
|
mi = rpmdbFreeIterator(mi);
|
1998-12-19 03:09:38 +08:00
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
return 0;
|
|
|
|
}
|
1998-12-19 03:09:38 +08:00
|
|
|
|
2000-10-21 00:47:00 +08:00
|
|
|
/**
|
|
|
|
* Update disk space needs on each partition for this package.
|
|
|
|
*/
|
2001-01-21 23:43:32 +08:00
|
|
|
static void handleOverlappedFiles(TFI_t fi, hashTable ht,
|
1999-07-14 22:36:10 +08:00
|
|
|
rpmProblemSet probs, struct diskspaceInfo * dsl)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
struct diskspaceInfo * ds = NULL;
|
|
|
|
uint_32 fixupSize = 0;
|
1999-10-20 18:22:46 +08:00
|
|
|
char * filespec = NULL;
|
|
|
|
int fileSpecAlloced = 0;
|
1999-08-07 05:35:15 +08:00
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
for (i = 0; i < fi->fc; i++) {
|
1999-08-15 04:01:38 +08:00
|
|
|
int otherPkgNum, otherFileNum;
|
2001-01-21 23:43:32 +08:00
|
|
|
const TFI_t * recs;
|
1999-08-15 04:01:38 +08:00
|
|
|
int numRecs;
|
|
|
|
|
1999-08-16 03:11:40 +08:00
|
|
|
if (XFA_SKIPPING(fi->actions[i]))
|
1999-07-14 22:36:10 +08:00
|
|
|
continue;
|
1998-12-19 03:09:38 +08:00
|
|
|
|
1999-10-21 10:40:57 +08:00
|
|
|
j = strlen(fi->dnl[fi->dil[i]]) + strlen(fi->bnl[i]) + 1;
|
1999-10-20 18:22:46 +08:00
|
|
|
if (j > fileSpecAlloced) {
|
|
|
|
fileSpecAlloced = j * 2;
|
|
|
|
filespec = xrealloc(filespec, fileSpecAlloced);
|
|
|
|
}
|
|
|
|
|
2000-10-21 00:47:00 +08:00
|
|
|
(void) stpcpy( stpcpy( filespec, fi->dnl[fi->dil[i]]), fi->bnl[i]);
|
1999-10-20 18:22:46 +08:00
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
if (dsl) {
|
|
|
|
ds = dsl;
|
2000-10-21 00:47:00 +08:00
|
|
|
while (ds->bsize && ds->dev != fi->fps[i].entry->dev) ds++;
|
|
|
|
if (!ds->bsize) ds = NULL;
|
1999-07-14 22:36:10 +08:00
|
|
|
fixupSize = 0;
|
1999-08-07 05:35:15 +08:00
|
|
|
}
|
1998-12-19 03:09:38 +08:00
|
|
|
|
1999-08-18 07:05:24 +08:00
|
|
|
/*
|
|
|
|
* Retrieve all records that apply to this file. Note that the
|
|
|
|
* file info records were built in the same order as the packages
|
|
|
|
* will be installed and removed so the records for an overlapped
|
|
|
|
* files will be sorted in exactly the same order.
|
|
|
|
*/
|
|
|
|
htGetEntry(ht, &fi->fps[i], (const void ***) &recs, &numRecs, NULL);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If this package is being added, look only at other packages
|
|
|
|
* being added -- removed packages dance to a different tune.
|
|
|
|
* If both this and the other package are being added, overlapped
|
|
|
|
* files must be identical (or marked as a conflict). The
|
|
|
|
* disposition of already installed config files leads to
|
|
|
|
* a small amount of extra complexity.
|
|
|
|
*
|
|
|
|
* If this package is being removed, then there are two cases that
|
|
|
|
* need to be worried about:
|
|
|
|
* If the other package is being added, then skip any overlapped files
|
|
|
|
* so that this package removal doesn't nuke the overlapped files
|
|
|
|
* that were just installed.
|
|
|
|
* If both this and the other package are being removed, then each
|
|
|
|
* file removal from preceding packages needs to be skipped so that
|
|
|
|
* the file removal occurs only on the last occurence of an overlapped
|
|
|
|
* file in the transaction set.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Locate this overlapped file in the set of added/removed packages. */
|
2001-01-09 12:07:49 +08:00
|
|
|
for (j = 0; j < numRecs && recs[j] != fi; j++)
|
1999-08-07 07:44:25 +08:00
|
|
|
;
|
1999-07-14 22:36:10 +08:00
|
|
|
|
1999-08-18 07:05:24 +08:00
|
|
|
/* Find what the previous disposition of this file was. */
|
1999-07-14 22:36:10 +08:00
|
|
|
otherFileNum = -1; /* keep gcc quiet */
|
1999-08-14 04:05:57 +08:00
|
|
|
for (otherPkgNum = j - 1; otherPkgNum >= 0; otherPkgNum--) {
|
1999-08-18 07:05:24 +08:00
|
|
|
/* Added packages need only look at other added packages. */
|
|
|
|
if (fi->type == TR_ADDED && recs[otherPkgNum]->type != TR_ADDED)
|
1999-08-14 04:05:57 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* TESTME: there are more efficient searches in the world... */
|
|
|
|
for (otherFileNum = 0; otherFileNum < recs[otherPkgNum]->fc;
|
|
|
|
otherFileNum++) {
|
2000-06-17 03:12:09 +08:00
|
|
|
|
|
|
|
/* If the addresses are the same, so are the values. */
|
|
|
|
if ((fi->fps + i) == (recs[otherPkgNum]->fps + otherFileNum))
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Otherwise, compare fingerprints by value. */
|
1999-08-14 04:05:57 +08:00
|
|
|
if (FP_EQUAL(fi->fps[i], recs[otherPkgNum]->fps[otherFileNum]))
|
1999-07-14 22:36:10 +08:00
|
|
|
break;
|
2000-06-17 03:12:09 +08:00
|
|
|
|
1998-12-19 03:09:38 +08:00
|
|
|
}
|
1999-08-18 07:05:24 +08:00
|
|
|
/* XXX is this test still necessary? */
|
1999-08-14 04:05:57 +08:00
|
|
|
if (recs[otherPkgNum]->actions[otherFileNum] != FA_UNKNOWN)
|
|
|
|
break;
|
1998-12-19 03:09:38 +08:00
|
|
|
}
|
|
|
|
|
1999-08-14 04:05:57 +08:00
|
|
|
switch (fi->type) {
|
1999-08-17 06:10:27 +08:00
|
|
|
struct stat sb;
|
1999-08-14 04:05:57 +08:00
|
|
|
case TR_ADDED:
|
1999-08-15 04:01:38 +08:00
|
|
|
if (otherPkgNum < 0) {
|
1999-08-18 07:05:24 +08:00
|
|
|
/* XXX is this test still necessary? */
|
1999-08-15 04:01:38 +08:00
|
|
|
if (fi->actions[i] != FA_UNKNOWN)
|
|
|
|
break;
|
1999-10-20 18:22:46 +08:00
|
|
|
if ((fi->fflags[i] & RPMFILE_CONFIG) &&
|
|
|
|
!lstat(filespec, &sb)) {
|
1999-08-18 07:05:24 +08:00
|
|
|
/* Here is a non-overlapped pre-existing config file. */
|
1999-07-14 22:36:10 +08:00
|
|
|
fi->actions[i] = (fi->fflags[i] & RPMFILE_NOREPLACE)
|
|
|
|
? FA_ALTNAME : FA_BACKUP;
|
1999-08-17 06:10:27 +08:00
|
|
|
} else {
|
1999-07-14 22:36:10 +08:00
|
|
|
fi->actions[i] = FA_CREATE;
|
1999-08-17 06:10:27 +08:00
|
|
|
}
|
1999-08-15 04:01:38 +08:00
|
|
|
break;
|
1999-07-14 22:36:10 +08:00
|
|
|
}
|
1999-08-17 06:10:27 +08:00
|
|
|
|
2000-10-21 00:47:00 +08:00
|
|
|
/* Mark added overlapped non-identical files as a conflict. */
|
1999-07-14 22:36:10 +08:00
|
|
|
if (probs && filecmp(recs[otherPkgNum]->fmodes[otherFileNum],
|
|
|
|
recs[otherPkgNum]->fmd5s[otherFileNum],
|
|
|
|
recs[otherPkgNum]->flinks[otherFileNum],
|
|
|
|
fi->fmodes[i],
|
|
|
|
fi->fmd5s[i],
|
|
|
|
fi->flinks[i])) {
|
2001-01-21 23:43:32 +08:00
|
|
|
psAppend(probs, RPMPROB_NEW_FILE_CONFLICT, fi->ap,
|
|
|
|
filespec, NULL, recs[otherPkgNum]->ap->h, 0);
|
1999-07-14 22:36:10 +08:00
|
|
|
}
|
1998-12-19 03:09:38 +08:00
|
|
|
|
1999-08-18 07:05:24 +08:00
|
|
|
/* Try to get the disk accounting correct even if a conflict. */
|
1999-07-14 22:36:10 +08:00
|
|
|
fixupSize = recs[otherPkgNum]->fsizes[otherFileNum];
|
1998-12-19 03:09:38 +08:00
|
|
|
|
1999-10-20 18:22:46 +08:00
|
|
|
if ((fi->fflags[i] & RPMFILE_CONFIG) && !lstat(filespec, &sb)) {
|
1999-08-18 07:05:24 +08:00
|
|
|
/* Here is an overlapped pre-existing config file. */
|
1999-08-17 06:10:27 +08:00
|
|
|
fi->actions[i] = (fi->fflags[i] & RPMFILE_NOREPLACE)
|
|
|
|
? FA_ALTNAME : FA_SKIP;
|
|
|
|
} else {
|
|
|
|
fi->actions[i] = FA_CREATE;
|
|
|
|
}
|
1999-08-15 04:01:38 +08:00
|
|
|
break;
|
1999-08-14 04:05:57 +08:00
|
|
|
case TR_REMOVED:
|
1999-08-15 04:01:38 +08:00
|
|
|
if (otherPkgNum >= 0) {
|
2000-10-21 00:47:00 +08:00
|
|
|
/* Here is an overlapped added file we don't want to nuke. */
|
2001-02-09 05:50:38 +08:00
|
|
|
if (recs[otherPkgNum]->actions[otherFileNum] != FA_ERASE) {
|
1999-08-17 06:10:27 +08:00
|
|
|
/* On updates, don't remove files. */
|
1999-08-15 21:41:06 +08:00
|
|
|
fi->actions[i] = FA_SKIP;
|
|
|
|
break;
|
|
|
|
}
|
1999-08-18 07:05:24 +08:00
|
|
|
/* Here is an overlapped removed file: skip in previous. */
|
1999-08-15 04:01:38 +08:00
|
|
|
recs[otherPkgNum]->actions[otherFileNum] = FA_SKIP;
|
|
|
|
}
|
1999-08-16 03:11:40 +08:00
|
|
|
if (XFA_SKIPPING(fi->actions[i]))
|
1999-08-15 04:01:38 +08:00
|
|
|
break;
|
|
|
|
if (fi->fstates[i] != RPMFILE_STATE_NORMAL)
|
|
|
|
break;
|
|
|
|
if (!(S_ISREG(fi->fmodes[i]) && (fi->fflags[i] & RPMFILE_CONFIG))) {
|
2001-02-09 05:50:38 +08:00
|
|
|
fi->actions[i] = FA_ERASE;
|
1999-08-15 04:01:38 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1999-08-18 07:05:24 +08:00
|
|
|
/* Here is a pre-existing modified config file that needs saving. */
|
1999-08-15 04:01:38 +08:00
|
|
|
{ char mdsum[50];
|
1999-10-20 18:22:46 +08:00
|
|
|
if (!mdfile(filespec, mdsum) && strcmp(fi->fmd5s[i], mdsum)) {
|
1999-08-15 04:01:38 +08:00
|
|
|
fi->actions[i] = FA_BACKUP;
|
|
|
|
break;
|
1999-07-14 22:36:10 +08:00
|
|
|
}
|
1999-01-19 11:01:52 +08:00
|
|
|
}
|
2001-02-09 05:50:38 +08:00
|
|
|
fi->actions[i] = FA_ERASE;
|
1999-08-15 04:01:38 +08:00
|
|
|
break;
|
1999-07-14 22:36:10 +08:00
|
|
|
}
|
1998-12-19 03:09:38 +08:00
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
if (ds) {
|
2000-10-21 00:47:00 +08:00
|
|
|
uint_32 s = BLOCK_ROUND(fi->fsizes[i], ds->bsize);
|
1998-12-19 03:09:38 +08:00
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
switch (fi->actions[i]) {
|
|
|
|
case FA_BACKUP:
|
|
|
|
case FA_SAVE:
|
|
|
|
case FA_ALTNAME:
|
2000-10-21 00:47:00 +08:00
|
|
|
ds->ineeded++;
|
|
|
|
ds->bneeded += s;
|
1999-07-14 22:36:10 +08:00
|
|
|
break;
|
1998-12-19 03:09:38 +08:00
|
|
|
|
2001-02-12 06:02:29 +08:00
|
|
|
/*
|
2001-04-03 21:41:56 +08:00
|
|
|
* FIXME: If two packages share a file (same md5sum), and
|
2000-10-21 00:47:00 +08:00
|
|
|
* that file is being replaced on disk, will ds->bneeded get
|
|
|
|
* decremented twice? Quite probably!
|
|
|
|
*/
|
1999-07-14 22:36:10 +08:00
|
|
|
case FA_CREATE:
|
2000-10-21 00:47:00 +08:00
|
|
|
ds->bneeded += s;
|
|
|
|
ds->bneeded -= BLOCK_ROUND(fi->replacedSizes[i], ds->bsize);
|
1999-07-14 22:36:10 +08:00
|
|
|
break;
|
1998-12-19 03:09:38 +08:00
|
|
|
|
2001-02-09 05:50:38 +08:00
|
|
|
case FA_ERASE:
|
2000-10-21 00:47:00 +08:00
|
|
|
ds->ineeded--;
|
|
|
|
ds->bneeded -= s;
|
1999-07-14 22:36:10 +08:00
|
|
|
break;
|
1998-12-19 03:09:38 +08:00
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
default:
|
1998-12-19 03:09:38 +08:00
|
|
|
break;
|
1999-07-14 22:36:10 +08:00
|
|
|
}
|
1998-12-19 03:09:38 +08:00
|
|
|
|
2000-10-21 00:47:00 +08:00
|
|
|
ds->bneeded -= BLOCK_ROUND(fixupSize, ds->bsize);
|
1998-12-19 03:09:38 +08:00
|
|
|
}
|
|
|
|
}
|
1999-10-30 00:06:01 +08:00
|
|
|
if (filespec) free(filespec);
|
1999-07-14 22:36:10 +08:00
|
|
|
}
|
1998-12-19 03:09:38 +08:00
|
|
|
|
2001-01-21 23:43:32 +08:00
|
|
|
static int ensureOlder(struct availablePackage * alp, Header old,
|
|
|
|
rpmProblemSet probs)
|
1999-07-14 22:36:10 +08:00
|
|
|
{
|
|
|
|
int result, rc = 0;
|
1998-12-19 03:09:38 +08:00
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
if (old == NULL) return 1;
|
1998-12-31 07:03:43 +08:00
|
|
|
|
2001-01-21 23:43:32 +08:00
|
|
|
result = rpmVersionCompare(old, alp->h);
|
1999-07-14 22:36:10 +08:00
|
|
|
if (result <= 0)
|
|
|
|
rc = 0;
|
|
|
|
else if (result > 0) {
|
|
|
|
rc = 1;
|
2001-01-21 23:43:32 +08:00
|
|
|
psAppend(probs, RPMPROB_OLDPACKAGE, alp, NULL, NULL, old, 0);
|
1999-07-14 22:36:10 +08:00
|
|
|
}
|
1998-12-31 07:03:43 +08:00
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
return rc;
|
1998-12-31 07:03:43 +08:00
|
|
|
}
|
1999-01-01 03:16:31 +08:00
|
|
|
|
2001-01-24 00:07:28 +08:00
|
|
|
static void skipFiles(const rpmTransactionSet ts, TFI_t fi)
|
1999-07-14 22:36:10 +08:00
|
|
|
{
|
2001-01-24 00:07:28 +08:00
|
|
|
int noDocs = (ts->transFlags & RPMTRANS_FLAG_NODOCS);
|
1999-08-07 08:07:51 +08:00
|
|
|
char ** netsharedPaths = NULL;
|
|
|
|
const char ** languages;
|
2001-04-04 04:41:09 +08:00
|
|
|
const char * dn, * bn;
|
|
|
|
int dnlen, bnlen, ix;
|
2000-07-08 04:06:41 +08:00
|
|
|
const char * s;
|
2001-04-03 21:41:56 +08:00
|
|
|
int * drc;
|
|
|
|
char * dff;
|
|
|
|
int i, j;
|
1999-01-01 03:16:31 +08:00
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
if (!noDocs)
|
|
|
|
noDocs = rpmExpandNumeric("%{_excludedocs}");
|
1999-01-01 03:16:31 +08:00
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
{ const char *tmpPath = rpmExpand("%{_netsharedpath}", NULL);
|
|
|
|
if (tmpPath && *tmpPath != '%')
|
|
|
|
netsharedPaths = splitString(tmpPath, strlen(tmpPath), ':');
|
2001-04-04 04:41:09 +08:00
|
|
|
tmpPath = _free(tmpPath);
|
1999-07-14 22:36:10 +08:00
|
|
|
}
|
1999-01-01 03:16:31 +08:00
|
|
|
|
1999-08-22 12:17:12 +08:00
|
|
|
s = rpmExpand("%{_install_langs}", NULL);
|
2001-04-04 04:41:09 +08:00
|
|
|
if (!(s && *s != '%'))
|
|
|
|
s = _free(s);
|
1999-08-22 12:17:12 +08:00
|
|
|
if (s) {
|
|
|
|
languages = (const char **) splitString(s, strlen(s), ':');
|
2001-04-04 04:41:09 +08:00
|
|
|
s = _free(s);
|
1999-09-08 07:04:24 +08:00
|
|
|
} else
|
|
|
|
languages = NULL;
|
1999-01-01 03:16:31 +08:00
|
|
|
|
2001-04-03 21:41:56 +08:00
|
|
|
/* Compute directory refcount, skip directory if now empty. */
|
|
|
|
drc = alloca(fi->dc * sizeof(*drc));
|
|
|
|
memset(drc, 0, fi->dc * sizeof(*drc));
|
|
|
|
dff = alloca(fi->dc * sizeof(*dff));
|
|
|
|
memset(dff, 0, fi->dc * sizeof(*dff));
|
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
for (i = 0; i < fi->fc; i++) {
|
1999-08-07 08:07:51 +08:00
|
|
|
char **nsp;
|
|
|
|
|
2001-04-04 04:41:09 +08:00
|
|
|
bn = fi->bnl[i];
|
|
|
|
bnlen = strlen(bn);
|
|
|
|
ix = fi->dil[i];
|
|
|
|
dn = fi->dnl[ix];
|
|
|
|
dnlen = strlen(dn);
|
|
|
|
|
|
|
|
drc[ix]++;
|
2001-04-03 21:41:56 +08:00
|
|
|
|
1999-08-07 08:07:51 +08:00
|
|
|
/* Don't bother with skipped files */
|
2001-04-03 21:41:56 +08:00
|
|
|
if (XFA_SKIPPING(fi->actions[i])) {
|
2001-04-04 04:41:09 +08:00
|
|
|
drc[ix]--;
|
1999-07-14 22:36:10 +08:00
|
|
|
continue;
|
2001-04-03 21:41:56 +08:00
|
|
|
}
|
1999-01-01 03:16:31 +08:00
|
|
|
|
1999-08-07 08:07:51 +08:00
|
|
|
/*
|
|
|
|
* Skip net shared paths.
|
|
|
|
* Net shared paths are not relative to the current root (though
|
|
|
|
* they do need to take package relocations into account).
|
|
|
|
*/
|
1999-07-14 22:36:10 +08:00
|
|
|
for (nsp = netsharedPaths; nsp && *nsp; nsp++) {
|
2001-04-03 21:41:56 +08:00
|
|
|
int len;
|
1999-10-20 18:22:46 +08:00
|
|
|
|
1999-08-07 08:07:51 +08:00
|
|
|
len = strlen(*nsp);
|
2001-04-04 04:41:09 +08:00
|
|
|
if (dnlen >= len) {
|
|
|
|
if (strncmp(dn, *nsp, len)) continue;
|
|
|
|
/* Only directories or complete file paths can be net shared */
|
|
|
|
if (!(dn[len] == '/' || dn[len] == '\0')) continue;
|
|
|
|
} else {
|
|
|
|
if (len < (dnlen + bnlen)) continue;
|
|
|
|
if (strncmp(dn, *nsp, dnlen)) continue;
|
|
|
|
if (strncmp(bn, (*nsp) + dnlen, bnlen)) continue;
|
|
|
|
len = dnlen + bnlen;
|
|
|
|
/* Only directories or complete file paths can be net shared */
|
|
|
|
if (!((*nsp)[len] == '/' || (*nsp)[len] == '\0')) continue;
|
|
|
|
}
|
1999-08-07 08:07:51 +08:00
|
|
|
|
|
|
|
break;
|
1999-01-01 03:16:31 +08:00
|
|
|
}
|
1999-07-14 22:36:10 +08:00
|
|
|
|
|
|
|
if (nsp && *nsp) {
|
2001-04-04 04:41:09 +08:00
|
|
|
drc[ix]--; dff[ix] = 1;
|
1999-08-16 03:11:40 +08:00
|
|
|
fi->actions[i] = FA_SKIPNETSHARED;
|
1999-07-14 22:36:10 +08:00
|
|
|
continue;
|
1999-01-01 03:16:31 +08:00
|
|
|
}
|
|
|
|
|
1999-08-07 08:07:51 +08:00
|
|
|
/*
|
|
|
|
* Skip i18n language specific files.
|
|
|
|
*/
|
2001-01-24 00:07:28 +08:00
|
|
|
if (fi->flangs && languages && *fi->flangs[i]) {
|
1999-08-07 08:07:51 +08:00
|
|
|
const char **lang, *l, *le;
|
2001-04-29 09:05:43 +08:00
|
|
|
for (lang = languages; *lang != '\0'; lang++) {
|
1999-08-22 12:17:12 +08:00
|
|
|
if (!strcmp(*lang, "all"))
|
|
|
|
break;
|
2001-04-29 09:05:43 +08:00
|
|
|
for (l = fi->flangs[i]; *l != '\0'; l = le) {
|
|
|
|
for (le = l; *le != '\0' && *le != '|'; le++)
|
1999-07-14 22:36:10 +08:00
|
|
|
;
|
|
|
|
if ((le-l) > 0 && !strncmp(*lang, l, (le-l)))
|
1999-08-22 12:17:12 +08:00
|
|
|
break;
|
1999-07-14 22:36:10 +08:00
|
|
|
if (*le == '|') le++; /* skip over | */
|
|
|
|
}
|
2001-04-29 09:05:43 +08:00
|
|
|
if (*l != '\0') break;
|
1999-07-14 22:36:10 +08:00
|
|
|
}
|
1999-08-07 08:07:51 +08:00
|
|
|
if (*lang == NULL) {
|
2001-04-04 04:41:09 +08:00
|
|
|
drc[ix]--; dff[ix] = 1;
|
1999-07-14 22:36:10 +08:00
|
|
|
fi->actions[i] = FA_SKIPNSTATE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
1999-01-01 03:16:31 +08:00
|
|
|
|
1999-08-07 08:07:51 +08:00
|
|
|
/*
|
|
|
|
* Skip documentation if requested.
|
|
|
|
*/
|
2001-04-03 21:41:56 +08:00
|
|
|
if (noDocs && (fi->fflags[i] & RPMFILE_DOC)) {
|
2001-04-04 04:41:09 +08:00
|
|
|
drc[ix]--; dff[ix] = 1;
|
1999-07-14 22:36:10 +08:00
|
|
|
fi->actions[i] = FA_SKIPNSTATE;
|
2001-04-21 14:02:09 +08:00
|
|
|
continue;
|
2001-04-03 21:41:56 +08:00
|
|
|
}
|
1999-01-01 03:16:31 +08:00
|
|
|
}
|
|
|
|
|
2001-04-03 21:41:56 +08:00
|
|
|
/* Skip (now empty) directories that had skipped files. */
|
|
|
|
for (j = 0; j < fi->dc; j++) {
|
|
|
|
|
|
|
|
if (drc[j]) continue; /* dir still has files. */
|
|
|
|
if (!dff[j]) continue; /* dir was not emptied here. */
|
|
|
|
|
|
|
|
/* Find parent directory and basename. */
|
|
|
|
dn = fi->dnl[j]; dnlen = strlen(dn) - 1;
|
|
|
|
bn = dn + dnlen; bnlen = 0;
|
|
|
|
while (bn > dn && bn[-1] != '/') {
|
|
|
|
bnlen++;
|
|
|
|
dnlen--;
|
|
|
|
bn--;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If explicitly included in the package, skip the directory. */
|
|
|
|
for (i = 0; i < fi->fc; i++) {
|
|
|
|
const char * dir;
|
|
|
|
|
|
|
|
if (XFA_SKIPPING(fi->actions[i]))
|
|
|
|
continue;
|
|
|
|
if (whatis(fi->fmodes[i]) != XDIR)
|
|
|
|
continue;
|
|
|
|
dir = fi->dnl[fi->dil[i]];
|
|
|
|
if (strlen(dir) != dnlen)
|
|
|
|
continue;
|
|
|
|
if (strncmp(dir, dn, dnlen))
|
|
|
|
continue;
|
|
|
|
if (strlen(fi->bnl[i]) != bnlen)
|
|
|
|
continue;
|
|
|
|
if (strncmp(fi->bnl[i], bn, bnlen))
|
|
|
|
continue;
|
|
|
|
rpmMessage(RPMMESS_DEBUG, _("excluding directory %s\n"), dn);
|
|
|
|
fi->actions[i] = FA_SKIPNSTATE;
|
|
|
|
break;
|
|
|
|
}
|
2001-01-24 00:07:28 +08:00
|
|
|
}
|
2001-04-03 21:41:56 +08:00
|
|
|
|
|
|
|
if (netsharedPaths) freeSplitString(netsharedPaths);
|
|
|
|
fi->flangs = _free(fi->flangs);
|
1999-08-22 12:17:12 +08:00
|
|
|
if (languages) freeSplitString((char **)languages);
|
1999-07-14 22:36:10 +08:00
|
|
|
}
|
1999-01-01 03:16:31 +08:00
|
|
|
|
2001-02-18 01:53:21 +08:00
|
|
|
/**
|
|
|
|
* Iterator across transaction elements, forward on install, backward on erase.
|
|
|
|
*/
|
|
|
|
struct tsIterator_s {
|
|
|
|
/*@kept@*/ rpmTransactionSet ts; /*!< transaction set. */
|
|
|
|
int reverse; /*!< reversed traversal? */
|
|
|
|
int ocsave; /*!< last returned iterator index. */
|
|
|
|
int oc; /*!< iterator index. */
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
static int tsGetOc(void * this) {
|
|
|
|
struct tsIterator_s * iter = this;
|
|
|
|
int oc = iter->ocsave;
|
|
|
|
return oc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
2001-04-30 06:43:01 +08:00
|
|
|
static /*@dependent@*/ struct availablePackage * tsGetAlp(void * this) {
|
2001-02-18 01:53:21 +08:00
|
|
|
struct tsIterator_s * iter = this;
|
|
|
|
struct availablePackage * alp = NULL;
|
|
|
|
int oc = iter->ocsave;
|
|
|
|
|
|
|
|
if (oc != -1) {
|
|
|
|
rpmTransactionSet ts = iter->ts;
|
|
|
|
TFI_t fi = ts->flList + oc;
|
|
|
|
if (fi->type == TR_ADDED)
|
|
|
|
alp = ts->addedPackages.list + ts->order[oc].u.addedIndex;
|
|
|
|
}
|
|
|
|
return alp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroy transaction element iterator.
|
|
|
|
* @param this transaction element iterator
|
|
|
|
* @retval NULL always
|
|
|
|
*/
|
|
|
|
static /*@null@*/ void * tsFreeIterator(/*@only@*//*@null@*/ const void * this)
|
|
|
|
{
|
|
|
|
return _free((void *)this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create transaction element iterator.
|
|
|
|
* @param this transaction set
|
|
|
|
* @return transaction element iterator
|
|
|
|
*/
|
|
|
|
static void * tsInitIterator(/*@kept@*/ const void * this)
|
|
|
|
{
|
|
|
|
rpmTransactionSet ts = (void *)this;
|
|
|
|
struct tsIterator_s * iter = NULL;
|
|
|
|
|
|
|
|
iter = xcalloc(1, sizeof(*iter));
|
|
|
|
iter->ts = ts;
|
2001-04-30 00:08:55 +08:00
|
|
|
iter->reverse = ((ts->transFlags & RPMTRANS_FLAG_REVERSE) ? 1 : 0);
|
|
|
|
iter->oc = (iter->reverse ? (ts->orderCount - 1) : 0);
|
2001-02-18 01:53:21 +08:00
|
|
|
iter->ocsave = iter->oc;
|
|
|
|
return iter;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return next transaction element's file info.
|
|
|
|
* @param this file info iterator
|
|
|
|
* @return next index, -1 on termination
|
|
|
|
*/
|
2001-04-30 06:43:01 +08:00
|
|
|
static /*@dependent@*/ TFI_t tsNextIterator(void * this) {
|
2001-02-18 01:53:21 +08:00
|
|
|
struct tsIterator_s * iter = this;
|
|
|
|
rpmTransactionSet ts = iter->ts;
|
|
|
|
TFI_t fi = NULL;
|
|
|
|
int oc = -1;
|
|
|
|
|
|
|
|
if (iter->reverse) {
|
|
|
|
if (iter->oc >= 0) oc = iter->oc--;
|
|
|
|
} else {
|
|
|
|
if (iter->oc < ts->orderCount) oc = iter->oc++;
|
|
|
|
}
|
|
|
|
iter->ocsave = oc;
|
|
|
|
if (oc != -1)
|
|
|
|
fi = ts->flList + oc;
|
|
|
|
return fi;
|
|
|
|
}
|
|
|
|
|
2000-10-21 06:04:27 +08:00
|
|
|
#define NOTIFY(_ts, _al) if ((_ts)->notify) (void) (_ts)->notify _al
|
1999-01-01 03:16:31 +08:00
|
|
|
|
2000-08-30 06:04:33 +08:00
|
|
|
int rpmRunTransactions( rpmTransactionSet ts,
|
|
|
|
rpmCallbackFunction notify, rpmCallbackData notifyData,
|
|
|
|
rpmProblemSet okProbs, rpmProblemSet * newProbs,
|
|
|
|
rpmtransFlags transFlags, rpmprobFilterFlags ignoreSet)
|
1999-07-14 22:36:10 +08:00
|
|
|
{
|
|
|
|
int i, j;
|
2001-02-18 01:53:21 +08:00
|
|
|
int ourrc = 0;
|
1999-07-14 22:36:10 +08:00
|
|
|
struct availablePackage * alp;
|
|
|
|
Header * hdrs;
|
|
|
|
int totalFileCount = 0;
|
|
|
|
hashTable ht;
|
2001-02-18 01:53:21 +08:00
|
|
|
TFI_t fi;
|
2001-01-27 01:06:09 +08:00
|
|
|
struct diskspaceInfo * dip;
|
1999-07-14 22:36:10 +08:00
|
|
|
struct sharedFileInfo * shared, * sharedList;
|
|
|
|
int numShared;
|
1999-08-14 04:05:57 +08:00
|
|
|
int nexti;
|
1999-07-14 22:36:10 +08:00
|
|
|
int lastFailed;
|
|
|
|
int oc;
|
1999-10-20 18:22:46 +08:00
|
|
|
fingerPrintCache fpc;
|
2001-02-28 06:08:53 +08:00
|
|
|
struct psm_s psmbuf;
|
|
|
|
PSM_t psm = &psmbuf;
|
2001-02-18 01:53:21 +08:00
|
|
|
void * tsi;
|
1999-01-01 03:16:31 +08:00
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
/* FIXME: what if the same package is included in ts twice? */
|
1999-01-01 03:16:31 +08:00
|
|
|
|
2000-10-21 06:04:27 +08:00
|
|
|
ts->transFlags = transFlags;
|
2001-03-04 23:34:53 +08:00
|
|
|
if (ts->transFlags & RPMTRANS_FLAG_NOSCRIPTS)
|
|
|
|
ts->transFlags |= (_noTransScripts | _noTransTriggers);
|
|
|
|
if (ts->transFlags & RPMTRANS_FLAG_NOTRIGGERS)
|
|
|
|
ts->transFlags |= _noTransTriggers;
|
2001-01-25 05:35:52 +08:00
|
|
|
|
|
|
|
/* XXX MULTILIB is broken, as packages can and do execute /sbin/ldconfig. */
|
|
|
|
if (ts->transFlags & (RPMTRANS_FLAG_JUSTDB | RPMTRANS_FLAG_MULTILIB))
|
2001-03-04 23:34:53 +08:00
|
|
|
ts->transFlags |= (_noTransScripts | _noTransTriggers);
|
2001-01-25 05:35:52 +08:00
|
|
|
|
2000-10-21 06:04:27 +08:00
|
|
|
ts->notify = notify;
|
|
|
|
ts->notifyData = notifyData;
|
2001-01-27 01:06:09 +08:00
|
|
|
ts->probs = *newProbs = psCreate();
|
2000-10-21 06:04:27 +08:00
|
|
|
ts->ignoreSet = ignoreSet;
|
2001-04-04 04:41:09 +08:00
|
|
|
ts->currDir = _free(ts->currDir);
|
2000-07-09 23:17:11 +08:00
|
|
|
ts->currDir = currentDirectory();
|
2000-12-20 01:43:56 +08:00
|
|
|
ts->chrootDone = 0;
|
2001-01-27 01:06:09 +08:00
|
|
|
ts->id = time(NULL);
|
2000-07-09 23:17:11 +08:00
|
|
|
|
2001-02-28 06:08:53 +08:00
|
|
|
memset(psm, 0, sizeof(*psm));
|
|
|
|
psm->ts = ts;
|
|
|
|
|
2000-10-21 00:47:00 +08:00
|
|
|
/* Get available space on mounted file systems. */
|
2000-10-21 06:04:27 +08:00
|
|
|
if (!(ts->ignoreSet & RPMPROB_FILTER_DISKSPACE) &&
|
2001-01-27 01:06:09 +08:00
|
|
|
!rpmGetFilesystemList(&ts->filesystems, &ts->filesystemCount)) {
|
1999-07-14 22:36:10 +08:00
|
|
|
struct stat sb;
|
1999-01-01 03:16:31 +08:00
|
|
|
|
2001-04-04 04:41:09 +08:00
|
|
|
ts->di = _free(ts->di);
|
2001-01-27 01:06:09 +08:00
|
|
|
dip = ts->di = xcalloc(sizeof(*ts->di), ts->filesystemCount + 1);
|
1999-01-01 03:16:31 +08:00
|
|
|
|
2001-01-27 01:06:09 +08:00
|
|
|
for (i = 0; (i < ts->filesystemCount) && dip; i++) {
|
1999-07-14 22:36:10 +08:00
|
|
|
#if STATFS_IN_SYS_STATVFS
|
|
|
|
struct statvfs sfb;
|
2000-07-08 04:06:41 +08:00
|
|
|
memset(&sfb, 0, sizeof(sfb));
|
2001-01-27 01:06:09 +08:00
|
|
|
if (statvfs(ts->filesystems[i], &sfb))
|
1999-07-14 22:36:10 +08:00
|
|
|
#else
|
|
|
|
struct statfs sfb;
|
|
|
|
# if STAT_STATFS4
|
|
|
|
/* this platform has the 4-argument version of the statfs call. The last two
|
|
|
|
* should be the size of struct statfs and 0, respectively. The 0 is the
|
|
|
|
* filesystem type, and is always 0 when statfs is called on a mounted
|
|
|
|
* filesystem, as we're doing.
|
|
|
|
*/
|
2000-07-08 04:06:41 +08:00
|
|
|
memset(&sfb, 0, sizeof(sfb));
|
2001-01-27 01:06:09 +08:00
|
|
|
if (statfs(ts->filesystems[i], &sfb, sizeof(sfb), 0))
|
1999-07-14 22:36:10 +08:00
|
|
|
# else
|
2000-07-08 04:06:41 +08:00
|
|
|
memset(&sfb, 0, sizeof(sfb));
|
2001-01-27 01:06:09 +08:00
|
|
|
if (statfs(ts->filesystems[i], &sfb))
|
1999-07-14 22:36:10 +08:00
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
{
|
2001-01-27 01:06:09 +08:00
|
|
|
dip = NULL;
|
1999-07-14 22:36:10 +08:00
|
|
|
} else {
|
2001-01-27 01:06:09 +08:00
|
|
|
ts->di[i].bsize = sfb.f_bsize;
|
|
|
|
ts->di[i].bneeded = 0;
|
|
|
|
ts->di[i].ineeded = 0;
|
1999-07-14 22:36:10 +08:00
|
|
|
#ifdef STATFS_HAS_F_BAVAIL
|
2001-01-27 01:06:09 +08:00
|
|
|
ts->di[i].bavail = sfb.f_bavail;
|
1999-07-14 22:36:10 +08:00
|
|
|
#else
|
|
|
|
/* FIXME: the statfs struct doesn't have a member to tell how many blocks are
|
|
|
|
* available for non-superusers. f_blocks - f_bfree is probably too big, but
|
|
|
|
* it's about all we can do.
|
|
|
|
*/
|
2001-01-27 01:06:09 +08:00
|
|
|
ts->di[i].bavail = sfb.f_blocks - sfb.f_bfree;
|
1999-07-14 22:36:10 +08:00
|
|
|
#endif
|
2000-12-30 05:44:37 +08:00
|
|
|
/* XXX Avoid FAT and other file systems that have not inodes. */
|
2001-01-27 01:06:09 +08:00
|
|
|
ts->di[i].iavail = !(sfb.f_ffree == 0 && sfb.f_files == 0)
|
2000-12-30 05:44:37 +08:00
|
|
|
? sfb.f_ffree : -1;
|
1999-01-01 03:16:31 +08:00
|
|
|
|
2001-01-27 01:06:09 +08:00
|
|
|
stat(ts->filesystems[i], &sb);
|
|
|
|
ts->di[i].dev = sb.st_dev;
|
1999-07-14 22:36:10 +08:00
|
|
|
}
|
|
|
|
}
|
1999-01-05 00:44:20 +08:00
|
|
|
|
2001-01-27 01:06:09 +08:00
|
|
|
if (dip) ts->di[i].bsize = 0;
|
1999-07-14 22:36:10 +08:00
|
|
|
}
|
1999-01-05 00:44:20 +08:00
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
hdrs = alloca(sizeof(*hdrs) * ts->addedPackages.size);
|
1999-01-05 00:44:20 +08:00
|
|
|
|
1999-08-07 07:44:25 +08:00
|
|
|
/* ===============================================
|
|
|
|
* For packages being installed:
|
|
|
|
* - verify package arch/os.
|
|
|
|
* - verify package epoch:version-release is newer.
|
|
|
|
* - count files.
|
|
|
|
* For packages being removed:
|
|
|
|
* - count files.
|
|
|
|
*/
|
1999-07-14 22:36:10 +08:00
|
|
|
/* The ordering doesn't matter here */
|
1999-12-02 03:57:17 +08:00
|
|
|
for (alp = ts->addedPackages.list;
|
2000-04-13 17:07:08 +08:00
|
|
|
(alp - ts->addedPackages.list) < ts->addedPackages.size;
|
|
|
|
alp++)
|
|
|
|
{
|
2000-10-21 06:04:27 +08:00
|
|
|
if (!archOkay(alp->h) && !(ts->ignoreSet & RPMPROB_FILTER_IGNOREARCH))
|
2001-01-21 23:43:32 +08:00
|
|
|
psAppend(ts->probs, RPMPROB_BADARCH, alp, NULL, NULL, NULL, 0);
|
1999-01-08 01:06:24 +08:00
|
|
|
|
2000-10-21 06:04:27 +08:00
|
|
|
if (!osOkay(alp->h) && !(ts->ignoreSet & RPMPROB_FILTER_IGNOREOS))
|
2001-01-21 23:43:32 +08:00
|
|
|
psAppend(ts->probs, RPMPROB_BADOS, alp, NULL, NULL, NULL, 0);
|
1999-01-05 00:44:20 +08:00
|
|
|
|
2000-10-21 06:04:27 +08:00
|
|
|
if (!(ts->ignoreSet & RPMPROB_FILTER_OLDPACKAGE)) {
|
2000-04-13 17:07:08 +08:00
|
|
|
rpmdbMatchIterator mi;
|
|
|
|
Header oldH;
|
2000-07-09 23:17:11 +08:00
|
|
|
mi = rpmdbInitIterator(ts->rpmdb, RPMTAG_NAME, alp->name, 0);
|
2000-04-13 17:07:08 +08:00
|
|
|
while ((oldH = rpmdbNextIterator(mi)) != NULL)
|
2001-01-21 23:43:32 +08:00
|
|
|
ensureOlder(alp, oldH, ts->probs);
|
2001-04-30 06:43:01 +08:00
|
|
|
mi = rpmdbFreeIterator(mi);
|
1999-07-14 22:36:10 +08:00
|
|
|
}
|
1999-03-19 11:39:17 +08:00
|
|
|
|
2000-07-09 12:42:12 +08:00
|
|
|
/* XXX multilib should not display "already installed" problems */
|
2000-10-21 06:04:27 +08:00
|
|
|
if (!(ts->ignoreSet & RPMPROB_FILTER_REPLACEPKG) && !alp->multiLib) {
|
2000-04-27 08:10:28 +08:00
|
|
|
rpmdbMatchIterator mi;
|
2000-07-09 23:17:11 +08:00
|
|
|
mi = rpmdbInitIterator(ts->rpmdb, RPMTAG_NAME, alp->name, 0);
|
2000-04-27 08:10:28 +08:00
|
|
|
rpmdbSetIteratorVersion(mi, alp->version);
|
|
|
|
rpmdbSetIteratorRelease(mi, alp->release);
|
|
|
|
while (rpmdbNextIterator(mi) != NULL) {
|
2001-01-21 23:43:32 +08:00
|
|
|
psAppend(ts->probs, RPMPROB_PKG_INSTALLED, alp,
|
2000-12-13 04:03:45 +08:00
|
|
|
NULL, NULL, NULL, 0);
|
2000-04-27 08:10:28 +08:00
|
|
|
break;
|
|
|
|
}
|
2001-04-30 06:43:01 +08:00
|
|
|
mi = rpmdbFreeIterator(mi);
|
2000-04-13 18:11:32 +08:00
|
|
|
}
|
1999-01-05 00:44:20 +08:00
|
|
|
|
2000-07-09 12:42:12 +08:00
|
|
|
totalFileCount += alp->filesCount;
|
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
}
|
1999-01-05 00:44:20 +08:00
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
/* FIXME: it seems a bit silly to read in all of these headers twice */
|
|
|
|
/* The ordering doesn't matter here */
|
2000-06-14 22:21:06 +08:00
|
|
|
if (ts->numRemovedPackages > 0) {
|
|
|
|
rpmdbMatchIterator mi;
|
2000-04-27 08:10:28 +08:00
|
|
|
Header h;
|
2000-07-09 12:42:12 +08:00
|
|
|
int fileCount;
|
2000-04-27 08:10:28 +08:00
|
|
|
|
2000-07-09 23:17:11 +08:00
|
|
|
mi = rpmdbInitIterator(ts->rpmdb, RPMDBI_PACKAGES, NULL, 0);
|
2000-05-07 08:53:11 +08:00
|
|
|
rpmdbAppendIterator(mi, ts->removedPackages, ts->numRemovedPackages);
|
2000-04-27 08:10:28 +08:00
|
|
|
while ((h = rpmdbNextIterator(mi)) != NULL) {
|
|
|
|
if (headerGetEntry(h, RPMTAG_BASENAMES, NULL, NULL, &fileCount))
|
|
|
|
totalFileCount += fileCount;
|
|
|
|
}
|
2001-04-30 06:43:01 +08:00
|
|
|
mi = rpmdbFreeIterator(mi);
|
2000-04-27 08:10:28 +08:00
|
|
|
}
|
1999-01-05 00:44:20 +08:00
|
|
|
|
1999-08-07 07:44:25 +08:00
|
|
|
/* ===============================================
|
|
|
|
* Initialize file list:
|
|
|
|
*/
|
2001-02-18 01:53:21 +08:00
|
|
|
ts->flEntries = ts->addedPackages.size + ts->numRemovedPackages;
|
2001-04-30 06:43:01 +08:00
|
|
|
ts->flList = xcalloc(ts->flEntries, sizeof(*ts->flList));
|
1999-01-05 00:44:20 +08:00
|
|
|
|
2000-10-21 00:47:00 +08:00
|
|
|
/*
|
|
|
|
* FIXME?: we'd be better off assembling one very large file list and
|
|
|
|
* calling fpLookupList only once. I'm not sure that the speedup is
|
|
|
|
* worth the trouble though.
|
|
|
|
*/
|
2001-04-30 06:43:01 +08:00
|
|
|
tsi = tsInitIterator(ts);
|
|
|
|
while ((fi = tsNextIterator(tsi)) != NULL) {
|
|
|
|
oc = tsGetOc(tsi);
|
2001-01-23 03:11:19 +08:00
|
|
|
fi->magic = TFIMAGIC;
|
1999-01-05 00:44:20 +08:00
|
|
|
|
2001-04-30 06:43:01 +08:00
|
|
|
/* XXX watchout: fi->type must be set for tsGetAlp() to "work" */
|
2001-01-24 00:07:28 +08:00
|
|
|
fi->type = ts->order[oc].type;
|
2001-04-21 14:02:09 +08:00
|
|
|
switch (fi->type) {
|
1999-08-14 04:05:57 +08:00
|
|
|
case TR_ADDED:
|
1999-07-14 22:36:10 +08:00
|
|
|
i = ts->order[oc].u.addedIndex;
|
2001-04-30 06:43:01 +08:00
|
|
|
/* XXX watchout: fi->type must be set for tsGetAlp() to "work" */
|
|
|
|
fi->ap = tsGetAlp(tsi);
|
2001-01-24 00:07:28 +08:00
|
|
|
fi->record = 0;
|
2001-04-30 06:43:01 +08:00
|
|
|
loadFi(fi->ap->h, fi);
|
2001-01-25 05:35:52 +08:00
|
|
|
if (fi->fc == 0) {
|
1999-07-14 22:36:10 +08:00
|
|
|
hdrs[i] = headerLink(fi->h);
|
|
|
|
continue;
|
|
|
|
}
|
1999-03-05 07:26:51 +08:00
|
|
|
|
2001-01-09 12:07:49 +08:00
|
|
|
/* Allocate file actions (and initialize to FA_UNKNOWN) */
|
1999-09-21 11:22:53 +08:00
|
|
|
fi->actions = xcalloc(fi->fc, sizeof(*fi->actions));
|
2001-04-30 06:43:01 +08:00
|
|
|
hdrs[i] = relocateFileList(ts, fi, fi->ap, fi->h, fi->actions);
|
2001-01-24 00:07:28 +08:00
|
|
|
|
|
|
|
/* Skip netshared paths, not our i18n files, and excluded docs */
|
|
|
|
skipFiles(ts, fi);
|
1999-08-14 04:05:57 +08:00
|
|
|
break;
|
|
|
|
case TR_REMOVED:
|
2001-04-30 06:43:01 +08:00
|
|
|
fi->ap = NULL;
|
1999-07-14 22:36:10 +08:00
|
|
|
fi->record = ts->order[oc].u.removed.dboffset;
|
2000-04-27 08:10:28 +08:00
|
|
|
{ rpmdbMatchIterator mi;
|
|
|
|
|
2000-07-09 23:17:11 +08:00
|
|
|
mi = rpmdbInitIterator(ts->rpmdb, RPMDBI_PACKAGES,
|
2001-01-25 05:35:52 +08:00
|
|
|
&fi->record, sizeof(fi->record));
|
2000-04-27 08:10:28 +08:00
|
|
|
if ((fi->h = rpmdbNextIterator(mi)) != NULL)
|
|
|
|
fi->h = headerLink(fi->h);
|
2001-04-30 06:43:01 +08:00
|
|
|
mi = rpmdbFreeIterator(mi);
|
2000-04-27 08:10:28 +08:00
|
|
|
}
|
1999-09-13 04:43:23 +08:00
|
|
|
if (fi->h == NULL) {
|
1999-07-14 22:36:10 +08:00
|
|
|
/* ACK! */
|
|
|
|
continue;
|
|
|
|
}
|
2001-01-24 00:07:28 +08:00
|
|
|
/* XXX header arg unused. */
|
|
|
|
loadFi(fi->h, fi);
|
1999-08-14 04:05:57 +08:00
|
|
|
break;
|
1999-07-14 22:36:10 +08:00
|
|
|
}
|
1999-02-21 11:34:52 +08:00
|
|
|
|
2001-01-24 00:07:28 +08:00
|
|
|
if (fi->fc)
|
2001-04-30 06:43:01 +08:00
|
|
|
fi->fps = xmalloc(fi->fc * sizeof(*fi->fps));
|
1999-07-14 22:36:10 +08:00
|
|
|
}
|
2001-04-30 06:43:01 +08:00
|
|
|
tsi = tsFreeIterator(tsi);
|
1999-01-05 00:44:20 +08:00
|
|
|
|
2000-10-21 00:47:00 +08:00
|
|
|
/* Open all database indices before installing. */
|
2000-07-09 23:17:11 +08:00
|
|
|
rpmdbOpenAll(ts->rpmdb);
|
2000-06-19 19:35:29 +08:00
|
|
|
|
2001-01-27 01:06:09 +08:00
|
|
|
if (!ts->chrootDone) {
|
|
|
|
chdir("/");
|
|
|
|
/*@-unrecog@*/ chroot(ts->rootDir); /*@=unrecog@*/
|
|
|
|
ts->chrootDone = 1;
|
|
|
|
}
|
1999-07-14 22:36:10 +08:00
|
|
|
|
1999-10-30 00:06:01 +08:00
|
|
|
ht = htCreate(totalFileCount * 2, 0, 0, fpHashFunction, fpEqual);
|
1999-10-20 18:22:46 +08:00
|
|
|
fpc = fpCacheCreate(totalFileCount);
|
1999-10-09 04:30:49 +08:00
|
|
|
|
1999-08-07 07:44:25 +08:00
|
|
|
/* ===============================================
|
|
|
|
* Add fingerprint for each file not skipped.
|
|
|
|
*/
|
2001-04-30 06:43:01 +08:00
|
|
|
tsi = tsInitIterator(ts);
|
|
|
|
while ((fi = tsNextIterator(tsi)) != NULL) {
|
1999-10-21 10:40:57 +08:00
|
|
|
fpLookupList(fpc, fi->dnl, fi->bnl, fi->dil, fi->fc, fi->fps);
|
1999-07-14 22:36:10 +08:00
|
|
|
for (i = 0; i < fi->fc; i++) {
|
1999-08-16 03:11:40 +08:00
|
|
|
if (XFA_SKIPPING(fi->actions[i]))
|
|
|
|
continue;
|
2001-04-30 06:43:01 +08:00
|
|
|
/*@-dependenttrans@*/
|
1999-08-16 03:11:40 +08:00
|
|
|
htAddEntry(ht, fi->fps + i, fi);
|
2001-04-30 06:43:01 +08:00
|
|
|
/*@=dependenttrans@*/
|
1999-07-14 22:36:10 +08:00
|
|
|
}
|
|
|
|
}
|
2001-04-30 06:43:01 +08:00
|
|
|
tsi = tsFreeIterator(tsi);
|
1999-07-14 22:36:10 +08:00
|
|
|
|
2001-02-18 01:53:21 +08:00
|
|
|
NOTIFY(ts, (NULL, RPMCALLBACK_TRANS_START, 6, ts->flEntries,
|
2000-10-21 06:04:27 +08:00
|
|
|
NULL, ts->notifyData));
|
1999-07-14 22:36:10 +08:00
|
|
|
|
1999-08-07 07:44:25 +08:00
|
|
|
/* ===============================================
|
1999-08-15 04:01:38 +08:00
|
|
|
* Compute file disposition for each package in transaction set.
|
1999-08-07 07:44:25 +08:00
|
|
|
*/
|
2001-04-30 06:43:01 +08:00
|
|
|
tsi = tsInitIterator(ts);
|
|
|
|
while ((fi = tsNextIterator(tsi)) != NULL) {
|
2000-03-23 23:49:50 +08:00
|
|
|
dbiIndexSet * matches;
|
1999-07-14 22:36:10 +08:00
|
|
|
int knownBad;
|
|
|
|
|
2001-02-18 01:53:21 +08:00
|
|
|
NOTIFY(ts, (NULL, RPMCALLBACK_TRANS_PROGRESS, (fi - ts->flList),
|
|
|
|
ts->flEntries, NULL, ts->notifyData));
|
1999-07-14 22:36:10 +08:00
|
|
|
|
2000-12-13 04:03:45 +08:00
|
|
|
if (fi->fc == 0) continue;
|
|
|
|
|
1999-08-15 04:01:38 +08:00
|
|
|
/* Extract file info for all files in this package from the database. */
|
2000-03-23 23:49:50 +08:00
|
|
|
matches = xcalloc(sizeof(*matches), fi->fc);
|
2000-07-09 23:17:11 +08:00
|
|
|
if (rpmdbFindFpList(ts->rpmdb, fi->fps, matches, fi->fc))
|
2001-04-30 06:43:01 +08:00
|
|
|
return 1; /* XXX WTFO? */
|
1999-07-14 22:36:10 +08:00
|
|
|
|
|
|
|
numShared = 0;
|
|
|
|
for (i = 0; i < fi->fc; i++)
|
1999-09-13 04:43:23 +08:00
|
|
|
numShared += dbiIndexSetCount(matches[i]);
|
1999-03-19 11:39:17 +08:00
|
|
|
|
1999-08-15 04:01:38 +08:00
|
|
|
/* Build sorted file info list for this package. */
|
2001-04-30 06:43:01 +08:00
|
|
|
shared = sharedList = xmalloc((numShared + 1) * sizeof(*sharedList));
|
1999-07-14 22:36:10 +08:00
|
|
|
for (i = 0; i < fi->fc; i++) {
|
1999-08-15 04:01:38 +08:00
|
|
|
/*
|
|
|
|
* Take care not to mark files as replaced in packages that will
|
|
|
|
* have been removed before we will get here.
|
|
|
|
*/
|
1999-09-13 04:43:23 +08:00
|
|
|
for (j = 0; j < dbiIndexSetCount(matches[i]); j++) {
|
1999-08-14 04:05:57 +08:00
|
|
|
int k, ro;
|
1999-09-13 04:43:23 +08:00
|
|
|
ro = dbiIndexRecordOffset(matches[i], j);
|
1999-08-15 04:01:38 +08:00
|
|
|
knownBad = 0;
|
1999-08-14 04:05:57 +08:00
|
|
|
for (k = 0; ro != knownBad && k < ts->orderCount; k++) {
|
|
|
|
switch (ts->order[k].type) {
|
|
|
|
case TR_REMOVED:
|
|
|
|
if (ts->order[k].u.removed.dboffset == ro)
|
|
|
|
knownBad = ro;
|
|
|
|
break;
|
|
|
|
case TR_ADDED:
|
|
|
|
break;
|
1999-01-05 03:11:04 +08:00
|
|
|
}
|
1999-01-05 00:44:20 +08:00
|
|
|
}
|
1999-07-14 22:36:10 +08:00
|
|
|
|
|
|
|
shared->pkgFileNum = i;
|
1999-09-13 04:43:23 +08:00
|
|
|
shared->otherPkg = dbiIndexRecordOffset(matches[i], j);
|
|
|
|
shared->otherFileNum = dbiIndexRecordFileNumber(matches[i], j);
|
1999-07-14 22:36:10 +08:00
|
|
|
shared->isRemoved = (knownBad == ro);
|
|
|
|
shared++;
|
1999-01-05 00:44:20 +08:00
|
|
|
}
|
2000-03-23 23:49:50 +08:00
|
|
|
if (matches[i]) {
|
|
|
|
dbiFreeIndexSet(matches[i]);
|
|
|
|
matches[i] = NULL;
|
|
|
|
}
|
1999-01-05 00:44:20 +08:00
|
|
|
}
|
1999-07-14 22:36:10 +08:00
|
|
|
numShared = shared - sharedList;
|
|
|
|
shared->otherPkg = -1;
|
2001-04-04 04:41:09 +08:00
|
|
|
matches = _free(matches);
|
1999-03-19 11:39:17 +08:00
|
|
|
|
1999-08-15 04:01:38 +08:00
|
|
|
/* Sort file info by other package index (otherPkg) */
|
1999-07-14 22:36:10 +08:00
|
|
|
qsort(sharedList, numShared, sizeof(*shared), sharedCmp);
|
1999-03-19 11:39:17 +08:00
|
|
|
|
1999-08-15 04:01:38 +08:00
|
|
|
/* For all files from this package that are in the database ... */
|
1999-08-14 04:05:57 +08:00
|
|
|
for (i = 0; i < numShared; i = nexti) {
|
|
|
|
int beingRemoved;
|
1999-03-19 11:39:17 +08:00
|
|
|
|
1999-08-15 04:01:38 +08:00
|
|
|
shared = sharedList + i;
|
|
|
|
|
|
|
|
/* Find the end of the files in the other package. */
|
1999-08-14 04:05:57 +08:00
|
|
|
for (nexti = i + 1; nexti < numShared; nexti++) {
|
1999-08-15 04:01:38 +08:00
|
|
|
if (sharedList[nexti].otherPkg != shared->otherPkg)
|
1999-08-14 04:05:57 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1999-08-15 04:01:38 +08:00
|
|
|
/* Is this file from a package being removed? */
|
|
|
|
beingRemoved = 0;
|
1999-07-14 22:36:10 +08:00
|
|
|
for (j = 0; j < ts->numRemovedPackages; j++) {
|
1999-08-15 04:01:38 +08:00
|
|
|
if (ts->removedPackages[j] != shared->otherPkg)
|
|
|
|
continue;
|
|
|
|
beingRemoved = 1;
|
|
|
|
break;
|
1999-03-19 11:39:17 +08:00
|
|
|
}
|
|
|
|
|
1999-08-15 04:01:38 +08:00
|
|
|
/* Determine the fate of each file. */
|
1999-08-14 04:05:57 +08:00
|
|
|
switch (fi->type) {
|
|
|
|
case TR_ADDED:
|
2000-07-09 23:17:11 +08:00
|
|
|
handleInstInstalledFiles(fi, ts->rpmdb, shared, nexti - i,
|
2000-10-21 06:04:27 +08:00
|
|
|
!(beingRemoved || (ts->ignoreSet & RPMPROB_FILTER_REPLACEOLDFILES)),
|
|
|
|
ts->probs, ts->transFlags);
|
1999-08-14 04:05:57 +08:00
|
|
|
break;
|
|
|
|
case TR_REMOVED:
|
|
|
|
if (!beingRemoved)
|
2000-07-09 23:17:11 +08:00
|
|
|
handleRmvdInstalledFiles(fi, ts->rpmdb, shared, nexti - i);
|
1999-08-14 04:05:57 +08:00
|
|
|
break;
|
|
|
|
}
|
1999-03-19 11:39:17 +08:00
|
|
|
}
|
1999-02-17 12:32:55 +08:00
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
free(sharedList);
|
1999-02-17 12:32:55 +08:00
|
|
|
|
1999-08-14 04:05:57 +08:00
|
|
|
/* Update disk space needs on each partition for this package. */
|
1999-08-07 05:35:15 +08:00
|
|
|
handleOverlappedFiles(fi, ht,
|
2000-12-13 04:03:45 +08:00
|
|
|
((ts->ignoreSet & RPMPROB_FILTER_REPLACENEWFILES)
|
2001-01-27 01:06:09 +08:00
|
|
|
? NULL : ts->probs), ts->di);
|
1999-02-17 12:32:55 +08:00
|
|
|
|
1999-08-14 04:05:57 +08:00
|
|
|
/* Check added package has sufficient space on each partition used. */
|
|
|
|
switch (fi->type) {
|
|
|
|
case TR_ADDED:
|
2001-01-27 01:06:09 +08:00
|
|
|
if (!(ts->di && fi->fc))
|
1999-08-14 04:05:57 +08:00
|
|
|
break;
|
2001-01-27 01:06:09 +08:00
|
|
|
for (i = 0; i < ts->filesystemCount; i++) {
|
|
|
|
|
|
|
|
dip = ts->di + i;
|
2000-12-30 05:44:37 +08:00
|
|
|
|
|
|
|
/* XXX Avoid FAT and other file systems that have not inodes. */
|
|
|
|
if (dip->iavail <= 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (adj_fs_blocks(dip->bneeded) > dip->bavail)
|
2001-01-21 23:43:32 +08:00
|
|
|
psAppend(ts->probs, RPMPROB_DISKSPACE, fi->ap,
|
2001-01-27 01:06:09 +08:00
|
|
|
ts->filesystems[i], NULL, NULL,
|
2000-12-30 05:44:37 +08:00
|
|
|
(adj_fs_blocks(dip->bneeded) - dip->bavail) * dip->bsize);
|
|
|
|
|
|
|
|
if (adj_fs_blocks(dip->ineeded) > dip->iavail)
|
2001-01-21 23:43:32 +08:00
|
|
|
psAppend(ts->probs, RPMPROB_DISKNODES, fi->ap,
|
2001-01-27 01:06:09 +08:00
|
|
|
ts->filesystems[i], NULL, NULL,
|
2000-12-30 05:44:37 +08:00
|
|
|
(adj_fs_blocks(dip->ineeded) - dip->iavail));
|
1999-07-14 22:36:10 +08:00
|
|
|
}
|
1999-08-14 04:05:57 +08:00
|
|
|
break;
|
|
|
|
case TR_REMOVED:
|
|
|
|
break;
|
1999-07-14 22:36:10 +08:00
|
|
|
}
|
1999-02-17 12:32:55 +08:00
|
|
|
}
|
2001-04-30 06:43:01 +08:00
|
|
|
tsi = tsFreeIterator(tsi);
|
1999-02-21 11:34:52 +08:00
|
|
|
|
2001-01-27 01:06:09 +08:00
|
|
|
if (ts->chrootDone) {
|
2001-04-21 14:02:09 +08:00
|
|
|
/*@-unrecog@*/ chroot("."); /*@-unrecog@*/
|
2001-01-27 01:06:09 +08:00
|
|
|
ts->chrootDone = 0;
|
|
|
|
chdir(ts->currDir);
|
|
|
|
}
|
1999-02-21 11:34:52 +08:00
|
|
|
|
2001-04-30 06:43:01 +08:00
|
|
|
NOTIFY(ts, (NULL, RPMCALLBACK_TRANS_STOP, 6, ts->flEntries,
|
|
|
|
NULL, ts->notifyData));
|
|
|
|
|
1999-08-07 07:44:25 +08:00
|
|
|
/* ===============================================
|
1999-08-14 04:05:57 +08:00
|
|
|
* Free unused memory as soon as possible.
|
1999-08-07 07:44:25 +08:00
|
|
|
*/
|
1999-02-21 11:34:52 +08:00
|
|
|
|
2001-02-20 01:12:21 +08:00
|
|
|
tsi = tsInitIterator(ts);
|
|
|
|
while ((fi = tsNextIterator(tsi)) != NULL) {
|
2001-02-28 06:08:53 +08:00
|
|
|
psm->fi = fi;
|
1999-08-14 04:05:57 +08:00
|
|
|
if (fi->fc == 0)
|
|
|
|
continue;
|
2001-02-20 01:12:21 +08:00
|
|
|
fi->fps = _free(fi->fps);
|
1999-03-21 05:09:47 +08:00
|
|
|
}
|
2001-02-20 01:12:21 +08:00
|
|
|
tsi = tsFreeIterator(tsi);
|
1999-02-21 11:34:52 +08:00
|
|
|
|
1999-10-20 18:22:46 +08:00
|
|
|
fpCacheFree(fpc);
|
2000-07-09 23:17:11 +08:00
|
|
|
htFree(ht);
|
1999-10-20 18:22:46 +08:00
|
|
|
|
1999-08-14 04:05:57 +08:00
|
|
|
/* ===============================================
|
|
|
|
* If unfiltered problems exist, free memory and return.
|
|
|
|
*/
|
2000-10-21 06:04:27 +08:00
|
|
|
if ((ts->transFlags & RPMTRANS_FLAG_BUILD_PROBS) ||
|
|
|
|
(ts->probs->numProblems && (!okProbs || psTrim(okProbs, ts->probs)))) {
|
|
|
|
*newProbs = ts->probs;
|
1999-02-21 11:34:52 +08:00
|
|
|
|
2001-02-18 01:53:21 +08:00
|
|
|
for (alp = ts->addedPackages.list, fi = ts->flList;
|
1999-08-07 05:35:15 +08:00
|
|
|
(alp - ts->addedPackages.list) < ts->addedPackages.size;
|
1999-07-14 22:36:10 +08:00
|
|
|
alp++, fi++) {
|
|
|
|
headerFree(hdrs[alp - ts->addedPackages.list]);
|
|
|
|
}
|
1999-02-21 11:34:52 +08:00
|
|
|
|
2001-04-30 06:43:01 +08:00
|
|
|
ts->flList = freeFl(ts, ts->flList);
|
|
|
|
ts->flEntries = 0;
|
1999-07-14 22:36:10 +08:00
|
|
|
return ts->orderCount;
|
|
|
|
}
|
1999-02-21 11:34:52 +08:00
|
|
|
|
2001-02-12 06:02:29 +08:00
|
|
|
/* ===============================================
|
|
|
|
* Save removed files before erasing.
|
|
|
|
*/
|
|
|
|
if (ts->transFlags & (RPMTRANS_FLAG_DIRSTASH | RPMTRANS_FLAG_REPACKAGE)) {
|
2001-02-20 01:12:21 +08:00
|
|
|
tsi = tsInitIterator(ts);
|
|
|
|
while ((fi = tsNextIterator(tsi)) != NULL) {
|
2001-02-28 06:08:53 +08:00
|
|
|
psm->fi = fi;
|
2001-02-20 01:12:21 +08:00
|
|
|
switch (fi->type) {
|
2001-02-12 06:02:29 +08:00
|
|
|
case TR_ADDED:
|
|
|
|
break;
|
|
|
|
case TR_REMOVED:
|
|
|
|
if (ts->transFlags & RPMTRANS_FLAG_REPACKAGE)
|
2001-03-03 03:47:45 +08:00
|
|
|
(void) psmStage(psm, PSM_PKGSAVE);
|
2001-02-12 06:02:29 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2001-02-20 01:12:21 +08:00
|
|
|
tsi = tsFreeIterator(tsi);
|
2001-02-12 06:02:29 +08:00
|
|
|
}
|
|
|
|
|
1999-08-07 07:44:25 +08:00
|
|
|
/* ===============================================
|
|
|
|
* Install and remove packages.
|
|
|
|
*/
|
2000-06-19 19:35:29 +08:00
|
|
|
|
2001-01-21 23:43:32 +08:00
|
|
|
lastFailed = -2; /* erased packages have -1 */
|
2001-02-18 01:53:21 +08:00
|
|
|
tsi = tsInitIterator(ts);
|
2001-02-20 01:12:21 +08:00
|
|
|
while ((fi = tsNextIterator(tsi)) != NULL) {
|
2001-01-21 23:43:32 +08:00
|
|
|
int gotfd;
|
|
|
|
|
|
|
|
gotfd = 0;
|
2001-02-28 06:08:53 +08:00
|
|
|
psm->fi = fi;
|
2001-02-18 01:53:21 +08:00
|
|
|
switch (fi->type)
|
2001-04-21 14:02:09 +08:00
|
|
|
{
|
1999-08-14 04:05:57 +08:00
|
|
|
case TR_ADDED:
|
2001-02-18 01:53:21 +08:00
|
|
|
alp = tsGetAlp(tsi);
|
|
|
|
assert(alp == fi->ap);
|
|
|
|
i = alp - ts->addedPackages.list;
|
1999-02-21 11:34:52 +08:00
|
|
|
|
2001-01-21 23:43:32 +08:00
|
|
|
if (alp->fd == NULL) {
|
|
|
|
alp->fd = ts->notify(fi->h, RPMCALLBACK_INST_OPEN_FILE, 0, 0,
|
2000-10-21 06:04:27 +08:00
|
|
|
alp->key, ts->notifyData);
|
2001-01-21 23:43:32 +08:00
|
|
|
if (alp->fd) {
|
1999-07-14 22:36:10 +08:00
|
|
|
Header h;
|
2001-02-13 03:02:15 +08:00
|
|
|
rpmRC rpmrc;
|
1999-02-21 11:34:52 +08:00
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
headerFree(hdrs[i]);
|
2001-01-25 05:35:52 +08:00
|
|
|
hdrs[i] = NULL;
|
2001-02-13 03:02:15 +08:00
|
|
|
rpmrc = rpmReadPackageHeader(alp->fd, &h, NULL, NULL, NULL);
|
|
|
|
if (!(rpmrc == RPMRC_OK || rpmrc == RPMRC_BADSIZE)) {
|
|
|
|
(void)ts->notify(fi->h, RPMCALLBACK_INST_CLOSE_FILE,
|
|
|
|
0, 0, alp->key, ts->notifyData);
|
2001-01-21 23:43:32 +08:00
|
|
|
alp->fd = NULL;
|
1999-07-14 22:36:10 +08:00
|
|
|
ourrc++;
|
|
|
|
} else {
|
2001-04-03 21:41:56 +08:00
|
|
|
hdrs[i] = relocateFileList(ts, fi, alp, h, NULL);
|
1999-07-14 22:36:10 +08:00
|
|
|
headerFree(h);
|
|
|
|
}
|
2001-01-21 23:43:32 +08:00
|
|
|
if (alp->fd) gotfd = 1;
|
1999-05-18 02:44:14 +08:00
|
|
|
}
|
|
|
|
}
|
1999-07-14 22:36:10 +08:00
|
|
|
|
2001-01-21 23:43:32 +08:00
|
|
|
if (alp->fd) {
|
2001-01-25 05:35:52 +08:00
|
|
|
Header hsave = NULL;
|
2000-07-06 04:39:15 +08:00
|
|
|
|
2001-01-25 05:35:52 +08:00
|
|
|
if (fi->h) {
|
|
|
|
hsave = headerLink(fi->h);
|
|
|
|
headerFree(fi->h);
|
|
|
|
}
|
|
|
|
fi->h = headerLink(hdrs[i]);
|
2000-07-06 04:39:15 +08:00
|
|
|
if (alp->multiLib)
|
2000-10-21 06:04:27 +08:00
|
|
|
ts->transFlags |= RPMTRANS_FLAG_MULTILIB;
|
2000-07-06 04:39:15 +08:00
|
|
|
|
2001-01-25 05:35:52 +08:00
|
|
|
if (fi->ap == NULL) fi->ap = alp; /* XXX WTFO? */
|
2001-03-03 03:47:45 +08:00
|
|
|
if (psmStage(psm, PSM_PKGINSTALL)) {
|
1999-07-14 22:36:10 +08:00
|
|
|
ourrc++;
|
|
|
|
lastFailed = i;
|
|
|
|
}
|
2001-01-25 05:35:52 +08:00
|
|
|
headerFree(fi->h);
|
|
|
|
fi->h = NULL;
|
|
|
|
if (hsave) {
|
|
|
|
fi->h = headerLink(hsave);
|
|
|
|
headerFree(hsave);
|
|
|
|
}
|
1999-07-14 22:36:10 +08:00
|
|
|
} else {
|
|
|
|
ourrc++;
|
|
|
|
lastFailed = i;
|
1999-02-21 11:34:52 +08:00
|
|
|
}
|
|
|
|
|
1999-07-14 22:36:10 +08:00
|
|
|
headerFree(hdrs[i]);
|
|
|
|
|
2001-01-21 23:43:32 +08:00
|
|
|
if (gotfd) {
|
2000-10-21 06:04:27 +08:00
|
|
|
(void)ts->notify(fi->h, RPMCALLBACK_INST_CLOSE_FILE, 0, 0,
|
|
|
|
alp->key, ts->notifyData);
|
2001-01-21 23:43:32 +08:00
|
|
|
alp->fd = NULL;
|
|
|
|
}
|
1999-08-14 04:05:57 +08:00
|
|
|
break;
|
|
|
|
case TR_REMOVED:
|
2001-02-18 01:53:21 +08:00
|
|
|
oc = tsGetOc(tsi);
|
2000-08-21 05:39:13 +08:00
|
|
|
/* If install failed, then we shouldn't erase. */
|
1999-08-14 04:05:57 +08:00
|
|
|
if (ts->order[oc].u.removed.dependsOnIndex == lastFailed)
|
|
|
|
break;
|
2000-08-21 05:39:13 +08:00
|
|
|
|
2001-03-03 03:47:45 +08:00
|
|
|
if (psmStage(psm, PSM_PKGERASE))
|
1999-07-14 22:36:10 +08:00
|
|
|
ourrc++;
|
2000-08-21 05:39:13 +08:00
|
|
|
|
2001-01-25 05:35:52 +08:00
|
|
|
break;
|
1999-07-14 22:36:10 +08:00
|
|
|
}
|
2000-07-09 23:17:11 +08:00
|
|
|
(void) rpmdbSync(ts->rpmdb);
|
1999-02-21 11:34:52 +08:00
|
|
|
}
|
2001-02-18 01:53:21 +08:00
|
|
|
tsi = tsFreeIterator(tsi);
|
1999-02-21 11:34:52 +08:00
|
|
|
|
2001-04-30 06:43:01 +08:00
|
|
|
ts->flList = freeFl(ts, ts->flList);
|
|
|
|
ts->flEntries = 0;
|
1999-07-14 22:36:10 +08:00
|
|
|
|
1999-08-07 05:35:15 +08:00
|
|
|
if (ourrc)
|
1999-07-14 22:36:10 +08:00
|
|
|
return -1;
|
|
|
|
else
|
|
|
|
return 0;
|
1999-02-21 11:34:52 +08:00
|
|
|
}
|