2002-05-17 00:55:21 +08:00
|
|
|
/** \ingroup rpmts
|
2000-08-28 03:40:35 +08:00
|
|
|
* \file lib/transaction.c
|
|
|
|
*/
|
|
|
|
|
1998-12-19 03:09:38 +08:00
|
|
|
#include "system.h"
|
|
|
|
|
2013-03-25 15:57:17 +08:00
|
|
|
#include <inttypes.h>
|
|
|
|
|
2008-01-30 19:53:51 +08:00
|
|
|
#include <rpm/rpmlib.h> /* rpmMachineScore, rpmReadPackageFile */
|
2007-12-08 20:02:32 +08:00
|
|
|
#include <rpm/rpmmacro.h> /* XXX for rpmExpand */
|
|
|
|
#include <rpm/rpmlog.h>
|
|
|
|
#include <rpm/rpmdb.h>
|
|
|
|
#include <rpm/rpmds.h>
|
2008-01-30 23:05:29 +08:00
|
|
|
#include <rpm/rpmfileutil.h>
|
|
|
|
#include <rpm/rpmstring.h>
|
2002-05-20 07:37:24 +08:00
|
|
|
|
2008-05-12 17:28:12 +08:00
|
|
|
#include "lib/fprint.h"
|
2010-05-21 20:36:03 +08:00
|
|
|
#include "lib/misc.h"
|
2010-05-31 19:07:46 +08:00
|
|
|
#include "lib/rpmchroot.h"
|
2007-11-23 18:39:29 +08:00
|
|
|
#include "lib/rpmlock.h"
|
2012-11-01 15:45:15 +08:00
|
|
|
#include "lib/rpmds_internal.h"
|
2008-12-19 21:05:54 +08:00
|
|
|
#include "lib/rpmfi_internal.h" /* only internal apis */
|
2008-11-27 16:48:22 +08:00
|
|
|
#include "lib/rpmte_internal.h" /* only internal apis */
|
2007-11-23 18:39:29 +08:00
|
|
|
#include "lib/rpmts_internal.h"
|
2009-01-15 16:28:13 +08:00
|
|
|
#include "rpmio/rpmhook.h"
|
1998-12-19 03:09:38 +08:00
|
|
|
|
2012-10-17 19:55:39 +08:00
|
|
|
#include "lib/rpmplugins.h"
|
|
|
|
|
2009-12-14 21:23:28 +08:00
|
|
|
/* XXX FIXME: merge with existing (broken?) tests in system.h */
|
|
|
|
/* portability fiddles */
|
|
|
|
#if STATFS_IN_SYS_STATVFS
|
|
|
|
#include <sys/statvfs.h>
|
|
|
|
|
|
|
|
#else
|
|
|
|
# if STATFS_IN_SYS_VFS
|
|
|
|
# include <sys/vfs.h>
|
|
|
|
# else
|
|
|
|
# if STATFS_IN_SYS_MOUNT
|
|
|
|
# include <sys/mount.h>
|
|
|
|
# else
|
|
|
|
# if STATFS_IN_SYS_STATFS
|
|
|
|
# include <sys/statfs.h>
|
|
|
|
# endif
|
|
|
|
# endif
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2000-12-13 04:03:45 +08:00
|
|
|
#include "debug.h"
|
|
|
|
|
2009-12-14 21:23:28 +08:00
|
|
|
struct diskspaceInfo_s {
|
2010-02-03 18:45:21 +08:00
|
|
|
char * mntPoint; /*!< File system mount point */
|
2009-12-14 21:23:28 +08:00
|
|
|
dev_t dev; /*!< File system device number. */
|
|
|
|
int64_t bneeded; /*!< No. of blocks needed. */
|
|
|
|
int64_t ineeded; /*!< No. of inodes needed. */
|
|
|
|
int64_t bsize; /*!< File system block size. */
|
|
|
|
int64_t bavail; /*!< No. of blocks available. */
|
|
|
|
int64_t iavail; /*!< No. of inodes available. */
|
|
|
|
int64_t obneeded; /*!< Bookkeeping to avoid duplicate reports */
|
|
|
|
int64_t oineeded; /*!< Bookkeeping to avoid duplicate reports */
|
2012-11-14 16:31:15 +08:00
|
|
|
int64_t bdelta; /*!< Delta for temporary space need on updates */
|
|
|
|
int64_t idelta; /*!< Delta for temporary inode need on updates */
|
2009-12-14 21:23:28 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Adjust for root only reserved space. On linux e2fs, this is 5%. */
|
|
|
|
#define adj_fs_blocks(_nb) (((_nb) * 21) / 20)
|
|
|
|
#define BLOCK_ROUND(size, block) (((size) + (block) - 1) / (block))
|
|
|
|
|
|
|
|
static int rpmtsInitDSI(const rpmts ts)
|
|
|
|
{
|
|
|
|
if (rpmtsFilterFlags(ts) & RPMPROB_FILTER_DISKSPACE)
|
|
|
|
return 0;
|
|
|
|
ts->dsi = _free(ts->dsi);
|
2010-02-03 18:45:21 +08:00
|
|
|
ts->dsi = xcalloc(1, sizeof(*ts->dsi));
|
|
|
|
return 0;
|
|
|
|
}
|
2009-12-14 21:23:28 +08:00
|
|
|
|
2010-02-03 18:45:21 +08:00
|
|
|
static rpmDiskSpaceInfo rpmtsCreateDSI(const rpmts ts, dev_t dev,
|
|
|
|
const char * dirName, int count)
|
|
|
|
{
|
|
|
|
rpmDiskSpaceInfo dsi;
|
|
|
|
struct stat sb;
|
|
|
|
char * resolved_path;
|
|
|
|
char mntPoint[PATH_MAX];
|
|
|
|
int rc;
|
2009-12-14 21:23:28 +08:00
|
|
|
|
|
|
|
#if STATFS_IN_SYS_STATVFS
|
2010-02-03 18:45:21 +08:00
|
|
|
struct statvfs sfb;
|
|
|
|
memset(&sfb, 0, sizeof(sfb));
|
|
|
|
rc = statvfs(dirName, &sfb);
|
2009-12-14 21:23:28 +08:00
|
|
|
#else
|
2010-02-03 18:45:21 +08:00
|
|
|
struct statfs sfb;
|
|
|
|
memset(&sfb, 0, sizeof(sfb));
|
2009-12-14 21:23:28 +08:00
|
|
|
# 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.
|
|
|
|
*/
|
2010-02-03 18:45:21 +08:00
|
|
|
rc = statfs(dirName, &sfb, sizeof(sfb), 0);
|
2009-12-14 21:23:28 +08:00
|
|
|
# else
|
2010-02-03 18:45:21 +08:00
|
|
|
rc = statfs(dirName, &sfb);
|
2009-12-14 21:23:28 +08:00
|
|
|
# endif
|
|
|
|
#endif
|
2010-02-03 18:45:21 +08:00
|
|
|
if (rc)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
rc = stat(dirName, &sb);
|
|
|
|
if (rc)
|
|
|
|
return NULL;
|
2010-02-04 18:02:25 +08:00
|
|
|
if (sb.st_dev != dev)
|
2010-02-03 18:45:21 +08:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
ts->dsi = xrealloc(ts->dsi, (count + 2) * sizeof(*ts->dsi));
|
|
|
|
dsi = ts->dsi + count;
|
|
|
|
memset(dsi, 0, 2 * sizeof(*dsi));
|
|
|
|
|
|
|
|
dsi->dev = sb.st_dev;
|
|
|
|
dsi->bsize = sfb.f_bsize;
|
|
|
|
if (!dsi->bsize)
|
|
|
|
dsi->bsize = 512; /* we need a bsize */
|
|
|
|
dsi->bneeded = 0;
|
|
|
|
dsi->ineeded = 0;
|
2009-12-14 21:23:28 +08:00
|
|
|
#ifdef STATFS_HAS_F_BAVAIL
|
2010-02-03 18:45:21 +08:00
|
|
|
dsi->bavail = (sfb.f_flag & ST_RDONLY) ? 0 : sfb.f_bavail;
|
2009-12-14 21:23:28 +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.
|
|
|
|
*/
|
2010-02-03 18:45:21 +08:00
|
|
|
dsi->bavail = sfb.f_blocks - sfb.f_bfree;
|
2009-12-14 21:23:28 +08:00
|
|
|
#endif
|
2010-02-03 18:45:21 +08:00
|
|
|
/* XXX Avoid FAT and other file systems that have not inodes. */
|
|
|
|
/* XXX assigning negative value to unsigned type */
|
|
|
|
dsi->iavail = !(sfb.f_ffree == 0 && sfb.f_files == 0)
|
|
|
|
? sfb.f_ffree : -1;
|
|
|
|
|
|
|
|
/* Find mount point belonging to this device number */
|
|
|
|
resolved_path = realpath(dirName, mntPoint);
|
|
|
|
if (!resolved_path) {
|
|
|
|
strncpy(mntPoint, dirName, PATH_MAX);
|
2010-02-03 22:42:52 +08:00
|
|
|
mntPoint[PATH_MAX-1] = '\0';
|
2009-12-14 21:23:28 +08:00
|
|
|
}
|
2010-02-03 18:45:21 +08:00
|
|
|
char * end = NULL;
|
|
|
|
while (end != mntPoint) {
|
|
|
|
end = strrchr(mntPoint, '/');
|
2010-02-04 18:02:25 +08:00
|
|
|
if (end == mntPoint) { /* reached "/" */
|
2010-02-03 18:45:21 +08:00
|
|
|
stat("/", &sb);
|
|
|
|
if (dsi->dev != sb.st_dev) {
|
|
|
|
dsi->mntPoint = xstrdup(mntPoint);
|
|
|
|
} else {
|
|
|
|
dsi->mntPoint = xstrdup("/");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
} else if (end) {
|
|
|
|
*end = '\0';
|
2010-02-04 18:02:25 +08:00
|
|
|
} else { /* dirName doesn't start with / - should not happen */
|
2010-02-03 18:45:21 +08:00
|
|
|
dsi->mntPoint = xstrdup(dirName);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
stat(mntPoint, &sb);
|
|
|
|
if (dsi->dev != sb.st_dev) {
|
|
|
|
*end = '/';
|
|
|
|
dsi->mntPoint = xstrdup(mntPoint);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rpmlog(RPMLOG_DEBUG,
|
|
|
|
"0x%08x %8" PRId64 " %12" PRId64 " %12" PRId64" %s\n",
|
|
|
|
(unsigned) dsi->dev, dsi->bsize,
|
|
|
|
dsi->bavail, dsi->iavail,
|
|
|
|
dsi->mntPoint);
|
|
|
|
return dsi;
|
2009-12-14 21:23:28 +08:00
|
|
|
}
|
|
|
|
|
2010-02-02 18:25:59 +08:00
|
|
|
static rpmDiskSpaceInfo rpmtsGetDSI(const rpmts ts, dev_t dev,
|
|
|
|
const char *dirName) {
|
2009-12-14 21:23:28 +08:00
|
|
|
rpmDiskSpaceInfo dsi;
|
|
|
|
dsi = ts->dsi;
|
|
|
|
if (dsi) {
|
|
|
|
while (dsi->bsize && dsi->dev != dev)
|
|
|
|
dsi++;
|
2010-02-03 18:45:21 +08:00
|
|
|
if (dsi->bsize == 0) {
|
|
|
|
/* create new entry */
|
|
|
|
dsi = rpmtsCreateDSI(ts, dev, dirName, dsi - ts->dsi);
|
|
|
|
}
|
2009-12-14 21:23:28 +08:00
|
|
|
}
|
2010-02-02 18:25:59 +08:00
|
|
|
return dsi;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rpmtsUpdateDSI(const rpmts ts, dev_t dev, const char *dirName,
|
|
|
|
rpm_loff_t fileSize, rpm_loff_t prevSize, rpm_loff_t fixupSize,
|
|
|
|
rpmFileAction action)
|
|
|
|
{
|
|
|
|
int64_t bneeded;
|
|
|
|
rpmDiskSpaceInfo dsi = rpmtsGetDSI(ts, dev, dirName);
|
2009-12-14 21:23:28 +08:00
|
|
|
if (dsi == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
bneeded = BLOCK_ROUND(fileSize, dsi->bsize);
|
|
|
|
|
|
|
|
switch (action) {
|
|
|
|
case FA_BACKUP:
|
|
|
|
case FA_SAVE:
|
|
|
|
case FA_ALTNAME:
|
|
|
|
dsi->ineeded++;
|
|
|
|
dsi->bneeded += bneeded;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FA_CREATE:
|
|
|
|
dsi->bneeded += bneeded;
|
2012-11-14 16:31:15 +08:00
|
|
|
dsi->ineeded++;
|
|
|
|
if (prevSize) {
|
|
|
|
dsi->bdelta += BLOCK_ROUND(prevSize, dsi->bsize);
|
|
|
|
dsi->idelta++;
|
|
|
|
}
|
2012-11-14 18:19:49 +08:00
|
|
|
if (fixupSize) {
|
|
|
|
dsi->bdelta += BLOCK_ROUND(fixupSize, dsi->bsize);
|
|
|
|
dsi->idelta++;
|
|
|
|
}
|
|
|
|
|
2009-12-14 21:23:28 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FA_ERASE:
|
|
|
|
dsi->ineeded--;
|
|
|
|
dsi->bneeded -= bneeded;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-02-04 21:55:16 +08:00
|
|
|
/* adjust bookkeeping when requirements shrink */
|
|
|
|
if (dsi->bneeded < dsi->obneeded) dsi->obneeded = dsi->bneeded;
|
|
|
|
if (dsi->ineeded < dsi->oineeded) dsi->oineeded = dsi->ineeded;
|
2009-12-14 21:23:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void rpmtsCheckDSIProblems(const rpmts ts, const rpmte te)
|
|
|
|
{
|
2010-02-26 19:45:47 +08:00
|
|
|
rpmDiskSpaceInfo dsi = ts->dsi;
|
2009-12-14 21:23:28 +08:00
|
|
|
|
2010-02-03 18:45:21 +08:00
|
|
|
if (dsi == NULL || !dsi->bsize)
|
2009-12-14 21:23:28 +08:00
|
|
|
return;
|
|
|
|
|
2010-02-03 18:45:21 +08:00
|
|
|
for (; dsi->bsize; dsi++) {
|
2009-12-14 21:23:28 +08:00
|
|
|
|
|
|
|
if (dsi->bavail >= 0 && adj_fs_blocks(dsi->bneeded) > dsi->bavail) {
|
2010-02-04 21:55:16 +08:00
|
|
|
if (dsi->bneeded > dsi->obneeded) {
|
2010-03-26 21:28:25 +08:00
|
|
|
rpmteAddProblem(te, RPMPROB_DISKSPACE, NULL, dsi->mntPoint,
|
2009-12-14 21:23:28 +08:00
|
|
|
(adj_fs_blocks(dsi->bneeded) - dsi->bavail) * dsi->bsize);
|
|
|
|
dsi->obneeded = dsi->bneeded;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dsi->iavail >= 0 && adj_fs_blocks(dsi->ineeded) > dsi->iavail) {
|
2010-02-04 21:55:16 +08:00
|
|
|
if (dsi->ineeded > dsi->oineeded) {
|
2010-03-26 21:28:25 +08:00
|
|
|
rpmteAddProblem(te, RPMPROB_DISKNODES, NULL, dsi->mntPoint,
|
2009-12-14 21:23:28 +08:00
|
|
|
(adj_fs_blocks(dsi->ineeded) - dsi->iavail));
|
|
|
|
dsi->oineeded = dsi->ineeded;
|
|
|
|
}
|
|
|
|
}
|
2012-11-14 16:31:15 +08:00
|
|
|
|
|
|
|
/* Adjust for temporary -> final disk consumption */
|
|
|
|
dsi->bneeded -= dsi->bdelta;
|
|
|
|
dsi->bdelta = 0;
|
|
|
|
dsi->ineeded -= dsi->idelta;
|
|
|
|
dsi->idelta = 0;
|
2009-12-14 21:23:28 +08:00
|
|
|
}
|
|
|
|
}
|
2004-03-06 02:22:25 +08:00
|
|
|
|
2011-09-01 17:55:30 +08:00
|
|
|
static void rpmtsFreeDSI(rpmts ts)
|
|
|
|
{
|
2010-02-03 18:45:21 +08:00
|
|
|
rpmDiskSpaceInfo dsi;
|
|
|
|
if (ts == NULL)
|
|
|
|
return;
|
|
|
|
dsi = ts->dsi;
|
|
|
|
while (dsi && dsi->bsize != 0) {
|
|
|
|
dsi->mntPoint = _free(dsi->mntPoint);
|
|
|
|
dsi++;
|
|
|
|
}
|
|
|
|
|
|
|
|
ts->dsi = _free(ts->dsi);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-24 15:21:20 +08:00
|
|
|
/* Calculate total number of files involved in transaction */
|
|
|
|
static uint64_t countFiles(rpmts ts)
|
|
|
|
{
|
|
|
|
uint64_t fc = 0;
|
|
|
|
rpmtsi pi = rpmtsiInit(ts);
|
|
|
|
rpmte p;
|
2013-11-11 17:20:49 +08:00
|
|
|
rpmfiles files;
|
|
|
|
while ((p = rpmtsiNext(pi, 0)) != NULL) {
|
|
|
|
files = rpmteFiles(p);
|
|
|
|
fc += rpmfilesFC(files);
|
|
|
|
rpmfilesFree(files);
|
|
|
|
}
|
2011-05-29 03:29:58 +08:00
|
|
|
rpmtsiFree(pi);
|
2009-02-24 15:21:20 +08:00
|
|
|
return fc;
|
|
|
|
}
|
|
|
|
|
2013-11-06 23:09:04 +08:00
|
|
|
static int handleRemovalConflict(rpmfiles fi, int fx, rpmfiles ofi, int ofx)
|
2012-08-24 18:02:09 +08:00
|
|
|
{
|
|
|
|
int rConflicts = 0; /* Removed files don't conflict, normally */
|
2013-11-07 21:57:13 +08:00
|
|
|
rpmFileTypes ft = rpmfiWhatis(rpmfilesFMode(fi, fx));
|
|
|
|
rpmFileTypes oft = rpmfiWhatis(rpmfilesFMode(ofi, ofx));
|
2012-08-24 18:02:09 +08:00
|
|
|
struct stat sb;
|
2012-08-24 18:36:52 +08:00
|
|
|
char *fn = NULL;
|
2012-08-24 18:02:09 +08:00
|
|
|
|
|
|
|
if (oft == XDIR) {
|
|
|
|
/* We can't handle directory changing to anything else */
|
|
|
|
if (ft != XDIR)
|
|
|
|
rConflicts = 1;
|
2012-08-24 18:36:52 +08:00
|
|
|
} else if (oft == LINK) {
|
|
|
|
/* We can't correctly handle directory symlink changing to directory */
|
|
|
|
if (ft == XDIR) {
|
2013-11-07 21:57:13 +08:00
|
|
|
fn = rpmfilesFN(fi, fx);
|
2012-08-24 18:36:52 +08:00
|
|
|
if (stat(fn, &sb) == 0 && S_ISDIR(sb.st_mode))
|
|
|
|
rConflicts = 1;
|
|
|
|
}
|
2012-08-24 18:02:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ...but if the conflicting item is either not on disk, or has
|
|
|
|
* already been changed to the new type, we should be ok afterall.
|
|
|
|
*/
|
|
|
|
if (rConflicts) {
|
2012-08-24 18:36:52 +08:00
|
|
|
if (fn == NULL)
|
2013-11-07 21:57:13 +08:00
|
|
|
fn = rpmfilesFN(fi, fx);
|
2012-08-24 18:02:09 +08:00
|
|
|
if (lstat(fn, &sb) || rpmfiWhatis(sb.st_mode) == ft)
|
|
|
|
rConflicts = 0;
|
|
|
|
}
|
|
|
|
|
2012-08-24 18:36:52 +08:00
|
|
|
free(fn);
|
2012-08-24 18:02:09 +08:00
|
|
|
return rConflicts;
|
|
|
|
}
|
|
|
|
|
2012-08-29 20:04:59 +08:00
|
|
|
/*
|
|
|
|
* Elf files can be "colored", and if enabled in the transaction, the
|
|
|
|
* color can be used to resolve conflicts between elf-64bit and elf-32bit
|
|
|
|
* files to the hosts preferred type, by default 64bit. The non-preferred
|
|
|
|
* type is overwritten or never installed at all and thus the conflict
|
|
|
|
* magically disappears. This is infamously nasty "rpm magic" and entirely
|
|
|
|
* unnecessary with careful packaging.
|
|
|
|
*/
|
|
|
|
static int handleColorConflict(rpmts ts,
|
2013-11-06 23:09:04 +08:00
|
|
|
rpmfs fs, rpmfiles fi, int fx,
|
|
|
|
rpmfs ofs, rpmfiles ofi, int ofx)
|
2012-08-29 20:04:59 +08:00
|
|
|
{
|
|
|
|
int rConflicts = 1;
|
|
|
|
rpm_color_t tscolor = rpmtsColor(ts);
|
|
|
|
|
|
|
|
if (tscolor != 0) {
|
2013-11-07 21:57:13 +08:00
|
|
|
rpm_color_t fcolor = rpmfilesFColor(fi, fx) & tscolor;
|
|
|
|
rpm_color_t ofcolor = rpmfilesFColor(ofi, ofx) & tscolor;
|
2012-08-29 20:04:59 +08:00
|
|
|
|
|
|
|
if (fcolor != 0 && ofcolor != 0 && fcolor != ofcolor) {
|
|
|
|
rpm_color_t prefcolor = rpmtsPrefColor(ts);
|
|
|
|
|
|
|
|
if (fcolor & prefcolor) {
|
|
|
|
if (ofs && !XFA_SKIPPING(rpmfsGetAction(fs, fx)))
|
|
|
|
rpmfsSetAction(ofs, ofx, FA_SKIPCOLOR);
|
|
|
|
rpmfsSetAction(fs, fx, FA_CREATE);
|
|
|
|
rConflicts = 0;
|
|
|
|
} else if (ofcolor & prefcolor) {
|
|
|
|
if (ofs && XFA_SKIPPING(rpmfsGetAction(fs, fx)))
|
|
|
|
rpmfsSetAction(ofs, ofx, FA_CREATE);
|
|
|
|
rpmfsSetAction(fs, fx, FA_SKIPCOLOR);
|
|
|
|
rConflicts = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rConflicts;
|
|
|
|
}
|
|
|
|
|
2001-09-26 04:51:34 +08:00
|
|
|
/**
|
2007-10-06 10:41:49 +08:00
|
|
|
* handleInstInstalledFiles.
|
2003-07-10 04:18:54 +08:00
|
|
|
* @param ts transaction set
|
2007-10-06 10:41:49 +08:00
|
|
|
* @param p current transaction element
|
2003-07-10 04:18:54 +08:00
|
|
|
* @param fi file info set
|
2007-10-06 10:41:49 +08:00
|
|
|
* @param shared shared file info
|
|
|
|
* @param sharedCount no. of shared elements
|
2003-07-10 04:18:54 +08:00
|
|
|
* @param reportConflicts
|
2001-09-26 04:51:34 +08:00
|
|
|
*/
|
2001-10-19 09:24:21 +08:00
|
|
|
/* XXX only ts->{probs,rpmdb} modified */
|
2013-11-06 23:09:04 +08:00
|
|
|
static void handleInstInstalledFile(const rpmts ts, rpmte p, rpmfiles fi, int fx,
|
|
|
|
Header otherHeader, rpmfiles otherFi, int ofx,
|
2008-11-07 17:58:25 +08:00
|
|
|
int beingRemoved)
|
1999-07-14 22:36:10 +08:00
|
|
|
{
|
2008-12-03 17:39:48 +08:00
|
|
|
rpmfs fs = rpmteGetFileStates(p);
|
2013-11-07 21:57:13 +08:00
|
|
|
int isCfgFile = ((rpmfilesFFlags(otherFi, ofx) | rpmfilesFFlags(fi, fx)) & RPMFILE_CONFIG);
|
2002-07-28 08:41:15 +08:00
|
|
|
|
2008-12-03 17:39:48 +08:00
|
|
|
if (XFA_SKIPPING(rpmfsGetAction(fs, fx)))
|
2011-03-04 19:46:06 +08:00
|
|
|
return;
|
2008-11-07 17:58:25 +08:00
|
|
|
|
2013-11-07 21:57:13 +08:00
|
|
|
if (rpmfilesCompare(otherFi, ofx, fi, fx)) {
|
2012-08-24 12:51:55 +08:00
|
|
|
int rConflicts = 1;
|
2011-08-29 19:04:28 +08:00
|
|
|
char rState = RPMFILE_STATE_REPLACED;
|
2008-11-07 17:58:25 +08:00
|
|
|
|
2012-08-24 18:02:09 +08:00
|
|
|
/*
|
|
|
|
* There are some removal conflicts we can't handle. However
|
|
|
|
* if the package has a %pretrans scriptlet, it might be able to
|
|
|
|
* fix the conflict. Let it through on test-transaction to allow
|
|
|
|
* eg yum to get past it, if the conflict is present on the actual
|
|
|
|
* transaction we'll abort. Behaving differently on test is nasty,
|
|
|
|
* but its still better than barfing in middle of large transaction.
|
|
|
|
*/
|
|
|
|
if (beingRemoved) {
|
|
|
|
rConflicts = handleRemovalConflict(fi, fx, otherFi, ofx);
|
|
|
|
if (rConflicts && rpmteHaveTransScript(p, RPMTAG_PRETRANS)) {
|
|
|
|
if (rpmtsFlags(ts) & RPMTRANS_FLAG_TEST)
|
|
|
|
rConflicts = 0;
|
|
|
|
}
|
|
|
|
}
|
2012-08-24 12:51:55 +08:00
|
|
|
|
2012-08-29 20:04:59 +08:00
|
|
|
if (rConflicts) {
|
|
|
|
/* If enabled, resolve colored conflicts to preferred type */
|
|
|
|
rConflicts = handleColorConflict(ts, fs, fi, fx,
|
|
|
|
NULL, otherFi, ofx);
|
|
|
|
/* If resolved, we need to adjust in-rpmdb state too */
|
|
|
|
if (rConflicts == 0 && rpmfsGetAction(fs, fx) == FA_CREATE)
|
2011-08-29 19:04:28 +08:00
|
|
|
rState = RPMFILE_STATE_WRONGCOLOR;
|
2008-11-07 17:58:25 +08:00
|
|
|
}
|
2003-07-10 04:18:54 +08:00
|
|
|
|
2012-08-24 12:51:55 +08:00
|
|
|
/* Somebody used The Force, lets shut up... */
|
|
|
|
if (rpmtsFilterFlags(ts) & RPMPROB_FILTER_REPLACEOLDFILES)
|
|
|
|
rConflicts = 0;
|
|
|
|
|
2008-11-07 17:58:25 +08:00
|
|
|
if (rConflicts) {
|
2009-09-02 17:06:34 +08:00
|
|
|
char *altNEVR = headerGetAsString(otherHeader, RPMTAG_NEVRA);
|
2013-11-07 21:57:13 +08:00
|
|
|
char *fn = rpmfilesFN(fi, fx);
|
2012-04-12 22:50:54 +08:00
|
|
|
rpmteAddProblem(p, RPMPROB_FILE_CONFLICT, altNEVR, fn,
|
2010-03-26 21:22:13 +08:00
|
|
|
headerGetInstance(otherHeader));
|
2012-04-12 22:50:54 +08:00
|
|
|
free(fn);
|
2009-03-08 23:25:45 +08:00
|
|
|
free(altNEVR);
|
1999-08-14 04:05:57 +08:00
|
|
|
}
|
1998-12-19 03:09:38 +08:00
|
|
|
|
2008-11-07 17:58:25 +08:00
|
|
|
/* Save file identifier to mark as state REPLACED. */
|
2008-12-03 17:39:48 +08:00
|
|
|
if ( !(isCfgFile || XFA_SKIPPING(rpmfsGetAction(fs, fx))) ) {
|
2008-11-07 17:58:25 +08:00
|
|
|
if (!beingRemoved)
|
2012-04-12 22:50:54 +08:00
|
|
|
rpmfsAddReplaced(rpmteGetFileStates(p), fx, rState,
|
|
|
|
headerGetInstance(otherHeader), ofx);
|
1998-12-19 03:09:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-17 02:29:33 +08:00
|
|
|
/* Determine config file disposition, skipping missing files (if any). */
|
2008-11-07 17:58:25 +08:00
|
|
|
if (isCfgFile) {
|
2009-03-08 23:38:49 +08:00
|
|
|
int skipMissing = ((rpmtsFlags(ts) & RPMTRANS_FLAG_ALLFILES) ? 0 : 1);
|
2012-04-12 22:50:54 +08:00
|
|
|
rpmFileAction action;
|
2013-11-07 21:57:13 +08:00
|
|
|
action = rpmfilesDecideFate(otherFi, ofx, fi, fx, skipMissing);
|
2008-12-03 17:39:48 +08:00
|
|
|
rpmfsSetAction(fs, fx, action);
|
2008-11-07 17:58:25 +08:00
|
|
|
}
|
2013-11-07 21:57:13 +08:00
|
|
|
rpmfilesSetFReplacedSize(fi, fx, rpmfilesFSize(otherFi, ofx));
|
1998-12-19 03:09:38 +08:00
|
|
|
}
|
|
|
|
|
2000-10-21 00:47:00 +08:00
|
|
|
/**
|
2002-05-20 02:42:25 +08:00
|
|
|
* Update disk space needs on each partition for this package's files.
|
2000-10-21 00:47:00 +08:00
|
|
|
*/
|
2001-10-19 09:24:21 +08:00
|
|
|
/* XXX only ts->{probs,di} modified */
|
2013-11-06 23:09:04 +08:00
|
|
|
static void handleOverlappedFiles(rpmts ts, fingerPrintCache fpc, rpmte p, rpmfiles fi)
|
1999-07-14 22:36:10 +08:00
|
|
|
{
|
2008-06-12 21:41:31 +08:00
|
|
|
rpm_loff_t fixupSize = 0;
|
2001-10-19 00:39:54 +08:00
|
|
|
int i, j;
|
2008-12-03 17:39:48 +08:00
|
|
|
rpmfs fs = rpmteGetFileStates(p);
|
|
|
|
rpmfs otherFs;
|
2013-11-06 23:09:04 +08:00
|
|
|
rpm_count_t fc = rpmfilesFC(fi);
|
2012-08-29 19:31:28 +08:00
|
|
|
int reportConflicts = !(rpmtsFilterFlags(ts) & RPMPROB_FILTER_REPLACENEWFILES);
|
2013-11-08 17:02:09 +08:00
|
|
|
fingerPrint * fpList = rpmfilesFps(fi);
|
2004-03-27 01:27:57 +08:00
|
|
|
|
2012-04-12 22:50:54 +08:00
|
|
|
for (i = 0; i < fc; i++) {
|
2001-11-16 02:22:33 +08:00
|
|
|
struct fingerPrint_s * fiFps;
|
1999-08-15 04:01:38 +08:00
|
|
|
int otherPkgNum, otherFileNum;
|
2013-11-06 23:09:04 +08:00
|
|
|
rpmfiles otherFi;
|
2008-11-27 16:22:45 +08:00
|
|
|
rpmte otherTe;
|
2008-02-05 21:15:41 +08:00
|
|
|
rpmfileAttrs FFlags;
|
2008-10-21 21:45:09 +08:00
|
|
|
struct rpmffi_s * recs;
|
1999-08-15 04:01:38 +08:00
|
|
|
int numRecs;
|
|
|
|
|
2008-12-03 17:39:48 +08:00
|
|
|
if (XFA_SKIPPING(rpmfsGetAction(fs, i)))
|
1999-07-14 22:36:10 +08:00
|
|
|
continue;
|
1998-12-19 03:09:38 +08:00
|
|
|
|
2013-11-07 21:57:13 +08:00
|
|
|
FFlags = rpmfilesFFlags(fi, i);
|
1999-10-20 18:22:46 +08:00
|
|
|
|
2002-05-20 02:42:25 +08:00
|
|
|
fixupSize = 0;
|
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.
|
|
|
|
*/
|
2012-09-14 14:28:50 +08:00
|
|
|
fiFps = fpCacheGetByFp(fpc, fpList, i, &recs, &numRecs);
|
1999-08-18 07:05:24 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If this package is being added, look only at other packages
|
|
|
|
* being added -- removed packages dance to a different tune.
|
2002-05-20 02:42:25 +08:00
|
|
|
*
|
1999-08-18 07:05:24 +08:00
|
|
|
* 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
|
2013-02-17 02:29:33 +08:00
|
|
|
* the file removal occurs only on the last occurrence of an overlapped
|
1999-08-18 07:05:24 +08:00
|
|
|
* file in the transaction set.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-04-12 23:01:52 +08:00
|
|
|
/*
|
|
|
|
* Locate this overlapped file in the set of added/removed packages,
|
|
|
|
* including the package owning it: a package can have self-conflicting
|
|
|
|
* files when directory symlinks are present. Don't compare a file
|
|
|
|
* with itself though...
|
|
|
|
*/
|
2012-04-03 11:11:11 +08:00
|
|
|
for (j = 0; j < numRecs && !(recs[j].p == p && recs[j].fileno == i); j++)
|
2001-06-06 03:26:22 +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 */
|
2001-11-17 03:26:33 +08:00
|
|
|
otherFi = NULL;
|
2008-11-27 16:22:45 +08:00
|
|
|
otherTe = NULL;
|
2008-12-03 17:39:48 +08:00
|
|
|
otherFs = NULL;
|
2008-10-21 21:45:09 +08:00
|
|
|
|
1999-08-14 04:05:57 +08:00
|
|
|
for (otherPkgNum = j - 1; otherPkgNum >= 0; otherPkgNum--) {
|
2008-11-27 16:22:45 +08:00
|
|
|
otherTe = recs[otherPkgNum].p;
|
2008-10-21 21:45:09 +08:00
|
|
|
otherFileNum = recs[otherPkgNum].fileno;
|
2008-12-03 17:39:48 +08:00
|
|
|
otherFs = rpmteGetFileStates(otherTe);
|
2001-11-16 02:22:33 +08:00
|
|
|
|
1999-08-18 07:05:24 +08:00
|
|
|
/* Added packages need only look at other added packages. */
|
2008-11-27 16:22:45 +08:00
|
|
|
if (rpmteType(p) == TR_ADDED && rpmteType(otherTe) != TR_ADDED)
|
2007-09-12 01:07:39 +08:00
|
|
|
continue;
|
1999-08-14 04:05:57 +08:00
|
|
|
|
2002-06-22 02:00:50 +08:00
|
|
|
/* XXX Happens iff fingerprint for incomplete package install. */
|
2013-11-08 19:04:21 +08:00
|
|
|
if (rpmfsGetAction(otherFs, otherFileNum) != FA_UNKNOWN) {
|
|
|
|
otherFi = rpmteFiles(otherTe);
|
2007-09-12 01:07:39 +08:00
|
|
|
break;
|
2013-11-08 19:04:21 +08:00
|
|
|
}
|
1998-12-19 03:09:38 +08:00
|
|
|
}
|
|
|
|
|
2002-05-20 02:42:25 +08:00
|
|
|
switch (rpmteType(p)) {
|
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? */
|
2008-11-12 04:32:23 +08:00
|
|
|
rpmFileAction action;
|
2008-12-03 17:39:48 +08:00
|
|
|
if (rpmfsGetAction(fs, i) != FA_UNKNOWN)
|
2007-09-12 01:07:39 +08:00
|
|
|
break;
|
2013-11-07 21:57:13 +08:00
|
|
|
if (rpmfilesConfigConflict(fi, i)) {
|
1999-08-18 07:05:24 +08:00
|
|
|
/* Here is a non-overlapped pre-existing config file. */
|
2008-11-12 04:32:23 +08:00
|
|
|
action = (FFlags & RPMFILE_NOREPLACE) ?
|
|
|
|
FA_ALTNAME : FA_BACKUP;
|
1999-08-17 06:10:27 +08:00
|
|
|
} else {
|
2008-11-12 04:32:23 +08:00
|
|
|
action = FA_CREATE;
|
1999-08-17 06:10:27 +08:00
|
|
|
}
|
2008-12-03 17:39:48 +08:00
|
|
|
rpmfsSetAction(fs, i, action);
|
2007-09-12 01:07:39 +08:00
|
|
|
break;
|
1999-07-14 22:36:10 +08:00
|
|
|
}
|
1999-08-17 06:10:27 +08:00
|
|
|
|
2001-11-16 08:26:30 +08:00
|
|
|
assert(otherFi != NULL);
|
2000-10-21 00:47:00 +08:00
|
|
|
/* Mark added overlapped non-identical files as a conflict. */
|
2013-11-07 21:57:13 +08:00
|
|
|
if (rpmfilesCompare(otherFi, otherFileNum, fi, i)) {
|
2012-08-29 20:04:59 +08:00
|
|
|
int rConflicts;
|
|
|
|
|
|
|
|
/* If enabled, resolve colored conflicts to preferred type */
|
|
|
|
rConflicts = handleColorConflict(ts, fs, fi, i,
|
|
|
|
otherFs, otherFi, otherFileNum);
|
|
|
|
|
2012-08-29 19:31:28 +08:00
|
|
|
if (rConflicts && reportConflicts) {
|
2013-11-07 21:57:13 +08:00
|
|
|
char *fn = rpmfilesFN(fi, i);
|
2010-03-13 01:41:10 +08:00
|
|
|
rpmteAddProblem(p, RPMPROB_NEW_FILE_CONFLICT,
|
2010-03-26 16:27:39 +08:00
|
|
|
rpmteNEVRA(otherTe), fn, 0);
|
2012-04-12 22:50:54 +08:00
|
|
|
free(fn);
|
2003-07-10 04:18:54 +08:00
|
|
|
}
|
2012-08-17 19:07:05 +08:00
|
|
|
} else {
|
|
|
|
/* Skip create on all but the first instance of a shared file */
|
2013-01-28 18:50:39 +08:00
|
|
|
rpmFileAction oaction = rpmfsGetAction(otherFs, otherFileNum);
|
2013-01-30 20:07:33 +08:00
|
|
|
if (oaction != FA_UNKNOWN && !XFA_SKIPPING(oaction)) {
|
|
|
|
rpmfileAttrs oflags;
|
|
|
|
/* ...but ghosts aren't really created so... */
|
2013-11-07 21:57:13 +08:00
|
|
|
oflags = rpmfilesFFlags(otherFi, otherFileNum);
|
2013-01-30 20:07:33 +08:00
|
|
|
if (!(oflags & RPMFILE_GHOST)) {
|
|
|
|
rpmfsSetAction(fs, i, FA_SKIP);
|
|
|
|
}
|
|
|
|
}
|
1999-07-14 22:36:10 +08:00
|
|
|
}
|
1998-12-19 03:09:38 +08:00
|
|
|
|
2012-08-20 16:12:05 +08:00
|
|
|
/* Skipped files dont need fixup size or backups, %config or not */
|
|
|
|
if (XFA_SKIPPING(rpmfsGetAction(fs, i)))
|
|
|
|
break;
|
|
|
|
|
1999-08-18 07:05:24 +08:00
|
|
|
/* Try to get the disk accounting correct even if a conflict. */
|
2013-11-07 21:57:13 +08:00
|
|
|
fixupSize = rpmfilesFSize(otherFi, otherFileNum);
|
1998-12-19 03:09:38 +08:00
|
|
|
|
2013-11-07 21:57:13 +08:00
|
|
|
if (rpmfilesConfigConflict(fi, i)) {
|
1999-08-18 07:05:24 +08:00
|
|
|
/* Here is an overlapped pre-existing config file. */
|
2008-11-12 04:32:23 +08:00
|
|
|
rpmFileAction action;
|
|
|
|
action = (FFlags & RPMFILE_NOREPLACE) ? FA_ALTNAME : FA_SKIP;
|
2008-12-03 17:39:48 +08:00
|
|
|
rpmfsSetAction(fs, i, action);
|
1999-08-17 06:10:27 +08:00
|
|
|
} else {
|
2012-08-29 19:31:50 +08:00
|
|
|
/* If not decided yet, create it */
|
|
|
|
if (rpmfsGetAction(fs, i) == FA_UNKNOWN)
|
2008-12-03 17:39:48 +08:00
|
|
|
rpmfsSetAction(fs, i, FA_CREATE);
|
1999-08-17 06:10:27 +08:00
|
|
|
}
|
2012-08-29 19:31:50 +08:00
|
|
|
break;
|
2001-11-16 02:22:33 +08:00
|
|
|
|
1999-08-14 04:05:57 +08:00
|
|
|
case TR_REMOVED:
|
1999-08-15 04:01:38 +08:00
|
|
|
if (otherPkgNum >= 0) {
|
2008-12-03 17:39:48 +08:00
|
|
|
assert(otherFi != NULL);
|
|
|
|
/* Here is an overlapped added file we don't want to nuke. */
|
|
|
|
if (rpmfsGetAction(otherFs, otherFileNum) != FA_ERASE) {
|
1999-08-17 06:10:27 +08:00
|
|
|
/* On updates, don't remove files. */
|
2008-12-03 17:39:48 +08:00
|
|
|
rpmfsSetAction(fs, i, FA_SKIP);
|
2007-09-12 01:07:39 +08:00
|
|
|
break;
|
1999-08-15 21:41:06 +08:00
|
|
|
}
|
1999-08-18 07:05:24 +08:00
|
|
|
/* Here is an overlapped removed file: skip in previous. */
|
2008-12-03 17:39:48 +08:00
|
|
|
rpmfsSetAction(otherFs, otherFileNum, FA_SKIP);
|
1999-08-15 04:01:38 +08:00
|
|
|
}
|
2008-12-03 17:39:48 +08:00
|
|
|
if (XFA_SKIPPING(rpmfsGetAction(fs, i)))
|
2007-09-12 01:07:39 +08:00
|
|
|
break;
|
2013-11-07 21:57:13 +08:00
|
|
|
if (rpmfilesFState(fi, i) != RPMFILE_STATE_NORMAL)
|
2007-09-12 01:07:39 +08:00
|
|
|
break;
|
1999-08-15 04:01:38 +08:00
|
|
|
|
2012-04-12 22:27:24 +08:00
|
|
|
/* Pre-existing modified config files need to be saved. */
|
2013-11-07 21:57:13 +08:00
|
|
|
if (rpmfilesConfigConflict(fi, i)) {
|
2012-08-22 16:56:12 +08:00
|
|
|
rpmfsSetAction(fs, i, FA_BACKUP);
|
|
|
|
break;
|
1999-01-19 11:01:52 +08:00
|
|
|
}
|
2012-04-12 22:27:24 +08:00
|
|
|
|
|
|
|
/* Otherwise, we can just erase. */
|
2008-12-03 17:39:48 +08:00
|
|
|
rpmfsSetAction(fs, i, FA_ERASE);
|
2007-09-12 01:07:39 +08:00
|
|
|
break;
|
1999-07-14 22:36:10 +08:00
|
|
|
}
|
2013-11-08 19:50:20 +08:00
|
|
|
rpmfilesFree(otherFi);
|
1998-12-19 03:09:38 +08:00
|
|
|
|
2002-05-20 02:42:25 +08:00
|
|
|
/* Update disk space info for a file. */
|
2012-09-14 12:45:44 +08:00
|
|
|
rpmtsUpdateDSI(ts, fpEntryDev(fpc, fiFps), fpEntryDir(fpc, fiFps),
|
2013-11-07 21:57:13 +08:00
|
|
|
rpmfilesFSize(fi, i), rpmfilesFReplacedSize(fi, i),
|
2010-02-03 18:45:21 +08:00
|
|
|
fixupSize, rpmfsGetAction(fs, i));
|
1998-12-19 03:09:38 +08:00
|
|
|
|
|
|
|
}
|
1999-07-14 22:36:10 +08:00
|
|
|
}
|
1998-12-19 03:09:38 +08:00
|
|
|
|
2001-09-26 04:51:34 +08:00
|
|
|
/**
|
2001-11-11 03:24:19 +08:00
|
|
|
* Ensure that current package is newer than installed package.
|
2012-09-13 16:36:27 +08:00
|
|
|
* @param tspool transaction string pool
|
2001-11-11 03:24:19 +08:00
|
|
|
* @param p current transaction element
|
|
|
|
* @param h installed header
|
2009-02-24 16:13:43 +08:00
|
|
|
* @param ps problem set
|
2001-09-26 04:51:34 +08:00
|
|
|
*/
|
2012-09-13 16:36:27 +08:00
|
|
|
static void ensureOlder(rpmstrPool tspool, const rpmte p, const Header h)
|
2001-11-11 03:24:19 +08:00
|
|
|
{
|
2008-01-30 22:04:40 +08:00
|
|
|
rpmsenseFlags reqFlags = (RPMSENSE_LESS | RPMSENSE_EQUAL);
|
2002-05-20 02:42:25 +08:00
|
|
|
rpmds req;
|
2001-11-11 03:24:19 +08:00
|
|
|
|
2012-09-13 16:36:27 +08:00
|
|
|
req = rpmdsSinglePool(tspool, RPMTAG_REQUIRENAME,
|
|
|
|
rpmteN(p), rpmteEVR(p), reqFlags);
|
2012-09-13 18:12:59 +08:00
|
|
|
if (rpmdsMatches(tspool, h, -1, req, 1, _rpmds_nopromote) == 0) {
|
2009-09-02 17:06:34 +08:00
|
|
|
char * altNEVR = headerGetAsString(h, RPMTAG_NEVRA);
|
2010-03-26 21:22:13 +08:00
|
|
|
rpmteAddProblem(p, RPMPROB_OLDPACKAGE, altNEVR, NULL,
|
|
|
|
headerGetInstance(h));
|
2010-02-26 03:50:20 +08:00
|
|
|
free(altNEVR);
|
|
|
|
}
|
|
|
|
rpmdsFree(req);
|
2001-11-11 03:24:19 +08:00
|
|
|
}
|
1999-01-01 03:16:31 +08:00
|
|
|
|
2009-09-14 22:19:33 +08:00
|
|
|
/**
|
|
|
|
* Check if the curent file in the file iterator is in the
|
|
|
|
* netshardpath and though should be excluded.
|
|
|
|
* @param ts transaction set
|
|
|
|
* @param fi file info set
|
|
|
|
* @returns pointer to matching path or NULL
|
|
|
|
*/
|
|
|
|
static char ** matchNetsharedpath(const rpmts ts, rpmfi fi)
|
|
|
|
{
|
|
|
|
char ** nsp;
|
|
|
|
const char * dn, * bn;
|
|
|
|
size_t dnlen, bnlen;
|
|
|
|
char * s;
|
|
|
|
bn = rpmfiBN(fi);
|
|
|
|
bnlen = strlen(bn);
|
|
|
|
dn = rpmfiDN(fi);
|
|
|
|
dnlen = strlen(dn);
|
|
|
|
for (nsp = ts->netsharedPaths; nsp && *nsp; nsp++) {
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
len = strlen(*nsp);
|
|
|
|
if (dnlen >= len) {
|
|
|
|
if (!rstreqn(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 (!rstreqn(dn, *nsp, dnlen))
|
|
|
|
continue;
|
|
|
|
/* Insure that only the netsharedpath basename is compared. */
|
|
|
|
if ((s = strchr((*nsp) + dnlen, '/')) != NULL && s[1] != '\0')
|
|
|
|
continue;
|
|
|
|
if (!rstreqn(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;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return nsp;
|
|
|
|
}
|
|
|
|
|
2013-11-11 18:06:28 +08:00
|
|
|
static void skipEraseFiles(const rpmts ts, rpmfiles files, rpmfs fs)
|
2009-09-14 22:19:33 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char ** nsp;
|
|
|
|
/*
|
|
|
|
* Skip net shared paths.
|
|
|
|
* Net shared paths are not relative to the current root (though
|
|
|
|
* they do need to take package relocations into account).
|
|
|
|
*/
|
2012-09-03 20:03:12 +08:00
|
|
|
if (ts->netsharedPaths) {
|
2013-11-11 18:06:28 +08:00
|
|
|
rpmfi fi = rpmfilesIter(files, RPMFI_ITER_FWD);
|
2012-09-03 20:03:12 +08:00
|
|
|
while ((i = rpmfiNext(fi)) >= 0)
|
|
|
|
{
|
|
|
|
nsp = matchNetsharedpath(ts, fi);
|
|
|
|
if (nsp && *nsp) {
|
|
|
|
rpmfsSetAction(fs, i, FA_SKIPNETSHARED);
|
|
|
|
}
|
2009-09-14 22:19:33 +08:00
|
|
|
}
|
2013-11-11 18:06:28 +08:00
|
|
|
rpmfiFree(fi);
|
2009-09-14 22:19:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-26 04:51:34 +08:00
|
|
|
/**
|
2002-12-25 01:06:35 +08:00
|
|
|
* Skip any files that do not match install policies.
|
|
|
|
* @param ts transaction set
|
|
|
|
* @param fi file info set
|
2001-09-26 04:51:34 +08:00
|
|
|
*/
|
2013-11-11 18:06:28 +08:00
|
|
|
static void skipInstallFiles(const rpmts ts, rpmfiles files, rpmfs fs)
|
1999-07-14 22:36:10 +08:00
|
|
|
{
|
2008-02-05 18:12:31 +08:00
|
|
|
rpm_color_t tscolor = rpmtsColor(ts);
|
|
|
|
rpm_color_t FColor;
|
2002-12-25 01:06:35 +08:00
|
|
|
int noConfigs = (rpmtsFlags(ts) & RPMTRANS_FLAG_NOCONFIGS);
|
2002-05-20 07:37:24 +08:00
|
|
|
int noDocs = (rpmtsFlags(ts) & RPMTRANS_FLAG_NODOCS);
|
2001-04-03 21:41:56 +08:00
|
|
|
int * drc;
|
|
|
|
char * dff;
|
2001-11-16 08:26:30 +08:00
|
|
|
int dc;
|
2007-12-14 17:38:20 +08:00
|
|
|
int i, j, ix;
|
2013-11-11 18:06:28 +08:00
|
|
|
rpmfi fi = rpmfilesIter(files, RPMFI_ITER_FWD);
|
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
|
|
|
|
2001-04-03 21:41:56 +08:00
|
|
|
/* Compute directory refcount, skip directory if now empty. */
|
2002-05-20 02:42:25 +08:00
|
|
|
dc = rpmfiDC(fi);
|
2008-04-25 19:34:36 +08:00
|
|
|
drc = xcalloc(dc, sizeof(*drc));
|
|
|
|
dff = xcalloc(dc, sizeof(*dff));
|
2001-11-16 08:26:30 +08:00
|
|
|
|
2002-05-20 02:42:25 +08:00
|
|
|
fi = rpmfiInit(fi, 0);
|
2010-11-04 20:09:33 +08:00
|
|
|
while ((i = rpmfiNext(fi)) >= 0) {
|
2002-12-31 09:23:03 +08:00
|
|
|
char ** nsp;
|
2008-11-20 15:40:46 +08:00
|
|
|
const char *flangs;
|
1999-08-07 08:07:51 +08:00
|
|
|
|
2002-05-20 02:42:25 +08:00
|
|
|
ix = rpmfiDX(fi);
|
2001-04-04 04:41:09 +08:00
|
|
|
drc[ix]++;
|
2001-04-03 21:41:56 +08:00
|
|
|
|
1999-08-07 08:07:51 +08:00
|
|
|
/* Don't bother with skipped files */
|
2008-12-03 17:39:48 +08:00
|
|
|
if (XFA_SKIPPING(rpmfsGetAction(fs, i))) {
|
2003-01-02 01:26:46 +08:00
|
|
|
drc[ix]--; dff[ix] = 1;
|
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
|
|
|
|
2002-12-31 09:23:03 +08:00
|
|
|
/* Ignore colored files not in our rainbow. */
|
2003-07-10 04:18:54 +08:00
|
|
|
FColor = rpmfiFColor(fi);
|
|
|
|
if (tscolor && FColor && !(tscolor & FColor)) {
|
2002-12-31 09:23:03 +08:00
|
|
|
drc[ix]--; dff[ix] = 1;
|
2008-12-03 17:39:48 +08:00
|
|
|
rpmfsSetAction(fs, i, FA_SKIPCOLOR);
|
2003-01-02 01:26:46 +08:00
|
|
|
continue;
|
2002-12-31 09:23:03 +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).
|
|
|
|
*/
|
2012-09-03 20:03:12 +08:00
|
|
|
if (ts->netsharedPaths) {
|
|
|
|
nsp = matchNetsharedpath(ts, fi);
|
|
|
|
if (nsp && *nsp) {
|
|
|
|
drc[ix]--; dff[ix] = 1;
|
|
|
|
rpmfsSetAction(fs, i, FA_SKIPNETSHARED);
|
|
|
|
continue;
|
|
|
|
}
|
1999-01-01 03:16:31 +08:00
|
|
|
}
|
|
|
|
|
1999-08-07 08:07:51 +08:00
|
|
|
/*
|
|
|
|
* Skip i18n language specific files.
|
|
|
|
*/
|
2009-03-09 20:57:46 +08:00
|
|
|
flangs = (ts->installLangs != NULL) ? rpmfiFLangs(fi) : NULL;
|
|
|
|
if (flangs != NULL && *flangs != '\0') {
|
2007-12-19 20:13:34 +08:00
|
|
|
const char *l, *le;
|
|
|
|
char **lang;
|
2008-11-30 20:07:03 +08:00
|
|
|
for (lang = ts->installLangs; *lang != NULL; lang++) {
|
2008-11-20 15:40:46 +08:00
|
|
|
for (l = flangs; *l != '\0'; l = le) {
|
2001-04-29 09:05:43 +08:00
|
|
|
for (le = l; *le != '\0' && *le != '|'; le++)
|
2001-06-06 03:26:22 +08:00
|
|
|
{};
|
2009-08-31 18:03:53 +08:00
|
|
|
if ((le-l) > 0 && rstreqn(*lang, l, (le-l)))
|
2007-09-12 01:07:39 +08:00
|
|
|
break;
|
1999-07-14 22:36:10 +08:00
|
|
|
if (*le == '|') le++; /* skip over | */
|
|
|
|
}
|
2001-06-06 03:26:22 +08:00
|
|
|
if (*l != '\0')
|
2007-09-12 01:07:39 +08:00
|
|
|
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;
|
2008-12-03 17:39:48 +08:00
|
|
|
rpmfsSetAction(fs, i, FA_SKIPNSTATE);
|
1999-07-14 22:36:10 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
1999-01-01 03:16:31 +08:00
|
|
|
|
2002-12-25 01:06:35 +08:00
|
|
|
/*
|
|
|
|
* Skip config files if requested.
|
|
|
|
*/
|
|
|
|
if (noConfigs && (rpmfiFFlags(fi) & RPMFILE_CONFIG)) {
|
|
|
|
drc[ix]--; dff[ix] = 1;
|
2008-12-03 17:39:48 +08:00
|
|
|
rpmfsSetAction(fs, i, FA_SKIPNSTATE);
|
2002-12-25 01:06:35 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
1999-08-07 08:07:51 +08:00
|
|
|
/*
|
|
|
|
* Skip documentation if requested.
|
|
|
|
*/
|
2002-05-20 02:42:25 +08:00
|
|
|
if (noDocs && (rpmfiFFlags(fi) & RPMFILE_DOC)) {
|
2001-04-04 04:41:09 +08:00
|
|
|
drc[ix]--; dff[ix] = 1;
|
2008-12-03 17:39:48 +08:00
|
|
|
rpmfsSetAction(fs, 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. */
|
2010-11-04 19:49:07 +08:00
|
|
|
for (j = 0; j < dc; j++) {
|
2010-11-04 20:09:33 +08:00
|
|
|
const char * dn, * bn;
|
|
|
|
size_t dnlen, bnlen;
|
2001-04-03 21:41:56 +08:00
|
|
|
|
|
|
|
if (drc[j]) continue; /* dir still has files. */
|
|
|
|
if (!dff[j]) continue; /* dir was not emptied here. */
|
|
|
|
|
|
|
|
/* Find parent directory and basename. */
|
2013-11-07 21:57:13 +08:00
|
|
|
dn = rpmfilesDN(files, j); dnlen = strlen(dn) - 1;
|
2001-04-03 21:41:56 +08:00
|
|
|
bn = dn + dnlen; bnlen = 0;
|
|
|
|
while (bn > dn && bn[-1] != '/') {
|
|
|
|
bnlen++;
|
|
|
|
dnlen--;
|
|
|
|
bn--;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If explicitly included in the package, skip the directory. */
|
2002-05-20 02:42:25 +08:00
|
|
|
fi = rpmfiInit(fi, 0);
|
|
|
|
while ((i = rpmfiNext(fi)) >= 0) {
|
2002-07-28 08:41:15 +08:00
|
|
|
const char * fdn, * fbn;
|
2008-02-05 18:31:32 +08:00
|
|
|
rpm_mode_t fFMode;
|
2001-04-03 21:41:56 +08:00
|
|
|
|
2008-12-03 17:39:48 +08:00
|
|
|
if (XFA_SKIPPING(rpmfsGetAction(fs, i)))
|
2007-09-12 01:07:39 +08:00
|
|
|
continue;
|
2002-07-28 08:41:15 +08:00
|
|
|
|
|
|
|
fFMode = rpmfiFMode(fi);
|
|
|
|
|
2007-09-26 14:57:26 +08:00
|
|
|
if (rpmfiWhatis(fFMode) != XDIR)
|
2007-09-12 01:07:39 +08:00
|
|
|
continue;
|
2002-07-28 08:41:15 +08:00
|
|
|
fdn = rpmfiDN(fi);
|
|
|
|
if (strlen(fdn) != dnlen)
|
2007-09-12 01:07:39 +08:00
|
|
|
continue;
|
2009-08-31 18:03:53 +08:00
|
|
|
if (!rstreqn(fdn, dn, dnlen))
|
2007-09-12 01:07:39 +08:00
|
|
|
continue;
|
2002-07-28 08:41:15 +08:00
|
|
|
fbn = rpmfiBN(fi);
|
|
|
|
if (strlen(fbn) != bnlen)
|
2007-09-12 01:07:39 +08:00
|
|
|
continue;
|
2009-08-31 18:03:53 +08:00
|
|
|
if (!rstreqn(fbn, bn, bnlen))
|
2007-09-12 01:07:39 +08:00
|
|
|
continue;
|
2008-03-07 15:47:51 +08:00
|
|
|
rpmlog(RPMLOG_DEBUG, "excluding directory %s\n", dn);
|
2008-12-03 17:39:48 +08:00
|
|
|
rpmfsSetAction(fs, i, FA_SKIPNSTATE);
|
2007-09-12 01:07:39 +08:00
|
|
|
break;
|
2001-04-03 21:41:56 +08:00
|
|
|
}
|
2001-01-24 00:07:28 +08:00
|
|
|
}
|
2001-04-03 21:41:56 +08:00
|
|
|
|
2008-04-25 19:34:36 +08:00
|
|
|
free(drc);
|
|
|
|
free(dff);
|
2013-11-11 18:06:28 +08:00
|
|
|
rpmfiFree(fi);
|
1999-07-14 22:36:10 +08:00
|
|
|
}
|
1999-01-01 03:16:31 +08:00
|
|
|
|
2008-11-07 17:58:25 +08:00
|
|
|
#undef HASHTYPE
|
|
|
|
#undef HTKEYTYPE
|
|
|
|
#undef HTDATATYPE
|
|
|
|
|
|
|
|
#define HASHTYPE rpmStringSet
|
2012-09-15 00:55:03 +08:00
|
|
|
#define HTKEYTYPE rpmsid
|
2008-11-07 17:58:25 +08:00
|
|
|
#include "lib/rpmhash.H"
|
|
|
|
#include "lib/rpmhash.C"
|
|
|
|
|
2012-09-15 00:55:03 +08:00
|
|
|
static unsigned int sidHash(rpmsid sid)
|
|
|
|
{
|
|
|
|
return sid;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sidCmp(rpmsid a, rpmsid b)
|
|
|
|
{
|
|
|
|
return (a != b);
|
|
|
|
}
|
|
|
|
|
2008-11-07 17:58:25 +08:00
|
|
|
/* Get a rpmdbMatchIterator containing all files in
|
|
|
|
* the rpmdb that share the basename with one from
|
|
|
|
* the transaction.
|
|
|
|
* @param ts transaction set
|
|
|
|
* @return rpmdbMatchIterator sorted
|
|
|
|
by (package, fileNum)
|
|
|
|
*/
|
|
|
|
static
|
2009-02-24 17:50:23 +08:00
|
|
|
rpmdbMatchIterator rpmFindBaseNamesInDB(rpmts ts, uint64_t fileCount)
|
2008-11-07 17:58:25 +08:00
|
|
|
{
|
2010-03-12 16:20:25 +08:00
|
|
|
tsMembers tsmem = rpmtsMembers(ts);
|
2012-12-19 18:32:52 +08:00
|
|
|
rpmstrPool tspool = rpmtsPool(ts);
|
2008-11-07 17:58:25 +08:00
|
|
|
rpmtsi pi; rpmte p;
|
2013-11-11 18:19:24 +08:00
|
|
|
rpmfiles files;
|
2008-11-07 17:58:25 +08:00
|
|
|
rpmfi fi;
|
|
|
|
rpmdbMatchIterator mi;
|
2009-12-17 23:28:37 +08:00
|
|
|
int oc = 0;
|
2008-11-07 17:58:25 +08:00
|
|
|
const char * baseName;
|
2012-09-15 00:55:03 +08:00
|
|
|
rpmsid baseNameId;
|
2008-11-07 17:58:25 +08:00
|
|
|
|
2009-02-24 17:50:23 +08:00
|
|
|
rpmStringSet baseNames = rpmStringSetCreate(fileCount,
|
2012-09-15 00:55:03 +08:00
|
|
|
sidHash, sidCmp, NULL);
|
2008-11-07 17:58:25 +08:00
|
|
|
|
2010-10-26 14:54:55 +08:00
|
|
|
mi = rpmdbNewIterator(rpmtsGetRdb(ts), RPMDBI_BASENAMES);
|
2008-11-07 17:58:25 +08:00
|
|
|
|
|
|
|
pi = rpmtsiInit(ts);
|
|
|
|
while ((p = rpmtsiNext(pi, 0)) != NULL) {
|
|
|
|
(void) rpmdbCheckSignals();
|
|
|
|
|
2010-03-12 16:20:25 +08:00
|
|
|
rpmtsNotify(ts, NULL, RPMCALLBACK_TRANS_PROGRESS, oc++, tsmem->orderCount);
|
2008-11-07 17:58:25 +08:00
|
|
|
|
|
|
|
/* Gather all installed headers with matching basename's. */
|
2013-11-11 18:19:24 +08:00
|
|
|
files = rpmteFiles(p);
|
|
|
|
fi = rpmfilesIter(files, RPMFI_ITER_FWD);
|
2009-09-07 17:23:21 +08:00
|
|
|
while (rpmfiNext(fi) >= 0) {
|
2008-11-07 17:58:25 +08:00
|
|
|
size_t keylen;
|
2012-09-05 15:41:44 +08:00
|
|
|
|
2012-09-15 00:55:03 +08:00
|
|
|
baseNameId = rpmfiBNId(fi);
|
|
|
|
|
|
|
|
if (rpmStringSetHasEntry(baseNames, baseNameId))
|
2008-11-07 17:58:25 +08:00
|
|
|
continue;
|
|
|
|
|
2012-12-19 18:32:52 +08:00
|
|
|
keylen = rpmstrPoolStrlen(tspool, baseNameId);
|
|
|
|
baseName = rpmstrPoolStr(tspool, baseNameId);
|
2008-11-07 17:58:25 +08:00
|
|
|
if (keylen == 0)
|
|
|
|
keylen++; /* XXX "/" fixup. */
|
2011-04-19 15:02:23 +08:00
|
|
|
rpmdbExtendIterator(mi, baseName, keylen);
|
2012-09-15 00:55:03 +08:00
|
|
|
rpmStringSetAddEntry(baseNames, baseNameId);
|
2013-11-11 18:19:24 +08:00
|
|
|
}
|
|
|
|
rpmfiFree(fi);
|
|
|
|
rpmfilesFree(files);
|
2008-11-07 17:58:25 +08:00
|
|
|
}
|
2011-05-29 03:29:58 +08:00
|
|
|
rpmtsiFree(pi);
|
2008-11-07 17:58:25 +08:00
|
|
|
rpmStringSetFree(baseNames);
|
|
|
|
|
|
|
|
rpmdbSortIterator(mi);
|
|
|
|
/* iterator is now sorted by (recnum, filenum) */
|
|
|
|
return mi;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check files in the transactions against the rpmdb
|
|
|
|
* Lookup all files with the same basename in the rpmdb
|
|
|
|
* and then check for matching finger prints
|
|
|
|
* @param ts transaction set
|
|
|
|
* @param fpc global finger print cache
|
|
|
|
*/
|
|
|
|
static
|
2012-09-14 02:52:38 +08:00
|
|
|
void checkInstalledFiles(rpmts ts, uint64_t fileCount, fingerPrintCache fpc)
|
2008-11-07 17:58:25 +08:00
|
|
|
{
|
2010-03-12 16:20:25 +08:00
|
|
|
tsMembers tsmem = rpmtsMembers(ts);
|
2008-11-07 17:58:25 +08:00
|
|
|
rpmte p;
|
2013-11-07 22:29:25 +08:00
|
|
|
rpmfiles fi;
|
2008-12-03 17:39:48 +08:00
|
|
|
rpmfs fs;
|
2008-11-07 17:58:25 +08:00
|
|
|
int j;
|
|
|
|
unsigned int fileNum;
|
|
|
|
|
|
|
|
rpmdbMatchIterator mi;
|
|
|
|
Header h, newheader;
|
|
|
|
|
|
|
|
rpmlog(RPMLOG_DEBUG, "computing file dispositions\n");
|
|
|
|
|
2009-02-24 17:50:23 +08:00
|
|
|
mi = rpmFindBaseNamesInDB(ts, fileCount);
|
2008-11-07 17:58:25 +08:00
|
|
|
|
|
|
|
/* For all installed headers with matching basename's ... */
|
|
|
|
if (mi == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (rpmdbGetIteratorCount(mi) == 0) {
|
|
|
|
mi = rpmdbFreeIterator(mi);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Loop over all packages from the rpmdb */
|
|
|
|
h = newheader = rpmdbNextIterator(mi);
|
|
|
|
while (h != NULL) {
|
|
|
|
headerGetFlags hgflags = HEADERGET_MINMEM;
|
|
|
|
struct rpmtd_s bnames, dnames, dindexes, ostates;
|
2012-09-14 13:41:01 +08:00
|
|
|
fingerPrint *fpp = NULL;
|
2008-11-07 17:58:25 +08:00
|
|
|
unsigned int installedPkg;
|
2012-08-30 14:45:49 +08:00
|
|
|
int beingRemoved = 0;
|
2013-11-07 22:29:25 +08:00
|
|
|
rpmfiles otherFi = NULL;
|
2012-08-30 14:45:49 +08:00
|
|
|
rpmte *removedPkg = NULL;
|
2008-11-07 17:58:25 +08:00
|
|
|
|
|
|
|
/* Is this package being removed? */
|
|
|
|
installedPkg = rpmdbGetIteratorOffset(mi);
|
2012-08-30 14:45:49 +08:00
|
|
|
if (removedHashGetEntry(tsmem->removedPackages, installedPkg,
|
|
|
|
&removedPkg, NULL, NULL)) {
|
|
|
|
beingRemoved = 1;
|
2013-11-08 19:50:20 +08:00
|
|
|
otherFi = rpmteFiles(removedPkg[0]);
|
2012-08-30 14:45:49 +08:00
|
|
|
}
|
2008-11-07 17:58:25 +08:00
|
|
|
|
|
|
|
h = headerLink(h);
|
2012-08-30 15:19:26 +08:00
|
|
|
/* For packages being removed we can use its rpmfi to avoid all this */
|
|
|
|
if (!beingRemoved) {
|
|
|
|
headerGet(h, RPMTAG_BASENAMES, &bnames, hgflags);
|
|
|
|
headerGet(h, RPMTAG_DIRNAMES, &dnames, hgflags);
|
|
|
|
headerGet(h, RPMTAG_DIRINDEXES, &dindexes, hgflags);
|
|
|
|
headerGet(h, RPMTAG_FILESTATES, &ostates, hgflags);
|
|
|
|
}
|
2008-11-07 17:58:25 +08:00
|
|
|
|
2008-12-03 17:39:48 +08:00
|
|
|
/* loop over all interesting files in that package */
|
2008-11-07 17:58:25 +08:00
|
|
|
do {
|
2012-09-14 14:28:50 +08:00
|
|
|
int fpIx;
|
2008-11-07 17:58:25 +08:00
|
|
|
struct rpmffi_s * recs;
|
|
|
|
int numRecs;
|
2008-11-25 21:33:11 +08:00
|
|
|
const char * dirName;
|
|
|
|
const char * baseName;
|
|
|
|
|
2012-09-06 00:40:07 +08:00
|
|
|
/* lookup finger print for this file */
|
2008-11-07 17:58:25 +08:00
|
|
|
fileNum = rpmdbGetIteratorFileNum(mi);
|
2012-08-30 15:19:26 +08:00
|
|
|
if (!beingRemoved) {
|
|
|
|
rpmtdSetIndex(&bnames, fileNum);
|
|
|
|
rpmtdSetIndex(&dindexes, fileNum);
|
|
|
|
rpmtdSetIndex(&dnames, *rpmtdGetUint32(&dindexes));
|
|
|
|
rpmtdSetIndex(&ostates, fileNum);
|
|
|
|
|
|
|
|
dirName = rpmtdGetString(&dnames);
|
|
|
|
baseName = rpmtdGetString(&bnames);
|
2008-11-25 21:33:11 +08:00
|
|
|
|
2012-09-14 19:19:32 +08:00
|
|
|
fpLookup(fpc, dirName, baseName, &fpp);
|
2012-09-14 14:28:50 +08:00
|
|
|
fpIx = 0;
|
2008-11-07 17:58:25 +08:00
|
|
|
} else {
|
2013-11-08 17:02:09 +08:00
|
|
|
fpp = rpmfilesFps(otherFi);
|
2012-09-14 14:28:50 +08:00
|
|
|
fpIx = fileNum;
|
2008-11-07 17:58:25 +08:00
|
|
|
}
|
2012-09-06 00:40:07 +08:00
|
|
|
|
2008-11-07 17:58:25 +08:00
|
|
|
/* search for files in the transaction with same finger print */
|
2012-09-14 14:28:50 +08:00
|
|
|
fpCacheGetByFp(fpc, fpp, fpIx, &recs, &numRecs);
|
2008-11-07 17:58:25 +08:00
|
|
|
|
2012-09-14 14:28:50 +08:00
|
|
|
for (j = 0; j < numRecs; j++) {
|
2008-11-26 23:29:55 +08:00
|
|
|
p = recs[j].p;
|
2013-11-07 22:29:25 +08:00
|
|
|
fi = rpmteFiles(p);
|
2008-12-03 17:39:48 +08:00
|
|
|
fs = rpmteGetFileStates(p);
|
2008-11-07 17:58:25 +08:00
|
|
|
|
|
|
|
/* Determine the fate of each file. */
|
|
|
|
switch (rpmteType(p)) {
|
|
|
|
case TR_ADDED:
|
|
|
|
if (!otherFi) {
|
2012-01-28 23:07:42 +08:00
|
|
|
/* XXX What to do if this fails? */
|
2013-11-07 22:29:25 +08:00
|
|
|
otherFi = rpmfilesNew(NULL, h, RPMTAG_BASENAMES, RPMFI_KEEPHEADER);
|
2008-11-07 17:58:25 +08:00
|
|
|
}
|
2013-11-07 22:29:25 +08:00
|
|
|
handleInstInstalledFile(ts, p, fi, recs[j].fileno,
|
|
|
|
h, otherFi, fileNum, beingRemoved);
|
2008-11-07 17:58:25 +08:00
|
|
|
break;
|
|
|
|
case TR_REMOVED:
|
|
|
|
if (!beingRemoved) {
|
2008-11-25 21:33:11 +08:00
|
|
|
if (*rpmtdGetChar(&ostates) == RPMFILE_STATE_NORMAL)
|
2008-12-03 17:39:48 +08:00
|
|
|
rpmfsSetAction(fs, recs[j].fileno, FA_SKIP);
|
2008-11-07 17:58:25 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2013-11-08 19:50:20 +08:00
|
|
|
rpmfilesFree(fi);
|
2008-11-07 17:58:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
newheader = rpmdbNextIterator(mi);
|
|
|
|
|
|
|
|
} while (newheader==h);
|
|
|
|
|
2013-11-07 22:29:25 +08:00
|
|
|
otherFi = rpmfilesFree(otherFi);
|
2012-08-30 15:19:26 +08:00
|
|
|
if (!beingRemoved) {
|
|
|
|
rpmtdFreeData(&ostates);
|
|
|
|
rpmtdFreeData(&bnames);
|
|
|
|
rpmtdFreeData(&dnames);
|
|
|
|
rpmtdFreeData(&dindexes);
|
2012-09-14 13:41:01 +08:00
|
|
|
free(fpp);
|
2012-08-30 15:19:26 +08:00
|
|
|
}
|
2008-11-07 17:58:25 +08:00
|
|
|
headerFree(h);
|
|
|
|
h = newheader;
|
|
|
|
}
|
|
|
|
|
2011-05-29 03:29:58 +08:00
|
|
|
rpmdbFreeIterator(mi);
|
2008-11-07 17:58:25 +08:00
|
|
|
}
|
|
|
|
|
2010-02-26 02:42:55 +08:00
|
|
|
#define badArch(_a) (rpmMachineScore(RPM_MACHTABLE_INSTARCH, (_a)) == 0)
|
|
|
|
#define badOs(_a) (rpmMachineScore(RPM_MACHTABLE_INSTOS, (_a)) == 0)
|
|
|
|
|
2009-02-24 16:13:43 +08:00
|
|
|
/*
|
|
|
|
* For packages being installed:
|
|
|
|
* - verify package arch/os.
|
|
|
|
* - verify package epoch:version-release is newer.
|
|
|
|
*/
|
|
|
|
static rpmps checkProblems(rpmts ts)
|
|
|
|
{
|
|
|
|
rpm_color_t tscolor = rpmtsColor(ts);
|
2010-02-26 02:42:55 +08:00
|
|
|
rpmprobFilterFlags probFilter = rpmtsFilterFlags(ts);
|
2012-09-13 16:36:27 +08:00
|
|
|
rpmstrPool tspool = rpmtsPool(ts);
|
2009-02-24 16:13:43 +08:00
|
|
|
rpmtsi pi = rpmtsiInit(ts);
|
|
|
|
rpmte p;
|
|
|
|
|
|
|
|
/* The ordering doesn't matter here */
|
|
|
|
/* XXX Only added packages need be checked. */
|
|
|
|
rpmlog(RPMLOG_DEBUG, "sanity checking %d elements\n", rpmtsNElements(ts));
|
|
|
|
while ((p = rpmtsiNext(pi, TR_ADDED)) != NULL) {
|
|
|
|
|
2010-02-26 02:42:55 +08:00
|
|
|
if (!(probFilter & RPMPROB_FILTER_IGNOREARCH) && badArch(rpmteA(p)))
|
2010-03-26 16:27:39 +08:00
|
|
|
rpmteAddProblem(p, RPMPROB_BADARCH, rpmteA(p), NULL, 0);
|
2009-02-24 16:13:43 +08:00
|
|
|
|
2010-02-26 02:42:55 +08:00
|
|
|
if (!(probFilter & RPMPROB_FILTER_IGNOREOS) && badOs(rpmteO(p)))
|
2010-03-26 16:27:39 +08:00
|
|
|
rpmteAddProblem(p, RPMPROB_BADOS, rpmteO(p), NULL, 0);
|
2009-02-24 16:13:43 +08:00
|
|
|
|
2010-02-26 02:42:55 +08:00
|
|
|
if (!(probFilter & RPMPROB_FILTER_OLDPACKAGE)) {
|
2009-02-24 16:13:43 +08:00
|
|
|
Header h;
|
2011-05-30 16:45:41 +08:00
|
|
|
rpmdbMatchIterator mi;
|
2010-10-22 16:49:52 +08:00
|
|
|
mi = rpmtsInitIterator(ts, RPMDBI_NAME, rpmteN(p), 0);
|
2009-02-24 16:13:43 +08:00
|
|
|
while ((h = rpmdbNextIterator(mi)) != NULL)
|
2012-09-13 16:36:27 +08:00
|
|
|
ensureOlder(tspool, p, h);
|
2011-05-30 16:45:41 +08:00
|
|
|
rpmdbFreeIterator(mi);
|
2009-02-24 16:13:43 +08:00
|
|
|
}
|
|
|
|
|
2010-02-26 02:42:55 +08:00
|
|
|
if (!(probFilter & RPMPROB_FILTER_REPLACEPKG)) {
|
2010-03-26 21:22:13 +08:00
|
|
|
Header h;
|
2011-05-30 16:45:41 +08:00
|
|
|
rpmdbMatchIterator mi;
|
2010-10-22 16:49:52 +08:00
|
|
|
mi = rpmtsInitIterator(ts, RPMDBI_NAME, rpmteN(p), 0);
|
2009-02-24 16:13:43 +08:00
|
|
|
rpmdbSetIteratorRE(mi, RPMTAG_EPOCH, RPMMIRE_STRCMP, rpmteE(p));
|
|
|
|
rpmdbSetIteratorRE(mi, RPMTAG_VERSION, RPMMIRE_STRCMP, rpmteV(p));
|
|
|
|
rpmdbSetIteratorRE(mi, RPMTAG_RELEASE, RPMMIRE_STRCMP, rpmteR(p));
|
|
|
|
if (tscolor) {
|
|
|
|
rpmdbSetIteratorRE(mi, RPMTAG_ARCH, RPMMIRE_STRCMP, rpmteA(p));
|
|
|
|
rpmdbSetIteratorRE(mi, RPMTAG_OS, RPMMIRE_STRCMP, rpmteO(p));
|
|
|
|
}
|
|
|
|
|
2010-03-26 21:22:13 +08:00
|
|
|
if ((h = rpmdbNextIterator(mi)) != NULL) {
|
|
|
|
rpmteAddProblem(p, RPMPROB_PKG_INSTALLED, NULL, NULL,
|
|
|
|
headerGetInstance(h));
|
2009-02-24 16:13:43 +08:00
|
|
|
}
|
2011-05-30 16:45:41 +08:00
|
|
|
rpmdbFreeIterator(mi);
|
2009-02-24 16:13:43 +08:00
|
|
|
}
|
2012-08-07 14:52:15 +08:00
|
|
|
|
|
|
|
if (!(probFilter & RPMPROB_FILTER_FORCERELOCATE))
|
|
|
|
rpmteAddRelocProblems(p);
|
2009-02-24 16:13:43 +08:00
|
|
|
}
|
2011-05-29 03:29:58 +08:00
|
|
|
rpmtsiFree(pi);
|
2010-03-13 01:41:10 +08:00
|
|
|
return rpmtsProblems(ts);
|
2009-02-24 16:13:43 +08:00
|
|
|
}
|
|
|
|
|
2008-03-17 22:03:51 +08:00
|
|
|
/*
|
|
|
|
* Run pre/post transaction scripts for transaction set
|
|
|
|
* param ts Transaction set
|
2010-03-29 23:36:21 +08:00
|
|
|
* param goal PKG_PRETRANS/PKG_POSTTRANS
|
|
|
|
* return 0 on success
|
2008-03-17 22:03:51 +08:00
|
|
|
*/
|
2010-03-29 23:36:21 +08:00
|
|
|
static int runTransScripts(rpmts ts, pkgGoal goal)
|
2008-03-17 22:03:51 +08:00
|
|
|
{
|
2011-11-22 17:24:22 +08:00
|
|
|
int rc = 0;
|
2008-03-17 22:03:51 +08:00
|
|
|
rpmte p;
|
2010-03-29 23:36:21 +08:00
|
|
|
rpmtsi pi = rpmtsiInit(ts);
|
2008-03-17 22:03:51 +08:00
|
|
|
while ((p = rpmtsiNext(pi, TR_ADDED)) != NULL) {
|
2011-11-22 17:24:22 +08:00
|
|
|
rc += rpmteProcess(p, goal);
|
2008-03-17 22:03:51 +08:00
|
|
|
}
|
2011-05-29 03:29:58 +08:00
|
|
|
rpmtsiFree(pi);
|
2011-11-22 17:24:22 +08:00
|
|
|
return rc;
|
2008-03-17 22:03:51 +08:00
|
|
|
}
|
|
|
|
|
2010-08-31 04:32:27 +08:00
|
|
|
static int rpmtsSetupCollections(rpmts ts)
|
2010-06-22 05:04:37 +08:00
|
|
|
{
|
|
|
|
/* seenCollectionsPost and TEs are basically a key-value pair. each item in
|
|
|
|
* seenCollectionsPost is a collection that has been seen from any package,
|
|
|
|
* and the associated index in the TEs is the last transaction element
|
|
|
|
* where that collection was seen. */
|
|
|
|
ARGV_t seenCollectionsPost = NULL;
|
|
|
|
rpmte *TEs = NULL;
|
|
|
|
int numSeenPost = 0;
|
|
|
|
|
|
|
|
/* seenCollectionsPre is a list of collections that have been seen from
|
|
|
|
* only removed packages */
|
|
|
|
ARGV_t seenCollectionsPre = NULL;
|
|
|
|
int numSeenPre = 0;
|
|
|
|
|
|
|
|
ARGV_const_t collname;
|
|
|
|
int installing = 1;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
rpmte p;
|
|
|
|
rpmtsi pi = rpmtsiInit(ts);
|
|
|
|
while ((p = rpmtsiNext(pi, 0)) != NULL) {
|
|
|
|
/* detect when we switch from installing to removing packages, and
|
|
|
|
* update the lastInCollectionAdd lists */
|
|
|
|
if (installing && rpmteType(p) == TR_REMOVED) {
|
|
|
|
installing = 0;
|
|
|
|
for (i = 0; i < numSeenPost; i++) {
|
|
|
|
rpmteAddToLastInCollectionAdd(TEs[i], seenCollectionsPost[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-31 04:32:27 +08:00
|
|
|
rpmteSetupCollectionPlugins(p);
|
|
|
|
|
2010-06-22 05:04:37 +08:00
|
|
|
for (collname = rpmteCollections(p); collname && *collname; collname++) {
|
|
|
|
/* figure out if we've seen this collection in post before */
|
|
|
|
for (i = 0; i < numSeenPost && strcmp(*collname, seenCollectionsPost[i]); i++) {
|
|
|
|
}
|
|
|
|
if (i < numSeenPost) {
|
|
|
|
/* we've seen the collection, update the index */
|
|
|
|
TEs[i] = p;
|
|
|
|
} else {
|
|
|
|
/* haven't seen the collection yet, add it */
|
|
|
|
argvAdd(&seenCollectionsPost, *collname);
|
|
|
|
TEs = xrealloc(TEs, sizeof(*TEs) * (numSeenPost + 1));
|
|
|
|
TEs[numSeenPost] = p;
|
|
|
|
numSeenPost++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* figure out if we've seen this collection in pre remove before */
|
|
|
|
if (installing == 0) {
|
|
|
|
for (i = 0; i < numSeenPre && strcmp(*collname, seenCollectionsPre[i]); i++) {
|
|
|
|
}
|
|
|
|
if (i >= numSeenPre) {
|
|
|
|
/* haven't seen this collection, add it */
|
|
|
|
rpmteAddToFirstInCollectionRemove(p, *collname);
|
|
|
|
argvAdd(&seenCollectionsPre, *collname);
|
|
|
|
numSeenPre++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-05-31 17:43:15 +08:00
|
|
|
rpmtsiFree(pi);
|
2010-06-22 05:04:37 +08:00
|
|
|
|
|
|
|
/* we've looked at all the rpmte's, update the lastInCollectionAny lists */
|
|
|
|
for (i = 0; i < numSeenPost; i++) {
|
|
|
|
rpmteAddToLastInCollectionAny(TEs[i], seenCollectionsPost[i]);
|
|
|
|
if (installing == 1) {
|
|
|
|
/* lastInCollectionAdd is only updated above if packages were
|
|
|
|
* removed. if nothing is removed in the transaction, we need to
|
|
|
|
* update that list here */
|
|
|
|
rpmteAddToLastInCollectionAdd(TEs[i], seenCollectionsPost[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
argvFree(seenCollectionsPost);
|
|
|
|
argvFree(seenCollectionsPre);
|
|
|
|
_free(TEs);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-02-24 19:41:18 +08:00
|
|
|
static int rpmtsSetup(rpmts ts, rpmprobFilterFlags ignoreSet)
|
|
|
|
{
|
|
|
|
rpm_tid_t tid = (rpm_tid_t) time(NULL);
|
|
|
|
int dbmode = (rpmtsFlags(ts) & RPMTRANS_FLAG_TEST) ? O_RDONLY : (O_RDWR|O_CREAT);
|
|
|
|
|
|
|
|
if (rpmtsFlags(ts) & RPMTRANS_FLAG_NOSCRIPTS)
|
|
|
|
(void) rpmtsSetFlags(ts, (rpmtsFlags(ts) | _noTransScripts | _noTransTriggers));
|
|
|
|
if (rpmtsFlags(ts) & RPMTRANS_FLAG_NOTRIGGERS)
|
|
|
|
(void) rpmtsSetFlags(ts, (rpmtsFlags(ts) | _noTransTriggers));
|
|
|
|
|
2011-05-25 19:52:39 +08:00
|
|
|
if (rpmtsFlags(ts) & (RPMTRANS_FLAG_JUSTDB | RPMTRANS_FLAG_TEST))
|
|
|
|
(void) rpmtsSetFlags(ts, (rpmtsFlags(ts) | _noTransScripts | _noTransTriggers | RPMTRANS_FLAG_NOCOLLECTIONS));
|
2009-02-24 19:41:18 +08:00
|
|
|
|
2011-01-28 19:15:09 +08:00
|
|
|
/*
|
|
|
|
* Make sure the database is open RDWR for package install/erase.
|
|
|
|
* Note that we initialize chroot state here even if it's just "/" as
|
|
|
|
* this ensures we can successfully perform open(".") which is
|
|
|
|
* required to reliably restore cwd after Lua scripts.
|
|
|
|
*/
|
2010-05-31 19:07:46 +08:00
|
|
|
if (rpmtsOpenDB(ts, dbmode) || rpmChrootSet(rpmtsRootDir(ts)))
|
|
|
|
return -1;
|
2009-02-24 19:41:18 +08:00
|
|
|
|
|
|
|
ts->ignoreSet = ignoreSet;
|
|
|
|
(void) rpmtsSetTid(ts, tid);
|
|
|
|
|
|
|
|
/* Get available space on mounted file systems. */
|
|
|
|
(void) rpmtsInitDSI(ts);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rpmtsFinish(rpmts ts)
|
|
|
|
{
|
2010-05-31 19:07:46 +08:00
|
|
|
return rpmChrootSet(NULL);
|
2009-02-24 19:41:18 +08:00
|
|
|
}
|
|
|
|
|
2009-02-24 18:13:26 +08:00
|
|
|
static int rpmtsPrepare(rpmts ts)
|
2009-02-24 17:15:53 +08:00
|
|
|
{
|
2010-03-12 16:20:25 +08:00
|
|
|
tsMembers tsmem = rpmtsMembers(ts);
|
2009-02-24 17:15:53 +08:00
|
|
|
rpmtsi pi;
|
|
|
|
rpmte p;
|
2010-05-31 23:00:33 +08:00
|
|
|
int rc = 0;
|
2009-02-24 17:50:23 +08:00
|
|
|
uint64_t fileCount = countFiles(ts);
|
2012-02-28 20:53:29 +08:00
|
|
|
const char *dbhome = NULL;
|
|
|
|
struct stat dbstat;
|
2009-02-24 17:15:53 +08:00
|
|
|
|
2012-12-19 18:32:52 +08:00
|
|
|
fingerPrintCache fpc = fpCacheCreate(fileCount/2 + 10001, rpmtsPool(ts));
|
2009-02-24 16:40:43 +08:00
|
|
|
|
2009-02-24 17:50:23 +08:00
|
|
|
rpmlog(RPMLOG_DEBUG, "computing %" PRIu64 " file fingerprints\n", fileCount);
|
|
|
|
|
|
|
|
/* Skip netshared paths, not our i18n files, and excluded docs */
|
|
|
|
pi = rpmtsiInit(ts);
|
2009-09-14 22:19:33 +08:00
|
|
|
while ((p = rpmtsiNext(pi, 0)) != NULL) {
|
2013-11-11 18:06:28 +08:00
|
|
|
rpmfiles files = rpmteFiles(p);
|
|
|
|
if (rpmfilesFC(files) > 0) {
|
|
|
|
rpmfs fs = rpmteGetFileStates(p);
|
|
|
|
if (rpmteType(p) == TR_ADDED) {
|
|
|
|
skipInstallFiles(ts, files, fs);
|
|
|
|
} else {
|
|
|
|
skipEraseFiles(ts, files, fs);
|
|
|
|
}
|
2009-09-14 22:19:33 +08:00
|
|
|
}
|
2013-11-11 18:06:28 +08:00
|
|
|
rpmfilesFree(files);
|
2009-02-24 17:50:23 +08:00
|
|
|
}
|
2011-05-31 17:43:15 +08:00
|
|
|
rpmtsiFree(pi);
|
2009-02-24 17:50:23 +08:00
|
|
|
|
2010-05-31 19:07:46 +08:00
|
|
|
/* Open rpmdb & enter chroot for fingerprinting if necessary */
|
|
|
|
if (rpmdbOpenAll(ts->rdb) || rpmChrootIn()) {
|
|
|
|
rc = -1;
|
|
|
|
goto exit;
|
2009-02-24 18:13:26 +08:00
|
|
|
}
|
|
|
|
|
2010-03-12 16:20:25 +08:00
|
|
|
rpmtsNotify(ts, NULL, RPMCALLBACK_TRANS_START, 6, tsmem->orderCount);
|
2012-09-14 03:19:40 +08:00
|
|
|
/* Add fingerprint for each file not skipped. */
|
|
|
|
fpCachePopulate(fpc, ts, fileCount);
|
2009-02-24 16:40:43 +08:00
|
|
|
/* check against files in the rpmdb */
|
2012-09-14 02:52:38 +08:00
|
|
|
checkInstalledFiles(ts, fileCount, fpc);
|
2009-02-24 16:40:43 +08:00
|
|
|
|
2012-02-28 20:53:29 +08:00
|
|
|
dbhome = rpmdbHome(rpmtsGetRdb(ts));
|
|
|
|
/* If we can't stat, ignore db growth. Probably not right but... */
|
|
|
|
if (dbhome && stat(dbhome, &dbstat))
|
|
|
|
dbhome = NULL;
|
2010-02-02 18:25:59 +08:00
|
|
|
|
2009-02-24 16:40:43 +08:00
|
|
|
pi = rpmtsiInit(ts);
|
|
|
|
while ((p = rpmtsiNext(pi, 0)) != NULL) {
|
2013-11-11 17:47:39 +08:00
|
|
|
rpmfiles files = rpmteFiles(p);;
|
|
|
|
if (files == NULL)
|
2009-02-24 16:40:43 +08:00
|
|
|
continue; /* XXX can't happen */
|
|
|
|
|
|
|
|
(void) rpmswEnter(rpmtsOp(ts, RPMTS_OP_FINGERPRINT), 0);
|
|
|
|
/* check files in ts against each other and update disk space
|
|
|
|
needs on each partition for this package. */
|
2013-11-11 17:47:39 +08:00
|
|
|
handleOverlappedFiles(ts, fpc, p, files);
|
2009-02-24 16:40:43 +08:00
|
|
|
|
|
|
|
/* Check added package has sufficient space on each partition used. */
|
|
|
|
if (rpmteType(p) == TR_ADDED) {
|
2012-02-28 21:22:32 +08:00
|
|
|
/*
|
|
|
|
* Try to estimate space needed for rpmdb growth: guess that the
|
|
|
|
* db grows 4 times the header size (indexes and all).
|
|
|
|
*/
|
|
|
|
if (dbhome) {
|
|
|
|
int64_t hsize = rpmteHeaderSize(p) * 4;
|
|
|
|
rpmtsUpdateDSI(ts, dbstat.st_dev, dbhome,
|
|
|
|
hsize, 0, 0, FA_CREATE);
|
|
|
|
}
|
|
|
|
|
2009-02-24 16:40:43 +08:00
|
|
|
rpmtsCheckDSIProblems(ts, p);
|
|
|
|
}
|
|
|
|
(void) rpmswExit(rpmtsOp(ts, RPMTS_OP_FINGERPRINT), 0);
|
2013-11-11 17:47:39 +08:00
|
|
|
rpmfilesFree(files);
|
2009-02-24 16:40:43 +08:00
|
|
|
}
|
2011-05-31 17:43:15 +08:00
|
|
|
rpmtsiFree(pi);
|
2010-03-12 16:20:25 +08:00
|
|
|
rpmtsNotify(ts, NULL, RPMCALLBACK_TRANS_STOP, 6, tsmem->orderCount);
|
2009-02-24 17:15:53 +08:00
|
|
|
|
2009-02-24 18:13:26 +08:00
|
|
|
/* return from chroot if done earlier */
|
2010-05-31 19:07:46 +08:00
|
|
|
if (rpmChrootOut())
|
|
|
|
rc = -1;
|
2009-02-24 18:13:26 +08:00
|
|
|
|
2012-02-01 23:48:20 +08:00
|
|
|
/* On actual transaction, file info sets are not needed after this */
|
|
|
|
if (!(rpmtsFlags(ts) & (RPMTRANS_FLAG_TEST|RPMTRANS_FLAG_BUILD_PROBS))) {
|
|
|
|
pi = rpmtsiInit(ts);
|
|
|
|
while ((p = rpmtsiNext(pi, 0)) != NULL) {
|
|
|
|
rpmteSetFI(p, NULL);
|
|
|
|
}
|
|
|
|
rpmtsiFree(pi);
|
2009-02-24 17:50:23 +08:00
|
|
|
}
|
2009-02-24 18:13:26 +08:00
|
|
|
|
|
|
|
exit:
|
2011-05-29 03:29:58 +08:00
|
|
|
fpCacheFree(fpc);
|
2010-02-03 18:45:21 +08:00
|
|
|
rpmtsFreeDSI(ts);
|
2009-02-24 18:13:26 +08:00
|
|
|
return rc;
|
2009-02-24 16:40:43 +08:00
|
|
|
}
|
|
|
|
|
2008-11-24 21:31:31 +08:00
|
|
|
/*
|
|
|
|
* Transaction main loop: install and remove packages
|
|
|
|
*/
|
|
|
|
static int rpmtsProcess(rpmts ts)
|
|
|
|
{
|
|
|
|
rpmtsi pi; rpmte p;
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
pi = rpmtsiInit(ts);
|
|
|
|
while ((p = rpmtsiNext(pi, 0)) != NULL) {
|
2010-03-29 23:36:21 +08:00
|
|
|
int failed;
|
2008-11-24 21:31:31 +08:00
|
|
|
|
2008-11-24 21:33:23 +08:00
|
|
|
rpmlog(RPMLOG_DEBUG, "========== +++ %s %s-%s 0x%x\n",
|
|
|
|
rpmteNEVR(p), rpmteA(p), rpmteO(p), rpmteColor(p));
|
|
|
|
|
2010-05-07 19:31:25 +08:00
|
|
|
failed = rpmteProcess(p, rpmteType(p));
|
2008-11-25 17:46:20 +08:00
|
|
|
if (failed) {
|
2010-02-25 18:36:09 +08:00
|
|
|
rpmlog(RPMLOG_ERR, "%s: %s %s\n", rpmteNEVRA(p),
|
2010-03-29 23:36:21 +08:00
|
|
|
rpmteTypeString(p), failed > 1 ? _("skipped") : _("failed"));
|
2008-11-25 17:46:20 +08:00
|
|
|
rc++;
|
|
|
|
}
|
2008-11-24 21:31:31 +08:00
|
|
|
}
|
2011-05-29 03:29:58 +08:00
|
|
|
rpmtsiFree(pi);
|
2008-11-24 21:31:31 +08:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2013-04-03 21:49:50 +08:00
|
|
|
rpmRC rpmtsSetupTransactionPlugins(rpmts ts)
|
2012-10-17 19:55:39 +08:00
|
|
|
{
|
|
|
|
rpmRC rc = RPMRC_OK;
|
|
|
|
char *plugins = NULL, *plugin = NULL;
|
|
|
|
const char *delims = ",";
|
2013-04-03 19:06:19 +08:00
|
|
|
rpmPlugins tsplugins;
|
2012-10-17 19:55:39 +08:00
|
|
|
|
2013-04-03 21:49:50 +08:00
|
|
|
/*
|
|
|
|
* Assume allocated equals initialized. There are some oddball cases
|
|
|
|
* (verification of non-installed package) where this is not true
|
|
|
|
* currently but that's not a new issue.
|
|
|
|
*/
|
|
|
|
if (ts->plugins != NULL)
|
|
|
|
return RPMRC_OK;
|
|
|
|
|
2012-10-17 19:55:39 +08:00
|
|
|
plugins = rpmExpand("%{?__transaction_plugins}", NULL);
|
|
|
|
if (!plugins || rstreq(plugins, "")) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2013-04-03 19:06:19 +08:00
|
|
|
tsplugins = rpmtsPlugins(ts);
|
2012-10-17 19:55:39 +08:00
|
|
|
plugin = strtok(plugins, delims);
|
|
|
|
while(plugin != NULL) {
|
|
|
|
rpmlog(RPMLOG_DEBUG, "plugin is %s\n", plugin);
|
2013-04-03 19:06:19 +08:00
|
|
|
if (!rpmpluginsPluginAdded(tsplugins, plugin)) {
|
|
|
|
if (rpmpluginsAddPlugin(tsplugins, "transaction",
|
2012-11-09 15:36:45 +08:00
|
|
|
plugin) == RPMRC_FAIL) {
|
2012-10-17 19:55:39 +08:00
|
|
|
/* any configured plugin failing to load is a failure */
|
|
|
|
rc = RPMRC_FAIL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
plugin = strtok(NULL, delims);
|
|
|
|
}
|
|
|
|
|
|
|
|
exit:
|
|
|
|
free(plugins);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2004-03-27 01:27:57 +08:00
|
|
|
int rpmtsRun(rpmts ts, rpmps okProbs, rpmprobFilterFlags ignoreSet)
|
|
|
|
{
|
2009-02-24 19:55:27 +08:00
|
|
|
int rc = -1; /* assume failure */
|
2012-09-12 18:37:54 +08:00
|
|
|
tsMembers tsmem = rpmtsMembers(ts);
|
2013-03-11 18:46:30 +08:00
|
|
|
rpmtxn txn = NULL;
|
2010-03-13 01:41:10 +08:00
|
|
|
rpmps tsprobs = NULL;
|
2012-12-01 00:35:44 +08:00
|
|
|
int TsmPreDone = 0; /* TsmPre hook hasn't been called */
|
|
|
|
|
2010-11-18 18:50:55 +08:00
|
|
|
/* Force default 022 umask during transaction for consistent results */
|
|
|
|
mode_t oldmask = umask(022);
|
2001-11-12 00:17:57 +08:00
|
|
|
|
2011-05-18 13:28:07 +08:00
|
|
|
/* Empty transaction, nothing to do */
|
2009-02-24 19:55:27 +08:00
|
|
|
if (rpmtsNElements(ts) <= 0) {
|
2011-05-18 13:28:07 +08:00
|
|
|
rc = 0;
|
2009-02-24 19:55:27 +08:00
|
|
|
goto exit;
|
|
|
|
}
|
2001-11-12 00:17:57 +08:00
|
|
|
|
2004-10-10 03:40:09 +08:00
|
|
|
/* If we are in test mode, then there's no need for transaction lock. */
|
2008-03-17 18:04:39 +08:00
|
|
|
if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_TEST)) {
|
2013-03-11 18:46:30 +08:00
|
|
|
if (!(txn = rpmtxnBegin(ts, RPMTXN_WRITE))) {
|
2009-02-24 19:55:27 +08:00
|
|
|
goto exit;
|
|
|
|
}
|
2004-04-08 07:50:35 +08:00
|
|
|
}
|
2004-03-27 01:27:57 +08:00
|
|
|
|
2009-02-24 19:41:18 +08:00
|
|
|
/* Setup flags and such, open the DB */
|
|
|
|
if (rpmtsSetup(ts, ignoreSet)) {
|
2009-02-24 19:55:27 +08:00
|
|
|
goto exit;
|
1999-07-14 22:36:10 +08:00
|
|
|
}
|
|
|
|
|
2010-08-31 04:32:27 +08:00
|
|
|
rpmtsSetupCollections(ts);
|
2010-06-22 05:04:37 +08:00
|
|
|
|
2009-02-24 16:13:43 +08:00
|
|
|
/* Check package set for problems */
|
2010-03-13 01:41:10 +08:00
|
|
|
tsprobs = checkProblems(ts);
|
1999-10-20 18:22:46 +08:00
|
|
|
|
2012-10-17 19:55:39 +08:00
|
|
|
/* Run pre transaction hook for all plugins */
|
2012-12-01 00:35:44 +08:00
|
|
|
TsmPreDone = 1;
|
2013-04-03 19:06:19 +08:00
|
|
|
if (rpmpluginsCallTsmPre(rpmtsPlugins(ts), ts) == RPMRC_FAIL) {
|
2012-10-17 19:55:39 +08:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2004-03-27 01:27:57 +08:00
|
|
|
/* Run pre-transaction scripts, but only if there are no known
|
2009-01-17 20:15:50 +08:00
|
|
|
* problems up to this point and not disabled otherwise. */
|
2013-04-10 16:31:41 +08:00
|
|
|
if (!((rpmtsFlags(ts) & (RPMTRANS_FLAG_BUILD_PROBS|RPMTRANS_FLAG_NOPRETRANS))
|
2010-04-14 19:14:52 +08:00
|
|
|
|| (rpmpsNumProblems(tsprobs)))) {
|
2008-03-07 15:47:51 +08:00
|
|
|
rpmlog(RPMLOG_DEBUG, "running pre-transaction scripts\n");
|
2011-11-22 18:34:46 +08:00
|
|
|
runTransScripts(ts, PKG_PRETRANS);
|
1999-07-14 22:36:10 +08:00
|
|
|
}
|
2010-03-13 01:41:10 +08:00
|
|
|
tsprobs = rpmpsFree(tsprobs);
|
1999-02-21 11:34:52 +08:00
|
|
|
|
2009-02-24 16:40:43 +08:00
|
|
|
/* Compute file disposition for each package in transaction set. */
|
2009-02-24 18:13:26 +08:00
|
|
|
if (rpmtsPrepare(ts)) {
|
2009-02-24 19:55:27 +08:00
|
|
|
goto exit;
|
2004-03-27 01:27:57 +08:00
|
|
|
}
|
2010-03-13 01:41:10 +08:00
|
|
|
/* Check again for problems (now including file conflicts, duh */
|
|
|
|
tsprobs = rpmtsProblems(ts);
|
2003-11-24 03:50:52 +08:00
|
|
|
|
2009-02-24 18:35:21 +08:00
|
|
|
/* If unfiltered problems exist, free memory and return. */
|
2010-04-14 19:14:52 +08:00
|
|
|
if ((rpmtsFlags(ts) & RPMTRANS_FLAG_BUILD_PROBS) || (rpmpsNumProblems(tsprobs))) {
|
2010-03-12 16:20:25 +08:00
|
|
|
rc = tsmem->orderCount;
|
2009-02-24 19:55:27 +08:00
|
|
|
goto exit;
|
2004-03-27 01:27:57 +08:00
|
|
|
}
|
2004-03-06 02:22:25 +08:00
|
|
|
|
2010-03-13 01:41:10 +08:00
|
|
|
/* Free up memory taken by problem sets */
|
|
|
|
tsprobs = rpmpsFree(tsprobs);
|
|
|
|
rpmtsCleanProblems(ts);
|
|
|
|
|
2012-09-12 18:37:54 +08:00
|
|
|
/*
|
|
|
|
* Free up the global string pool unless we expect it to be needed
|
|
|
|
* again. During the transaction, private pools will be used for
|
|
|
|
* rpmfi's etc.
|
|
|
|
*/
|
|
|
|
if (!(rpmtsFlags(ts) & (RPMTRANS_FLAG_TEST|RPMTRANS_FLAG_BUILD_PROBS)))
|
|
|
|
tsmem->pool = rpmstrPoolFree(tsmem->pool);
|
|
|
|
|
2009-02-24 19:55:27 +08:00
|
|
|
/* Actually install and remove packages, get final exit code */
|
|
|
|
rc = rpmtsProcess(ts) ? -1 : 0;
|
2004-03-06 02:22:25 +08:00
|
|
|
|
2009-02-24 19:55:27 +08:00
|
|
|
/* Run post-transaction scripts unless disabled */
|
2013-04-10 16:31:41 +08:00
|
|
|
if (!(rpmtsFlags(ts) & (RPMTRANS_FLAG_NOPOSTTRANS))) {
|
2008-03-07 15:47:51 +08:00
|
|
|
rpmlog(RPMLOG_DEBUG, "running post-transaction scripts\n");
|
2010-03-29 23:36:21 +08:00
|
|
|
runTransScripts(ts, PKG_POSTTRANS);
|
2004-03-27 01:27:57 +08:00
|
|
|
}
|
|
|
|
|
2012-12-01 00:35:44 +08:00
|
|
|
exit:
|
2012-10-17 19:55:39 +08:00
|
|
|
/* Run post transaction hook for all plugins */
|
2012-12-01 00:35:44 +08:00
|
|
|
if (TsmPreDone) /* If TsmPre hook has been called, call the TsmPost hook */
|
2013-04-03 19:06:19 +08:00
|
|
|
rpmpluginsCallTsmPost(rpmtsPlugins(ts), ts, rc);
|
2012-10-17 19:55:39 +08:00
|
|
|
|
2009-02-24 19:41:18 +08:00
|
|
|
/* Finish up... */
|
2010-11-18 18:50:55 +08:00
|
|
|
(void) umask(oldmask);
|
2009-02-24 19:41:18 +08:00
|
|
|
(void) rpmtsFinish(ts);
|
2011-05-29 03:29:58 +08:00
|
|
|
rpmpsFree(tsprobs);
|
2013-03-11 18:46:30 +08:00
|
|
|
rpmtxnEnd(txn);
|
2009-02-24 19:55:27 +08:00
|
|
|
return rc;
|
2004-03-06 02:22:25 +08:00
|
|
|
}
|