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 * \file lib/depends.c
*/ */
#define _DS_SCAREMEM 0 /* XXX remove? */
#include "system.h" #include "system.h"
#include <rpmlib.h> #include <rpmlib.h>
@ -129,118 +127,6 @@ char * hGetNEVR(Header h, const char ** np)
return NVR; 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 rpmtransCreateSet(rpmdb db, const char * rootDir)
{ {
rpmTransactionSet ts; rpmTransactionSet ts;
@ -362,12 +248,9 @@ static int removePackage(rpmTransactionSet ts, Header h, int dboffset,
/*@=type =voidabstract @*/ /*@=type =voidabstract @*/
} }
p = ts->order[ts->orderCount] = teNew(); p = ts->order[ts->orderCount] = teNew(ts, h, NULL, NULL);
ts->orderCount++; ts->orderCount++;
/* XXX FIXME: what should a TR_REMOVED key be ??? */
addTE(ts, p, h, NULL, NULL);
/*@-type@*/ /* FIX: transactionElement not opaque */ /*@-type@*/ /* FIX: transactionElement not opaque */
p->type = TR_REMOVED; p->type = TR_REMOVED;
p->u.removed.dboffset = dboffset; p->u.removed.dboffset = dboffset;
@ -431,7 +314,6 @@ int rpmtransAddPackage(rpmTransactionSet ts, Header h,
if (p != NULL && duplicate && oc < ts->orderCount) { if (p != NULL && duplicate && oc < ts->orderCount) {
/* XXX FIXME removed transaction element side effects need to be weeded */ /* XXX FIXME removed transaction element side effects need to be weeded */
delTE(p);
/*@-type -unqualifiedtrans@*/ /*@-type -unqualifiedtrans@*/
ts->order[oc] = teFree(ts->order[oc]); ts->order[oc] = teFree(ts->order[oc]);
/*@=type =unqualifiedtrans@*/ /*@=type =unqualifiedtrans@*/
@ -444,15 +326,16 @@ int rpmtransAddPackage(rpmTransactionSet ts, Header h,
/*@=type =voidabstract @*/ /*@=type =voidabstract @*/
} }
p = ts->order[oc] = teNew(); p = ts->order[oc] = teNew(ts, h, key, relocs);
if (!duplicate)
addTE(ts, p, h, key, relocs); ts->orderCount++;
/*@-type@*/ /* FIX: transactionElement not opaque */ /*@-type@*/ /* FIX: transactionElement not opaque */
p->type = TR_ADDED; p->type = TR_ADDED;
pkgKey = alAddPackage(ts->addedPackages, pkgKey, p->key, pkgKey = alAddPackage(ts->addedPackages, pkgKey, p->key,
p->provides, p->fi); p->provides, p->fi);
if (pkgKey == RPMAL_NOMATCH) { if (pkgKey == RPMAL_NOMATCH) {
ts->order[oc] = teFree(ts->order[oc]);
ec = 1; ec = 1;
goto exit; goto exit;
} }
@ -485,8 +368,6 @@ int rpmtransAddPackage(rpmTransactionSet ts, Header h,
if (!duplicate) { if (!duplicate) {
ts->numAddedPackages++; ts->numAddedPackages++;
/* XXX FIXME: there's a chance of a memory leak with the late increment */
ts->orderCount++;
} }
if (!upgrade) if (!upgrade)
@ -579,7 +460,7 @@ exit:
void rpmtransAvailablePackage(rpmTransactionSet ts, Header h, fnpyKey key) void rpmtransAvailablePackage(rpmTransactionSet ts, Header h, fnpyKey key)
{ {
int scareMem = _DS_SCAREMEM; int scareMem = 0;
rpmDepSet provides = dsNew(h, RPMTAG_PROVIDENAME, scareMem); rpmDepSet provides = dsNew(h, RPMTAG_PROVIDENAME, scareMem);
TFI_t fi = fiNew(ts, NULL, h, RPMTAG_BASENAMES, scareMem); TFI_t fi = fiNew(ts, NULL, h, RPMTAG_BASENAMES, scareMem);
@ -621,7 +502,6 @@ rpmTransactionSet rpmtransFree(rpmTransactionSet ts)
pi = teInitIterator(ts); pi = teInitIterator(ts);
for (pi = teInitIterator(ts), oc = 0; (p = teNextIterator(pi)) != NULL; oc++) { for (pi = teInitIterator(ts), oc = 0; (p = teNextIterator(pi)) != NULL; oc++) {
delTE(p);
/*@-type -unqualifiedtrans @*/ /*@-type -unqualifiedtrans @*/
ts->order[oc] = teFree(ts->order[oc]); ts->order[oc] = teFree(ts->order[oc]);
/*@=type =unqualifiedtrans @*/ /*@=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. * @warning The fd argument has been eliminated, and is assumed always NULL.
* *
* @param ts transaction set * @param ts transaction set
* @param h package header * @param h header
* @param key package private data * @param key package retrieval key (e.g. file name)
* @param upgrade is package being upgraded? * @param upgrade is package being upgraded?
* @param relocs package file relocations * @param relocs package file relocations
* @return 0 on success, 1 on I/O error, 2 needs capabilities * @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 transactionElement @*/
/*@access rpmTransactionSet @*/ /*@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) transactionElement teFree(transactionElement te)
{ {
if (te != NULL) { if (te != NULL) {
delTE(te);
memset(te, 0, sizeof(*te)); /* XXX trash and burn */ memset(te, 0, sizeof(*te)); /* XXX trash and burn */
te = _free(te); te = _free(te);
} }
return NULL; return NULL;
} }
transactionElement teNew(void) transactionElement teNew(rpmTransactionSet ts, Header h,
fnpyKey key, rpmRelocation * relocs)
{ {
transactionElement te = xcalloc(1, sizeof(*te)); transactionElement te = xcalloc(1, sizeof(*te));
addTE(ts, te, h, key, relocs);
return te; return te;
} }

View File

@ -132,11 +132,17 @@ transactionElement teFree(/*@only@*/ /*@null@*/ transactionElement te)
/*@modifies te@*/; /*@modifies te@*/;
/** /**
* Create a transaction element. * 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 * @return new transaction element
*/ */
/*@only@*/ /*@null@*/ /*@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. * Retrieve type of transaction element.

View File

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