Move addTE/delTE to rpmte.c.

CVS patchset: 5187
CVS date: 2001/11/16 23:22:24
This commit is contained in:
jbj 2001-11-16 23:22:24 +00:00
parent 7d44f13395
commit c2b98f0e2c
5 changed files with 149 additions and 150 deletions

View File

@ -2,8 +2,6 @@
* \file lib/depends.c
*/
#define _DS_SCAREMEM 0 /* XXX remove? */
#include "system.h"
#include <rpmlib.h>
@ -129,118 +127,6 @@ char * hGetNEVR(Header h, const char ** np)
return NVR;
}
/*@-type -mustmod@*/ /* FIX: transactionElement not opaque */
/**
*/
static void delTE(transactionElement p)
/*@modifies p @*/
{
rpmRelocation * r;
if (p->relocs) {
for (r = p->relocs; (r->oldPath || r->newPath); r++) {
r->oldPath = _free(r->oldPath);
r->newPath = _free(r->newPath);
}
p->relocs = _free(p->relocs);
}
p->this = dsFree(p->this);
p->provides = dsFree(p->provides);
p->requires = dsFree(p->requires);
p->conflicts = dsFree(p->conflicts);
p->obsoletes = dsFree(p->obsoletes);
p->fi = fiFree(p->fi, 1);
/*@-noeffectuncon@*/
if (p->fd != NULL)
p->fd = fdFree(p->fd, "delTE");
/*@=noeffectuncon@*/
p->os = _free(p->os);
p->arch = _free(p->arch);
p->epoch = _free(p->epoch);
p->name = _free(p->name);
p->NEVR = _free(p->NEVR);
p->h = headerFree(p->h, "delTE");
/*@-abstract@*/
memset(p, 0, sizeof(*p)); /* XXX trash and burn */
/*@=abstract@*/
/*@-nullstate@*/ /* FIX: p->{NEVR,name} annotations */
return;
/*@=nullstate@*/
}
/**
*/
static void addTE(rpmTransactionSet ts, transactionElement p, Header h,
/*@dependent@*/ /*@null@*/ fnpyKey key,
/*@null@*/ rpmRelocation * relocs)
/*@modifies ts, p, h @*/
{
int scareMem = _DS_SCAREMEM;
HGE_t hge = (HGE_t)headerGetEntryMinMemory;
int_32 * ep;
const char * arch, * os;
int xx;
p->NEVR = hGetNEVR(h, NULL);
p->name = xstrdup(p->NEVR);
if ((p->release = strrchr(p->name, '-')) != NULL)
*p->release++ = '\0';
if ((p->version = strrchr(p->name, '-')) != NULL)
*p->version++ = '\0';
arch = NULL;
xx = hge(h, RPMTAG_ARCH, NULL, (void **)&arch, NULL);
p->arch = (arch != NULL ? xstrdup(arch) : NULL);
os = NULL;
xx = hge(h, RPMTAG_OS, NULL, (void **)&os, NULL);
p->os = (os != NULL ? xstrdup(os) : NULL);
ep = NULL;
xx = hge(h, RPMTAG_EPOCH, NULL, (void **)&ep, NULL);
/*@-branchstate@*/
if (ep) {
p->epoch = xmalloc(20);
sprintf(p->epoch, "%d", *ep);
} else
p->epoch = NULL;
/*@=branchstate@*/
p->this = dsThis(h, RPMTAG_PROVIDENAME, RPMSENSE_EQUAL);
p->provides = dsNew(h, RPMTAG_PROVIDENAME, scareMem);
p->fi = fiNew(ts, NULL, h, RPMTAG_BASENAMES, scareMem);
p->requires = dsNew(h, RPMTAG_REQUIRENAME, scareMem);
p->conflicts = dsNew(h, RPMTAG_CONFLICTNAME, scareMem);
p->obsoletes = dsNew(h, RPMTAG_OBSOLETENAME, scareMem);
p->key = key;
p->fd = NULL;
if (relocs != NULL) {
rpmRelocation * r;
int i;
for (i = 0, r = relocs; r->oldPath || r->newPath; i++, r++)
{};
p->relocs = xmalloc((i + 1) * sizeof(*p->relocs));
for (i = 0, r = relocs; r->oldPath || r->newPath; i++, r++) {
p->relocs[i].oldPath = r->oldPath ? xstrdup(r->oldPath) : NULL;
p->relocs[i].newPath = r->newPath ? xstrdup(r->newPath) : NULL;
}
p->relocs[i].oldPath = NULL;
p->relocs[i].newPath = NULL;
} else {
p->relocs = NULL;
}
}
/*@=type =mustmod@*/
rpmTransactionSet rpmtransCreateSet(rpmdb db, const char * rootDir)
{
rpmTransactionSet ts;
@ -362,12 +248,9 @@ static int removePackage(rpmTransactionSet ts, Header h, int dboffset,
/*@=type =voidabstract @*/
}
p = ts->order[ts->orderCount] = teNew();
p = ts->order[ts->orderCount] = teNew(ts, h, NULL, NULL);
ts->orderCount++;
/* XXX FIXME: what should a TR_REMOVED key be ??? */
addTE(ts, p, h, NULL, NULL);
/*@-type@*/ /* FIX: transactionElement not opaque */
p->type = TR_REMOVED;
p->u.removed.dboffset = dboffset;
@ -431,7 +314,6 @@ int rpmtransAddPackage(rpmTransactionSet ts, Header h,
if (p != NULL && duplicate && oc < ts->orderCount) {
/* XXX FIXME removed transaction element side effects need to be weeded */
delTE(p);
/*@-type -unqualifiedtrans@*/
ts->order[oc] = teFree(ts->order[oc]);
/*@=type =unqualifiedtrans@*/
@ -444,15 +326,16 @@ int rpmtransAddPackage(rpmTransactionSet ts, Header h,
/*@=type =voidabstract @*/
}
p = ts->order[oc] = teNew();
p = ts->order[oc] = teNew(ts, h, key, relocs);
if (!duplicate)
ts->orderCount++;
addTE(ts, p, h, key, relocs);
/*@-type@*/ /* FIX: transactionElement not opaque */
p->type = TR_ADDED;
pkgKey = alAddPackage(ts->addedPackages, pkgKey, p->key,
p->provides, p->fi);
if (pkgKey == RPMAL_NOMATCH) {
ts->order[oc] = teFree(ts->order[oc]);
ec = 1;
goto exit;
}
@ -485,8 +368,6 @@ int rpmtransAddPackage(rpmTransactionSet ts, Header h,
if (!duplicate) {
ts->numAddedPackages++;
/* XXX FIXME: there's a chance of a memory leak with the late increment */
ts->orderCount++;
}
if (!upgrade)
@ -579,7 +460,7 @@ exit:
void rpmtransAvailablePackage(rpmTransactionSet ts, Header h, fnpyKey key)
{
int scareMem = _DS_SCAREMEM;
int scareMem = 0;
rpmDepSet provides = dsNew(h, RPMTAG_PROVIDENAME, scareMem);
TFI_t fi = fiNew(ts, NULL, h, RPMTAG_BASENAMES, scareMem);
@ -621,7 +502,6 @@ rpmTransactionSet rpmtransFree(rpmTransactionSet ts)
pi = teInitIterator(ts);
for (pi = teInitIterator(ts), oc = 0; (p = teNextIterator(pi)) != NULL; oc++) {
delTE(p);
/*@-type -unqualifiedtrans @*/
ts->order[oc] = teFree(ts->order[oc]);
/*@=type =unqualifiedtrans @*/

View File

@ -1390,8 +1390,8 @@ rpmdbMatchIterator rpmtsInitIterator(const rpmTransactionSet ts, int rpmtag,
* @warning The fd argument has been eliminated, and is assumed always NULL.
*
* @param ts transaction set
* @param h package header
* @param key package private data
* @param h header
* @param key package retrieval key (e.g. file name)
* @param upgrade is package being upgraded?
* @param relocs package file relocations
* @return 0 on success, 1 on I/O error, 2 needs capabilities

View File

@ -17,18 +17,131 @@ int _te_debug = 0;
/*@access transactionElement @*/
/*@access rpmTransactionSet @*/
/**
*/
static void delTE(transactionElement p)
/*@modifies p @*/
{
rpmRelocation * r;
if (p->relocs) {
for (r = p->relocs; (r->oldPath || r->newPath); r++) {
r->oldPath = _free(r->oldPath);
r->newPath = _free(r->newPath);
}
p->relocs = _free(p->relocs);
}
p->this = dsFree(p->this);
p->provides = dsFree(p->provides);
p->requires = dsFree(p->requires);
p->conflicts = dsFree(p->conflicts);
p->obsoletes = dsFree(p->obsoletes);
p->fi = fiFree(p->fi, 1);
/*@-noeffectuncon@*/
if (p->fd != NULL)
p->fd = fdFree(p->fd, "delTE");
/*@=noeffectuncon@*/
p->os = _free(p->os);
p->arch = _free(p->arch);
p->epoch = _free(p->epoch);
p->name = _free(p->name);
p->NEVR = _free(p->NEVR);
p->h = headerFree(p->h, "delTE");
/*@-abstract@*/
memset(p, 0, sizeof(*p)); /* XXX trash and burn */
/*@=abstract@*/
/*@-nullstate@*/ /* FIX: p->{NEVR,name} annotations */
return;
/*@=nullstate@*/
}
/**
*/
static void addTE(rpmTransactionSet ts, transactionElement p, Header h,
/*@dependent@*/ /*@null@*/ fnpyKey key,
/*@null@*/ rpmRelocation * relocs)
/*@modifies ts, p, h @*/
{
int scareMem = 0;
HGE_t hge = (HGE_t)headerGetEntryMinMemory;
int_32 * ep;
const char * arch, * os;
int xx;
p->NEVR = hGetNEVR(h, NULL);
p->name = xstrdup(p->NEVR);
if ((p->release = strrchr(p->name, '-')) != NULL)
*p->release++ = '\0';
if ((p->version = strrchr(p->name, '-')) != NULL)
*p->version++ = '\0';
arch = NULL;
xx = hge(h, RPMTAG_ARCH, NULL, (void **)&arch, NULL);
p->arch = (arch != NULL ? xstrdup(arch) : NULL);
os = NULL;
xx = hge(h, RPMTAG_OS, NULL, (void **)&os, NULL);
p->os = (os != NULL ? xstrdup(os) : NULL);
ep = NULL;
xx = hge(h, RPMTAG_EPOCH, NULL, (void **)&ep, NULL);
/*@-branchstate@*/
if (ep) {
p->epoch = xmalloc(20);
sprintf(p->epoch, "%d", *ep);
} else
p->epoch = NULL;
/*@=branchstate@*/
p->this = dsThis(h, RPMTAG_PROVIDENAME, RPMSENSE_EQUAL);
p->provides = dsNew(h, RPMTAG_PROVIDENAME, scareMem);
p->fi = fiNew(ts, NULL, h, RPMTAG_BASENAMES, scareMem);
p->requires = dsNew(h, RPMTAG_REQUIRENAME, scareMem);
p->conflicts = dsNew(h, RPMTAG_CONFLICTNAME, scareMem);
p->obsoletes = dsNew(h, RPMTAG_OBSOLETENAME, scareMem);
p->key = key;
p->fd = NULL;
if (relocs != NULL) {
rpmRelocation * r;
int i;
for (i = 0, r = relocs; r->oldPath || r->newPath; i++, r++)
{};
p->relocs = xmalloc((i + 1) * sizeof(*p->relocs));
for (i = 0, r = relocs; r->oldPath || r->newPath; i++, r++) {
p->relocs[i].oldPath = r->oldPath ? xstrdup(r->oldPath) : NULL;
p->relocs[i].newPath = r->newPath ? xstrdup(r->newPath) : NULL;
}
p->relocs[i].oldPath = NULL;
p->relocs[i].newPath = NULL;
} else {
p->relocs = NULL;
}
}
transactionElement teFree(transactionElement te)
{
if (te != NULL) {
delTE(te);
memset(te, 0, sizeof(*te)); /* XXX trash and burn */
te = _free(te);
}
return NULL;
}
transactionElement teNew(void)
transactionElement teNew(rpmTransactionSet ts, Header h,
fnpyKey key, rpmRelocation * relocs)
{
transactionElement te = xcalloc(1, sizeof(*te));
addTE(ts, te, h, key, relocs);
return te;
}

View File

@ -132,11 +132,17 @@ transactionElement teFree(/*@only@*/ /*@null@*/ transactionElement te)
/*@modifies te@*/;
/**
* Create a transaction element.
* @param ts transaction set
* @param h header
* @param key package retrieval key (e.g. file name)
* @param relocs package file relocations
* @return new transaction element
*/
/*@only@*/ /*@null@*/
transactionElement teNew(void)
/*@*/;
transactionElement teNew(const rpmTransactionSet ts, Header h,
/*@exposed@*/ /*@null@*/ fnpyKey key,
/*@null@*/ rpmRelocation * relocs)
/*@modifies ts, h @*/;
/**
* Retrieve type of transaction element.

View File

@ -6,7 +6,7 @@
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2001-11-16 17:39-0500\n"
"POT-Creation-Date: 2001-11-16 18:03-0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -1410,83 +1410,83 @@ msgstr ""
msgid " failed - "
msgstr ""
#: lib/depends.c:103
#: lib/depends.c:101
#, c-format
msgid "cannot open Packages database in %s\n"
msgstr ""
#: lib/depends.c:419
#: lib/depends.c:302
#, c-format
msgid "package %s was already added, replacing with %s\n"
msgstr ""
#: lib/depends.c:704
#: lib/depends.c:584
msgid "(cached)"
msgstr ""
#: lib/depends.c:729
#: lib/depends.c:609
msgid "(rpmrc provides)"
msgstr ""
#: lib/depends.c:745
#: lib/depends.c:625
msgid "(rpmlib provides)"
msgstr ""
#: lib/depends.c:766
#: lib/depends.c:646
msgid "(db files)"
msgstr ""
#: lib/depends.c:778
#: lib/depends.c:658
msgid "(db provides)"
msgstr ""
#: lib/depends.c:791
#: lib/depends.c:671
msgid "(db package)"
msgstr ""
#: lib/depends.c:830
#: lib/depends.c:710
#, c-format
msgid "%9s: (%s, %s) added to Depends cache.\n"
msgstr ""
#: lib/depends.c:832 lib/rpmds.c:407 lib/rpmds.c:566
#: lib/depends.c:712 lib/rpmds.c:407 lib/rpmds.c:566
msgid "NO "
msgstr ""
#: lib/depends.c:832 lib/rpmds.c:407 lib/rpmds.c:566
#: lib/depends.c:712 lib/rpmds.c:407 lib/rpmds.c:566
msgid "YES"
msgstr ""
#: lib/depends.c:1173
#: lib/depends.c:1053
#, c-format
msgid "removing %s \"%s\" from tsort relations.\n"
msgstr ""
#. Record all relations.
#: lib/depends.c:1415
#: lib/depends.c:1295
msgid "========== recording tsort relations\n"
msgstr ""
#. T4. Scan for zeroes.
#: lib/depends.c:1491
#: lib/depends.c:1371
msgid ""
"========== tsorting packages (order, #predecessors, #succesors, depth)\n"
msgstr ""
#: lib/depends.c:1568
#: lib/depends.c:1448
msgid "========== successors only (presentation order)\n"
msgstr ""
#: lib/depends.c:1628
#: lib/depends.c:1508
msgid "LOOP:\n"
msgstr ""
#: lib/depends.c:1665
#: lib/depends.c:1545
msgid "========== continuing tsort ...\n"
msgstr ""
#. Return no. of packages that could not be ordered.
#: lib/depends.c:1670
#: lib/depends.c:1550
#, c-format
msgid "rpmdepOrder failed, %d elements remain\n"
msgstr ""