2001-10-30 04:12:35 +08:00
|
|
|
/** \ingroup rpmdep
|
|
|
|
* \file lib/rpmal.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "system.h"
|
|
|
|
|
|
|
|
|
2009-03-17 00:02:16 +08:00
|
|
|
#include <rpm/rpmte.h>
|
2007-12-08 20:02:32 +08:00
|
|
|
#include <rpm/rpmfi.h>
|
2012-09-12 19:33:17 +08:00
|
|
|
#include <rpm/rpmstrpool.h>
|
2009-04-03 18:07:42 +08:00
|
|
|
|
|
|
|
#include "lib/rpmal.h"
|
2010-05-21 20:36:03 +08:00
|
|
|
#include "lib/misc.h"
|
2010-06-22 05:04:38 +08:00
|
|
|
#include "lib/rpmte_internal.h"
|
2012-10-05 15:13:09 +08:00
|
|
|
#include "lib/rpmds_internal.h"
|
2012-10-05 16:25:49 +08:00
|
|
|
#include "lib/rpmfi_internal.h"
|
2001-10-30 04:12:35 +08:00
|
|
|
|
|
|
|
#include "debug.h"
|
|
|
|
|
2007-09-12 01:07:39 +08:00
|
|
|
typedef struct availablePackage_s * availablePackage;
|
2009-03-17 00:02:16 +08:00
|
|
|
typedef int rpmalNum;
|
2001-10-31 12:00:58 +08:00
|
|
|
|
2001-11-05 06:00:11 +08:00
|
|
|
/** \ingroup rpmdep
|
|
|
|
* Info about a single package to be installed.
|
|
|
|
*/
|
|
|
|
struct availablePackage_s {
|
2009-03-17 00:02:16 +08:00
|
|
|
rpmte p; /*!< transaction member */
|
2002-05-20 02:42:25 +08:00
|
|
|
rpmds provides; /*!< Provides: dependencies. */
|
2012-10-05 16:35:11 +08:00
|
|
|
rpmds obsoletes; /*!< Obsoletes: dependencies. */
|
2002-05-20 02:42:25 +08:00
|
|
|
rpmfi fi; /*!< File info set. */
|
2001-11-05 06:00:11 +08:00
|
|
|
};
|
|
|
|
|
2001-10-30 07:39:51 +08:00
|
|
|
/** \ingroup rpmdep
|
|
|
|
* A single available item (e.g. a Provides: dependency).
|
|
|
|
*/
|
2010-09-22 21:37:12 +08:00
|
|
|
typedef struct availableIndexEntry_s {
|
2009-03-17 00:02:16 +08:00
|
|
|
rpmalNum pkgNum; /*!< Containing package index. */
|
2009-03-20 15:22:41 +08:00
|
|
|
unsigned int entryIx; /*!< Dependency index. */
|
2010-09-22 21:37:12 +08:00
|
|
|
} * availableIndexEntry;
|
2001-10-30 07:39:51 +08:00
|
|
|
|
2009-03-20 15:22:41 +08:00
|
|
|
struct fileNameEntry_s {
|
2012-09-13 00:20:52 +08:00
|
|
|
rpmsid dirName;
|
|
|
|
rpmsid baseName;
|
2001-10-30 07:39:51 +08:00
|
|
|
};
|
|
|
|
|
2009-03-20 15:22:41 +08:00
|
|
|
#undef HASHTYPE
|
|
|
|
#undef HTKEYTYPE
|
|
|
|
#undef HTDATATYPE
|
2012-10-05 16:34:22 +08:00
|
|
|
#define HASHTYPE rpmalDepHash
|
2012-09-12 21:51:12 +08:00
|
|
|
#define HTKEYTYPE rpmsid
|
2009-03-20 15:22:41 +08:00
|
|
|
#define HTDATATYPE struct availableIndexEntry_s
|
|
|
|
#include "lib/rpmhash.H"
|
|
|
|
#include "lib/rpmhash.C"
|
|
|
|
|
|
|
|
#undef HASHTYPE
|
|
|
|
#undef HTKEYTYPE
|
|
|
|
#undef HTDATATYPE
|
|
|
|
#define HASHTYPE rpmalFileHash
|
|
|
|
#define HTKEYTYPE struct fileNameEntry_s
|
2010-09-22 21:37:12 +08:00
|
|
|
#define HTDATATYPE struct availableIndexEntry_s
|
2009-03-20 15:22:41 +08:00
|
|
|
#include "lib/rpmhash.H"
|
|
|
|
#include "lib/rpmhash.C"
|
|
|
|
|
2001-10-30 07:39:51 +08:00
|
|
|
/** \ingroup rpmdep
|
|
|
|
* Set of available packages, items, and directories.
|
|
|
|
*/
|
2002-05-28 02:12:12 +08:00
|
|
|
struct rpmal_s {
|
2012-09-12 19:33:17 +08:00
|
|
|
rpmstrPool pool; /*!< String pool */
|
2001-11-05 06:00:11 +08:00
|
|
|
availablePackage list; /*!< Set of packages. */
|
2012-10-05 16:34:22 +08:00
|
|
|
rpmalDepHash providesHash;
|
2012-10-05 16:35:11 +08:00
|
|
|
rpmalDepHash obsoletesHash;
|
2009-03-20 15:22:41 +08:00
|
|
|
rpmalFileHash fileHash;
|
2001-11-05 06:00:11 +08:00
|
|
|
int delta; /*!< Delta for pkg list reallocation. */
|
|
|
|
int size; /*!< No. of pkgs in list. */
|
|
|
|
int alloced; /*!< No. of pkgs allocated for list. */
|
2011-09-01 18:19:18 +08:00
|
|
|
rpmtransFlags tsflags; /*!< Transaction control flags. */
|
2008-02-05 18:12:31 +08:00
|
|
|
rpm_color_t tscolor; /*!< Transaction color. */
|
2009-06-11 22:16:03 +08:00
|
|
|
rpm_color_t prefcolor; /*!< Transaction preferred color. */
|
2001-10-30 07:39:51 +08:00
|
|
|
};
|
|
|
|
|
2001-10-30 04:12:35 +08:00
|
|
|
/**
|
|
|
|
* Destroy available item index.
|
|
|
|
* @param al available list
|
|
|
|
*/
|
2002-05-28 02:12:12 +08:00
|
|
|
static void rpmalFreeIndex(rpmal al)
|
2001-10-30 04:12:35 +08:00
|
|
|
{
|
2012-10-05 16:34:22 +08:00
|
|
|
al->providesHash = rpmalDepHashFree(al->providesHash);
|
2012-10-05 16:35:11 +08:00
|
|
|
al->obsoletesHash = rpmalDepHashFree(al->obsoletesHash);
|
2009-03-20 15:22:41 +08:00
|
|
|
al->fileHash = rpmalFileHashFree(al->fileHash);
|
2001-10-30 04:12:35 +08:00
|
|
|
}
|
|
|
|
|
2012-09-12 19:33:17 +08:00
|
|
|
rpmal rpmalCreate(rpmstrPool pool, int delta, rpmtransFlags tsflags,
|
2011-09-01 18:19:18 +08:00
|
|
|
rpm_color_t tscolor, rpm_color_t prefcolor)
|
2001-10-30 04:12:35 +08:00
|
|
|
{
|
2002-05-28 02:12:12 +08:00
|
|
|
rpmal al = xcalloc(1, sizeof(*al));
|
2001-10-30 04:12:35 +08:00
|
|
|
|
2012-09-12 21:50:41 +08:00
|
|
|
/* transition time safe-guard */
|
|
|
|
assert(pool != NULL);
|
|
|
|
|
2012-09-12 19:33:17 +08:00
|
|
|
al->pool = rpmstrPoolLink(pool);
|
2001-10-30 04:12:35 +08:00
|
|
|
al->delta = delta;
|
|
|
|
al->size = 0;
|
|
|
|
al->alloced = al->delta;
|
2009-03-20 15:22:41 +08:00
|
|
|
al->list = xmalloc(sizeof(*al->list) * al->alloced);;
|
2001-10-30 04:12:35 +08:00
|
|
|
|
2009-03-20 15:22:41 +08:00
|
|
|
al->providesHash = NULL;
|
2012-10-05 16:35:11 +08:00
|
|
|
al->obsoletesHash = NULL;
|
2009-03-20 15:22:41 +08:00
|
|
|
al->fileHash = NULL;
|
2011-09-01 18:19:18 +08:00
|
|
|
al->tsflags = tsflags;
|
2009-03-20 15:22:41 +08:00
|
|
|
al->tscolor = tscolor;
|
2009-06-11 22:16:03 +08:00
|
|
|
al->prefcolor = prefcolor;
|
2001-10-30 04:12:35 +08:00
|
|
|
|
|
|
|
return al;
|
|
|
|
}
|
|
|
|
|
2002-05-28 02:12:12 +08:00
|
|
|
rpmal rpmalFree(rpmal al)
|
2001-10-30 04:12:35 +08:00
|
|
|
{
|
2001-11-05 22:09:22 +08:00
|
|
|
availablePackage alp;
|
2001-10-30 04:12:35 +08:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if (al == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2001-11-05 22:09:22 +08:00
|
|
|
if ((alp = al->list) != NULL)
|
|
|
|
for (i = 0; i < al->size; i++, alp++) {
|
2012-10-05 16:35:11 +08:00
|
|
|
alp->obsoletes = rpmdsFree(alp->obsoletes);
|
2002-05-20 02:42:25 +08:00
|
|
|
alp->provides = rpmdsFree(alp->provides);
|
2002-08-20 06:27:44 +08:00
|
|
|
alp->fi = rpmfiFree(alp->fi);
|
2001-10-30 04:12:35 +08:00
|
|
|
}
|
2012-09-12 19:33:17 +08:00
|
|
|
al->pool = rpmstrPoolFree(al->pool);
|
2001-10-30 04:12:35 +08:00
|
|
|
al->list = _free(al->list);
|
|
|
|
al->alloced = 0;
|
2009-03-20 15:22:41 +08:00
|
|
|
|
2002-05-28 02:12:12 +08:00
|
|
|
rpmalFreeIndex(al);
|
2001-11-23 23:49:11 +08:00
|
|
|
al = _free(al);
|
2001-10-30 04:12:35 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-09-12 21:51:12 +08:00
|
|
|
static unsigned int sidHash(rpmsid sid)
|
|
|
|
{
|
|
|
|
return sid;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sidCmp(rpmsid a, rpmsid b)
|
|
|
|
{
|
|
|
|
return (a != b);
|
|
|
|
}
|
|
|
|
|
2011-09-01 17:55:30 +08:00
|
|
|
static unsigned int fileHash(struct fileNameEntry_s file)
|
|
|
|
{
|
2012-09-13 00:20:52 +08:00
|
|
|
return file.dirName ^ file.baseName;
|
2004-10-20 06:52:33 +08:00
|
|
|
}
|
|
|
|
|
2011-09-01 17:55:30 +08:00
|
|
|
static int fileCompare(struct fileNameEntry_s one, struct fileNameEntry_s two)
|
|
|
|
{
|
2012-09-13 00:20:52 +08:00
|
|
|
int rc = (one.dirName != two.dirName);;
|
2009-03-20 15:22:41 +08:00
|
|
|
if (!rc)
|
2012-09-13 00:20:52 +08:00
|
|
|
rc = (one.baseName != two.baseName);
|
2009-03-20 15:22:41 +08:00
|
|
|
return rc;
|
2001-11-07 06:46:26 +08:00
|
|
|
}
|
|
|
|
|
2009-03-17 00:02:16 +08:00
|
|
|
void rpmalDel(rpmal al, rpmte p)
|
2001-10-30 04:12:35 +08:00
|
|
|
{
|
2001-11-05 06:00:11 +08:00
|
|
|
availablePackage alp;
|
2009-03-17 00:02:16 +08:00
|
|
|
rpmalNum pkgNum;
|
2001-10-30 04:12:35 +08:00
|
|
|
|
2002-04-12 00:55:19 +08:00
|
|
|
if (al == NULL || al->list == NULL)
|
2001-11-13 04:51:05 +08:00
|
|
|
return; /* XXX can't happen */
|
|
|
|
|
2009-03-17 00:02:16 +08:00
|
|
|
// XXX use a search for self provide
|
|
|
|
for (pkgNum=0; pkgNum<al->size; pkgNum++) {
|
|
|
|
if (al->list[pkgNum].p == p) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pkgNum == al->size ) return; // Not found!
|
|
|
|
|
2001-11-05 06:00:11 +08:00
|
|
|
alp = al->list + pkgNum;
|
2009-03-20 15:22:41 +08:00
|
|
|
// do not actually delete, just set p to NULL
|
|
|
|
// and later filter that out of the results
|
|
|
|
alp->p = NULL;
|
|
|
|
}
|
2001-10-30 04:12:35 +08:00
|
|
|
|
2011-09-01 17:55:30 +08:00
|
|
|
static void rpmalAddFiles(rpmal al, rpmalNum pkgNum, rpmfi fi)
|
|
|
|
{
|
2009-03-20 15:22:41 +08:00
|
|
|
struct fileNameEntry_s fileName;
|
2010-09-22 21:37:12 +08:00
|
|
|
struct availableIndexEntry_s fileEntry;
|
2012-10-05 16:25:49 +08:00
|
|
|
int fc = rpmfiFC(fi);
|
2009-03-20 15:22:41 +08:00
|
|
|
rpm_color_t ficolor;
|
2011-09-01 18:40:50 +08:00
|
|
|
int skipdoc = (al->tsflags & RPMTRANS_FLAG_NODOCS);
|
|
|
|
int skipconf = (al->tsflags & RPMTRANS_FLAG_NOCONFIGS);
|
2001-10-30 04:12:35 +08:00
|
|
|
|
2009-03-20 15:22:41 +08:00
|
|
|
fileEntry.pkgNum = pkgNum;
|
|
|
|
|
2012-10-05 16:25:49 +08:00
|
|
|
for (int i = 0; i < fc; i++) {
|
2009-03-20 15:22:41 +08:00
|
|
|
/* Ignore colored provides not in our rainbow. */
|
2012-10-05 16:25:49 +08:00
|
|
|
ficolor = rpmfiFColorIndex(fi, i);
|
2009-03-20 15:22:41 +08:00
|
|
|
if (al->tscolor && ficolor && !(al->tscolor & ficolor))
|
|
|
|
continue;
|
|
|
|
|
2011-09-01 18:40:50 +08:00
|
|
|
/* Ignore files that wont be installed */
|
2012-10-05 16:25:49 +08:00
|
|
|
if (skipdoc && (rpmfiFFlagsIndex(fi, i) & RPMFILE_DOC))
|
2011-09-01 18:40:50 +08:00
|
|
|
continue;
|
2012-10-05 16:25:49 +08:00
|
|
|
if (skipconf && (rpmfiFFlagsIndex(fi, i) & RPMFILE_CONFIG))
|
2011-09-01 18:40:50 +08:00
|
|
|
continue;
|
|
|
|
|
2012-10-05 16:25:49 +08:00
|
|
|
fileName.dirName = rpmfiDNIdIndex(fi, rpmfiDIIndex(fi, i));
|
|
|
|
fileName.baseName = rpmfiBNIdIndex(fi, i);
|
2012-09-05 21:36:16 +08:00
|
|
|
|
2009-03-20 15:22:41 +08:00
|
|
|
fileEntry.entryIx = i;
|
|
|
|
|
2012-09-13 00:20:52 +08:00
|
|
|
rpmalFileHashAddEntry(al->fileHash, fileName, fileEntry);
|
2001-10-30 04:12:35 +08:00
|
|
|
}
|
2009-03-20 15:22:41 +08:00
|
|
|
}
|
|
|
|
|
2011-09-01 17:55:30 +08:00
|
|
|
static void rpmalAddProvides(rpmal al, rpmalNum pkgNum, rpmds provides)
|
|
|
|
{
|
2009-03-20 15:22:41 +08:00
|
|
|
struct availableIndexEntry_s indexEntry;
|
|
|
|
rpm_color_t dscolor;
|
2011-09-01 18:50:55 +08:00
|
|
|
int skipconf = (al->tsflags & RPMTRANS_FLAG_NOCONFIGS);
|
2012-10-05 15:13:09 +08:00
|
|
|
int dc = rpmdsCount(provides);
|
2001-11-07 06:46:26 +08:00
|
|
|
|
2009-03-20 15:22:41 +08:00
|
|
|
indexEntry.pkgNum = pkgNum;
|
2001-11-07 06:46:26 +08:00
|
|
|
|
2012-10-05 15:13:09 +08:00
|
|
|
for (int i = 0; i < dc; i++) {
|
2009-03-20 15:22:41 +08:00
|
|
|
/* Ignore colored provides not in our rainbow. */
|
2012-10-05 15:13:09 +08:00
|
|
|
dscolor = rpmdsColorIndex(provides, i);
|
2009-03-20 15:22:41 +08:00
|
|
|
if (al->tscolor && dscolor && !(al->tscolor & dscolor))
|
|
|
|
continue;
|
|
|
|
|
2011-09-01 18:50:55 +08:00
|
|
|
/* Ignore config() provides if the files wont be installed */
|
2012-10-05 15:13:09 +08:00
|
|
|
if (skipconf & (rpmdsFlagsIndex(provides, i) & RPMSENSE_CONFIG))
|
2011-09-01 18:50:55 +08:00
|
|
|
continue;
|
|
|
|
|
2012-10-05 15:13:09 +08:00
|
|
|
indexEntry.entryIx = i;;
|
2012-10-05 16:34:22 +08:00
|
|
|
rpmalDepHashAddEntry(al->providesHash,
|
2012-10-05 15:13:09 +08:00
|
|
|
rpmdsNIdIndex(provides, i), indexEntry);
|
2009-03-20 15:22:41 +08:00
|
|
|
}
|
2001-10-30 04:12:35 +08:00
|
|
|
}
|
|
|
|
|
2012-10-05 16:35:11 +08:00
|
|
|
static void rpmalAddObsoletes(rpmal al, rpmalNum pkgNum, rpmds obsoletes)
|
|
|
|
{
|
|
|
|
struct availableIndexEntry_s indexEntry;
|
|
|
|
rpm_color_t dscolor;
|
|
|
|
int dc = rpmdsCount(obsoletes);
|
|
|
|
|
|
|
|
indexEntry.pkgNum = pkgNum;
|
|
|
|
|
|
|
|
for (int i = 0; i < dc; i++) {
|
|
|
|
/* Obsoletes shouldn't be colored but just in case... */
|
|
|
|
dscolor = rpmdsColorIndex(obsoletes, i);
|
|
|
|
if (al->tscolor && dscolor && !(al->tscolor & dscolor))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
indexEntry.entryIx = i;;
|
|
|
|
rpmalDepHashAddEntry(al->obsoletesHash,
|
|
|
|
rpmdsNIdIndex(obsoletes, i), indexEntry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-20 15:22:41 +08:00
|
|
|
void rpmalAdd(rpmal al, rpmte p)
|
2001-10-30 04:12:35 +08:00
|
|
|
{
|
2007-09-21 20:17:08 +08:00
|
|
|
rpmalNum pkgNum;
|
2001-11-13 04:51:05 +08:00
|
|
|
availablePackage alp;
|
2001-10-30 04:12:35 +08:00
|
|
|
|
2009-03-17 00:02:16 +08:00
|
|
|
if (al->size == al->alloced) {
|
|
|
|
al->alloced += al->delta;
|
|
|
|
al->list = xrealloc(al->list, sizeof(*al->list) * al->alloced);
|
|
|
|
}
|
|
|
|
pkgNum = al->size++;
|
2001-11-13 04:51:05 +08:00
|
|
|
|
2001-11-05 06:00:11 +08:00
|
|
|
alp = al->list + pkgNum;
|
2001-10-30 04:12:35 +08:00
|
|
|
|
2009-03-17 00:02:16 +08:00
|
|
|
alp->p = p;
|
2001-10-30 04:12:35 +08:00
|
|
|
|
2010-03-22 19:04:26 +08:00
|
|
|
alp->provides = rpmdsLink(rpmteDS(p, RPMTAG_PROVIDENAME));
|
2012-10-05 16:35:11 +08:00
|
|
|
alp->obsoletes = rpmdsLink(rpmteDS(p, RPMTAG_OBSOLETENAME));
|
2010-03-22 18:49:45 +08:00
|
|
|
alp->fi = rpmfiLink(rpmteFI(p));
|
2001-11-05 22:09:22 +08:00
|
|
|
|
2012-09-12 21:50:41 +08:00
|
|
|
/*
|
|
|
|
* Transition-time safe-guard to catch private-pool uses.
|
|
|
|
* File sets with no files have NULL pool, that's fine. But WTF is up
|
|
|
|
* with the provides: every single package should have at least its
|
|
|
|
* own name as a provide, and thus never NULL, and normal use matches
|
|
|
|
* this expectation. However the test-suite is tripping up on NULL
|
|
|
|
* NULL pool from NULL alp->provides in numerous cases?
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
rpmstrPool fipool = rpmfiPool(alp->fi);
|
|
|
|
rpmstrPool dspool = rpmdsPool(alp->provides);
|
|
|
|
|
|
|
|
assert(fipool == NULL || fipool == al->pool);
|
|
|
|
assert(dspool == NULL || dspool == al->pool);
|
|
|
|
}
|
|
|
|
|
2012-10-04 20:48:43 +08:00
|
|
|
/* Try to be lazy as delayed hash creation is cheaper */
|
|
|
|
if (al->providesHash != NULL)
|
2009-03-20 15:22:41 +08:00
|
|
|
rpmalAddProvides(al, pkgNum, alp->provides);
|
2012-10-05 16:35:11 +08:00
|
|
|
if (al->obsoletesHash != NULL)
|
|
|
|
rpmalAddObsoletes(al, pkgNum, alp->obsoletes);
|
2012-10-04 20:48:43 +08:00
|
|
|
if (al->fileHash != NULL)
|
2009-03-20 15:22:41 +08:00
|
|
|
rpmalAddFiles(al, pkgNum, alp->fi);
|
2001-10-30 04:12:35 +08:00
|
|
|
|
2009-03-20 15:22:41 +08:00
|
|
|
assert(((rpmalNum)(alp - al->list)) == pkgNum);
|
2001-11-07 06:46:26 +08:00
|
|
|
}
|
|
|
|
|
2012-10-04 20:48:43 +08:00
|
|
|
static void rpmalMakeFileIndex(rpmal al)
|
2001-10-30 04:12:35 +08:00
|
|
|
{
|
2001-11-08 08:12:49 +08:00
|
|
|
availablePackage alp;
|
2012-10-04 20:48:43 +08:00
|
|
|
int i, fileCnt = 0;
|
2001-10-30 04:12:35 +08:00
|
|
|
|
2001-11-08 08:12:49 +08:00
|
|
|
for (i = 0; i < al->size; i++) {
|
|
|
|
alp = al->list + i;
|
2009-03-20 15:22:41 +08:00
|
|
|
if (alp->fi != NULL)
|
|
|
|
fileCnt += rpmfiFC(alp->fi);
|
2001-11-08 08:12:49 +08:00
|
|
|
}
|
2012-10-04 20:48:43 +08:00
|
|
|
al->fileHash = rpmalFileHashCreate(fileCnt/4+128,
|
|
|
|
fileHash, fileCompare, NULL, NULL);
|
|
|
|
for (i = 0; i < al->size; i++) {
|
|
|
|
alp = al->list + i;
|
|
|
|
rpmalAddFiles(al, i, alp->fi);
|
|
|
|
}
|
|
|
|
}
|
2001-10-30 04:12:35 +08:00
|
|
|
|
2012-10-04 20:48:43 +08:00
|
|
|
static void rpmalMakeProvidesIndex(rpmal al)
|
|
|
|
{
|
|
|
|
availablePackage alp;
|
|
|
|
int i, providesCnt = 0;
|
2009-03-20 15:22:41 +08:00
|
|
|
|
2012-10-04 20:48:43 +08:00
|
|
|
for (i = 0; i < al->size; i++) {
|
|
|
|
alp = al->list + i;
|
|
|
|
providesCnt += rpmdsCount(alp->provides);
|
|
|
|
}
|
|
|
|
|
2012-10-05 16:34:22 +08:00
|
|
|
al->providesHash = rpmalDepHashCreate(providesCnt/4+128,
|
2012-10-04 20:48:43 +08:00
|
|
|
sidHash, sidCmp, NULL, NULL);
|
2002-09-03 20:23:51 +08:00
|
|
|
for (i = 0; i < al->size; i++) {
|
|
|
|
alp = al->list + i;
|
2009-03-20 15:22:41 +08:00
|
|
|
rpmalAddProvides(al, i, alp->provides);
|
2001-10-30 04:12:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-05 16:35:11 +08:00
|
|
|
static void rpmalMakeObsoletesIndex(rpmal al)
|
|
|
|
{
|
|
|
|
availablePackage alp;
|
|
|
|
int i, obsoletesCnt = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < al->size; i++) {
|
|
|
|
alp = al->list + i;
|
|
|
|
obsoletesCnt += rpmdsCount(alp->obsoletes);
|
|
|
|
}
|
|
|
|
|
|
|
|
al->obsoletesHash = rpmalDepHashCreate(obsoletesCnt/4+128,
|
|
|
|
sidHash, sidCmp, NULL, NULL);
|
|
|
|
for (i = 0; i < al->size; i++) {
|
|
|
|
alp = al->list + i;
|
|
|
|
rpmalAddObsoletes(al, i, alp->obsoletes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rpmte * rpmalAllObsoletes(rpmal al, rpmds ds)
|
|
|
|
{
|
|
|
|
rpmte * ret = NULL;
|
|
|
|
rpmsid nameId;
|
|
|
|
availableIndexEntry result;
|
|
|
|
int resultCnt;
|
|
|
|
|
|
|
|
if (al == NULL || ds == NULL || (nameId = rpmdsNId(ds)) == 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (al->obsoletesHash == NULL)
|
|
|
|
rpmalMakeObsoletesIndex(al);
|
|
|
|
|
|
|
|
rpmalDepHashGetEntry(al->obsoletesHash, nameId, &result, &resultCnt, NULL);
|
|
|
|
|
|
|
|
if (resultCnt > 0) {
|
|
|
|
availablePackage alp;
|
|
|
|
int rc, found = 0;
|
|
|
|
|
|
|
|
ret = xmalloc((resultCnt+1) * sizeof(*ret));
|
|
|
|
|
|
|
|
for (int i = 0; i < resultCnt; i++) {
|
|
|
|
alp = al->list + result[i].pkgNum;
|
|
|
|
if (alp->p == NULL) // deleted
|
|
|
|
continue;
|
|
|
|
|
|
|
|
rc = rpmdsCompareIndex(alp->obsoletes, result[i].entryIx,
|
|
|
|
ds, rpmdsIx(ds));
|
|
|
|
|
|
|
|
if (rc) {
|
|
|
|
rpmdsNotify(ds, "(added obsolete)", 0);
|
|
|
|
ret[found] = alp->p;
|
|
|
|
found++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found)
|
|
|
|
ret[found] = NULL;
|
|
|
|
else
|
|
|
|
ret = _free(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-09-18 11:30:59 +08:00
|
|
|
static rpmte * rpmalAllFileSatisfiesDepend(const rpmal al, const char *fileName)
|
2001-10-30 04:12:35 +08:00
|
|
|
{
|
2009-09-14 18:23:34 +08:00
|
|
|
const char *slash;
|
2009-03-17 00:02:16 +08:00
|
|
|
rpmte * ret = NULL;
|
2008-04-26 19:51:20 +08:00
|
|
|
|
2009-09-14 18:23:34 +08:00
|
|
|
if (al == NULL || fileName == NULL || *fileName != '/')
|
2001-11-05 06:00:11 +08:00
|
|
|
return NULL;
|
2001-10-30 04:12:35 +08:00
|
|
|
|
2009-09-14 18:23:34 +08:00
|
|
|
/* Split path into dirname and basename components for lookup */
|
|
|
|
if ((slash = strrchr(fileName, '/')) != NULL) {
|
2010-09-22 21:37:12 +08:00
|
|
|
availableIndexEntry result;
|
2009-09-14 18:23:34 +08:00
|
|
|
int resultCnt = 0;
|
|
|
|
size_t bnStart = (slash - fileName) + 1;
|
2012-09-13 00:20:52 +08:00
|
|
|
struct fileNameEntry_s fne;
|
|
|
|
|
|
|
|
fne.baseName = rpmstrPoolId(al->pool, fileName + bnStart, 0);
|
2012-09-18 11:26:34 +08:00
|
|
|
fne.dirName = rpmstrPoolIdn(al->pool, fileName, bnStart, 0);
|
2012-09-13 00:20:52 +08:00
|
|
|
|
2012-10-04 20:48:43 +08:00
|
|
|
if (al->fileHash == NULL)
|
|
|
|
rpmalMakeFileIndex(al);
|
|
|
|
|
2009-09-14 18:23:34 +08:00
|
|
|
rpmalFileHashGetEntry(al->fileHash, fne, &result, &resultCnt, NULL);
|
|
|
|
|
|
|
|
if (resultCnt > 0) {
|
|
|
|
int i, found;
|
|
|
|
ret = xmalloc((resultCnt+1) * sizeof(*ret));
|
|
|
|
|
|
|
|
for (found = i = 0; i < resultCnt; i++) {
|
|
|
|
availablePackage alp = al->list + result[i].pkgNum;
|
|
|
|
if (alp->p == NULL) // deleted
|
|
|
|
continue;
|
|
|
|
|
|
|
|
ret[found] = alp->p;
|
|
|
|
found++;
|
|
|
|
}
|
|
|
|
ret[found] = NULL;
|
|
|
|
}
|
2001-10-30 04:12:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-10-02 15:50:10 +08:00
|
|
|
rpmte * rpmalAllSatisfiesDepend(const rpmal al, const rpmds ds)
|
2001-10-30 04:12:35 +08:00
|
|
|
{
|
2009-03-17 00:02:16 +08:00
|
|
|
rpmte * ret = NULL;
|
2012-10-05 15:16:44 +08:00
|
|
|
int i, ix, found;
|
2012-09-12 21:51:12 +08:00
|
|
|
rpmsid nameId;
|
|
|
|
const char *name;
|
2009-03-20 15:22:41 +08:00
|
|
|
availableIndexEntry result;
|
|
|
|
int resultCnt;
|
2012-04-05 16:32:38 +08:00
|
|
|
int obsolete;
|
2009-03-20 15:22:41 +08:00
|
|
|
|
2001-11-05 06:00:11 +08:00
|
|
|
availablePackage alp;
|
2001-11-14 03:04:33 +08:00
|
|
|
int rc;
|
2001-10-30 04:12:35 +08:00
|
|
|
|
2012-09-12 21:51:12 +08:00
|
|
|
if (al == NULL || ds == NULL || (nameId = rpmdsNId(ds)) == 0)
|
2001-11-05 06:00:11 +08:00
|
|
|
return ret;
|
|
|
|
|
2012-04-05 16:32:38 +08:00
|
|
|
obsolete = (rpmdsTagN(ds) == RPMTAG_OBSOLETENAME);
|
2012-09-12 21:51:12 +08:00
|
|
|
name = rpmstrPoolStr(al->pool, nameId);
|
2012-04-05 16:32:38 +08:00
|
|
|
if (!obsolete && *name == '/') {
|
2002-12-21 09:05:44 +08:00
|
|
|
/* First, look for files "contained" in package ... */
|
2012-09-18 11:30:59 +08:00
|
|
|
ret = rpmalAllFileSatisfiesDepend(al, name);
|
2012-09-18 11:27:57 +08:00
|
|
|
if (ret != NULL && *ret != NULL) {
|
|
|
|
rpmdsNotify(ds, "(added files)", 0);
|
2001-10-30 04:12:35 +08:00
|
|
|
return ret;
|
2012-09-18 11:27:57 +08:00
|
|
|
}
|
2002-12-21 09:05:44 +08:00
|
|
|
/* ... then, look for files "provided" by package. */
|
2007-07-02 20:02:15 +08:00
|
|
|
ret = _free(ret);
|
2001-10-30 04:12:35 +08:00
|
|
|
}
|
|
|
|
|
2012-10-04 20:48:43 +08:00
|
|
|
if (al->providesHash == NULL)
|
|
|
|
rpmalMakeProvidesIndex(al);
|
|
|
|
|
2012-10-05 16:34:22 +08:00
|
|
|
rpmalDepHashGetEntry(al->providesHash, nameId, &result,
|
2009-03-20 15:22:41 +08:00
|
|
|
&resultCnt, NULL);
|
2001-10-30 04:12:35 +08:00
|
|
|
|
2009-03-20 15:22:41 +08:00
|
|
|
if (resultCnt==0) return NULL;
|
2001-10-30 04:12:35 +08:00
|
|
|
|
2009-03-20 15:22:41 +08:00
|
|
|
ret = xmalloc((resultCnt+1) * sizeof(*ret));
|
2001-11-07 06:46:26 +08:00
|
|
|
|
2009-03-20 15:22:41 +08:00
|
|
|
for (found=i=0; i<resultCnt; i++) {
|
|
|
|
alp = al->list + result[i].pkgNum;
|
|
|
|
if (alp->p == NULL) // deleted
|
|
|
|
continue;
|
2012-10-05 15:16:44 +08:00
|
|
|
ix = result[i].entryIx;
|
2012-04-05 16:32:38 +08:00
|
|
|
|
|
|
|
/* Obsoletes are on package name, filter out other provide matches */
|
2012-10-05 15:16:44 +08:00
|
|
|
if (obsolete && !rstreq(rpmdsNIndex(alp->provides, ix), rpmteN(alp->p)))
|
2012-04-05 16:32:38 +08:00
|
|
|
continue;
|
|
|
|
|
2012-10-05 15:16:44 +08:00
|
|
|
rc = rpmdsCompareIndex(alp->provides, ix, ds, rpmdsIx(ds));
|
2001-10-30 04:12:35 +08:00
|
|
|
|
|
|
|
if (rc) {
|
2010-03-29 11:48:23 +08:00
|
|
|
rpmdsNotify(ds, "(added provide)", 0);
|
2009-03-20 15:22:41 +08:00
|
|
|
ret[found] = alp->p;
|
2002-12-21 09:05:44 +08:00
|
|
|
found++;
|
2001-10-30 04:12:35 +08:00
|
|
|
}
|
|
|
|
}
|
2012-10-02 17:12:20 +08:00
|
|
|
|
|
|
|
if (found)
|
|
|
|
ret[found] = NULL;
|
|
|
|
else
|
|
|
|
ret = _free(ret);
|
2001-10-30 04:12:35 +08:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2001-10-31 12:00:58 +08:00
|
|
|
|
2009-03-17 00:02:16 +08:00
|
|
|
rpmte
|
|
|
|
rpmalSatisfiesDepend(const rpmal al, const rpmds ds)
|
2001-10-31 12:00:58 +08:00
|
|
|
{
|
2009-06-11 22:22:59 +08:00
|
|
|
rpmte *providers = rpmalAllSatisfiesDepend(al, ds);
|
|
|
|
rpmte best = NULL;
|
|
|
|
|
|
|
|
if (providers) {
|
|
|
|
if (al->tscolor) {
|
|
|
|
/*
|
|
|
|
* For colored dependencies, try to find a matching provider.
|
|
|
|
* Otherwise prefer provider of ts preferred color.
|
|
|
|
*/
|
|
|
|
rpm_color_t dscolor = rpmdsColor(ds);
|
|
|
|
for (rpmte *p = providers; *p; p++) {
|
|
|
|
rpm_color_t tecolor = rpmteColor(*p);
|
|
|
|
if (dscolor) {
|
|
|
|
if (dscolor == tecolor) best = *p;
|
|
|
|
} else if (al->prefcolor) {
|
|
|
|
if (al->prefcolor == tecolor) best = *p;
|
|
|
|
}
|
|
|
|
if (best) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* if not decided by now, just pick first match */
|
|
|
|
if (!best) best = providers[0];
|
|
|
|
free(providers);
|
2001-10-31 12:00:58 +08:00
|
|
|
}
|
2009-06-11 22:22:59 +08:00
|
|
|
return best;
|
2001-10-31 12:00:58 +08:00
|
|
|
}
|
2010-06-22 05:04:38 +08:00
|
|
|
|
|
|
|
rpmte *
|
|
|
|
rpmalAllInCollection(const rpmal al, const char *collname)
|
|
|
|
{
|
|
|
|
rpmte *ret = NULL;
|
|
|
|
int found = 0;
|
|
|
|
rpmalNum pkgNum;
|
|
|
|
|
|
|
|
if (!al || !al->list || !collname)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
for (pkgNum = 0; pkgNum < al->size; pkgNum++) {
|
|
|
|
rpmte p = al->list[pkgNum].p;
|
|
|
|
if (rpmteHasCollection(p, collname)) {
|
|
|
|
ret = xrealloc(ret, sizeof(*ret) * (found + 1 + 1));
|
|
|
|
ret[found] = p;
|
|
|
|
found++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ret) {
|
|
|
|
ret[found] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|