3 * Routine(s) to handle an "rpmte" transaction element.
13 #define _RPMTE_INTERNAL
26 void rpmteCleanDS(rpmte te)
28 te->this = rpmdsFree(te->this);
29 te->provides = rpmdsFree(te->provides);
30 te->requires = rpmdsFree(te->requires);
31 te->conflicts = rpmdsFree(te->conflicts);
32 te->obsoletes = rpmdsFree(te->obsoletes);
36 * Destroy transaction element data.
37 * @param p transaction element
39 static void delTE(rpmte p)
40 /*@globals fileSystem @*/
41 /*@modifies p, fileSystem @*/
46 for (r = p->relocs; (r->oldPath || r->newPath); r++) {
47 r->oldPath = _free(r->oldPath);
48 r->newPath = _free(r->newPath);
50 p->relocs = _free(p->relocs);
55 p->fi = rpmfiFree(p->fi);
59 p->fd = fdFree(p->fd, "delTE");
63 p->arch = _free(p->arch);
64 p->epoch = _free(p->epoch);
65 p->name = _free(p->name);
66 p->NEVR = _free(p->NEVR);
68 p->h = headerFree(p->h);
71 memset(p, 0, sizeof(*p)); /* XXX trash and burn */
73 /*@-nullstate@*/ /* FIX: p->{NEVR,name} annotations */
79 * Initialize transaction element data from header.
80 * @param ts transaction set
81 * @param p transaction element
83 * @param key (TR_ADDED) package retrieval key (e.g. file name)
84 * @param relocs (TR_ADDED) package file relocations
87 static void addTE(rpmts ts, rpmte p, Header h,
88 /*@dependent@*/ /*@null@*/ fnpyKey key,
89 /*@null@*/ rpmRelocation * relocs)
90 /*@globals fileSystem @*/
91 /*@modifies ts, p, h, fileSystem @*/
94 HGE_t hge = (HGE_t)headerGetEntryMinMemory;
96 const char * arch, * os;
99 p->NEVR = hGetNEVR(h, NULL);
100 p->name = xstrdup(p->NEVR);
101 if ((p->release = strrchr(p->name, '-')) != NULL)
102 *p->release++ = '\0';
103 if ((p->version = strrchr(p->name, '-')) != NULL)
104 *p->version++ = '\0';
107 xx = hge(h, RPMTAG_ARCH, NULL, (void **)&arch, NULL);
108 p->arch = (arch != NULL ? xstrdup(arch) : NULL);
110 xx = hge(h, RPMTAG_OS, NULL, (void **)&os, NULL);
111 p->os = (os != NULL ? xstrdup(os) : NULL);
114 xx = hge(h, RPMTAG_EPOCH, NULL, (void **)&ep, NULL);
117 p->epoch = xmalloc(20);
118 sprintf(p->epoch, "%d", *ep);
123 p->this = rpmdsThis(h, RPMTAG_PROVIDENAME, RPMSENSE_EQUAL);
124 p->provides = rpmdsNew(h, RPMTAG_PROVIDENAME, scareMem);
125 p->fi = rpmfiNew(ts, h, RPMTAG_BASENAMES, scareMem);
126 p->requires = rpmdsNew(h, RPMTAG_REQUIRENAME, scareMem);
127 p->conflicts = rpmdsNew(h, RPMTAG_CONFLICTNAME, scareMem);
128 p->obsoletes = rpmdsNew(h, RPMTAG_OBSOLETENAME, scareMem);
136 if (relocs != NULL) {
140 for (i = 0, r = relocs; r->oldPath || r->newPath; i++, r++)
142 p->relocs = xmalloc((i + 1) * sizeof(*p->relocs));
144 for (i = 0, r = relocs; r->oldPath || r->newPath; i++, r++) {
145 p->relocs[i].oldPath = r->oldPath ? xstrdup(r->oldPath) : NULL;
146 p->relocs[i].newPath = r->newPath ? xstrdup(r->newPath) : NULL;
148 p->relocs[i].oldPath = NULL;
149 p->relocs[i].newPath = NULL;
156 rpmte rpmteFree(rpmte te)
160 memset(te, 0, sizeof(*te)); /* XXX trash and burn */
166 rpmte rpmteNew(const rpmts ts, Header h,
169 rpmRelocation * relocs,
173 rpmte te = xcalloc(1, sizeof(*te));
175 addTE(ts, te, h, key, relocs);
179 te->u.addedKey = pkgKey;
183 te->u.removed.dependsOnKey = pkgKey;
184 te->u.removed.dboffset = dboffset;
190 rpmElementType rpmteType(rpmte te)
192 return (te != NULL ? te->type : -1);
195 const char * rpmteN(rpmte te)
197 return (te != NULL ? te->name : NULL);
200 const char * rpmteE(rpmte te)
202 return (te != NULL ? te->epoch : NULL);
205 const char * rpmteV(rpmte te)
207 return (te != NULL ? te->version : NULL);
210 const char * rpmteR(rpmte te)
212 return (te != NULL ? te->release : NULL);
215 const char * rpmteA(rpmte te)
217 return (te != NULL ? te->arch : NULL);
220 const char * rpmteO(rpmte te)
222 return (te != NULL ? te->os : NULL);
225 int rpmteMultiLib(rpmte te)
227 return (te != NULL ? te->multiLib : 0);
230 int rpmteSetMultiLib(rpmte te, int nmultiLib)
234 omultiLib = te->multiLib;
235 te->multiLib = nmultiLib;
240 int rpmteDepth(rpmte te)
242 return (te != NULL ? te->depth : 0);
245 int rpmteSetDepth(rpmte te, int ndepth)
255 int rpmteNpreds(rpmte te)
257 return (te != NULL ? te->npreds : 0);
260 int rpmteSetNpreds(rpmte te, int npreds)
270 int rpmteTree(rpmte te)
272 return (te != NULL ? te->tree : 0);
275 int rpmteSetTree(rpmte te, int ntree)
285 rpmte rpmteParent(rpmte te)
287 return (te != NULL ? te->parent : NULL);
290 rpmte rpmteSetParent(rpmte te, rpmte pte)
296 /*@-assignexpose -temptrans@*/
298 /*@=assignexpose =temptrans@*/
304 int rpmteDegree(rpmte te)
306 return (te != NULL ? te->degree : 0);
309 int rpmteSetDegree(rpmte te, int ndegree)
313 odegree = te->degree;
314 te->degree = ndegree;
319 tsortInfo rpmteTSI(rpmte te)
321 /*@-compdef -retalias -retexpose -usereleased @*/
323 /*@=compdef =retalias =retexpose =usereleased @*/
326 void rpmteFreeTSI(rpmte te)
328 if (te != NULL && rpmteTSI(te) != NULL) {
331 /* Clean up tsort remnants (if any). */
332 while ((tsi = rpmteTSI(te)->tsi_next) != NULL) {
333 rpmteTSI(te)->tsi_next = tsi->tsi_next;
334 tsi->tsi_next = NULL;
337 te->tsi = _free(te->tsi);
339 /*@-nullstate@*/ /* FIX: te->tsi is NULL */
344 void rpmteNewTSI(rpmte te)
348 te->tsi = xcalloc(1, sizeof(*te->tsi));
352 alKey rpmteAddedKey(rpmte te)
354 return (te != NULL ? te->u.addedKey : RPMAL_NOMATCH);
357 alKey rpmteSetAddedKey(rpmte te, alKey npkgKey)
359 alKey opkgKey = RPMAL_NOMATCH;
361 opkgKey = te->u.addedKey;
362 te->u.addedKey = npkgKey;
368 alKey rpmteDependsOnKey(rpmte te)
370 return (te != NULL ? te->u.removed.dependsOnKey : RPMAL_NOMATCH);
373 int rpmteDBOffset(rpmte te)
375 return (te != NULL ? te->u.removed.dboffset : 0);
378 const char * rpmteNEVR(rpmte te)
380 return (te != NULL ? te->NEVR : NULL);
383 FD_t rpmteFd(rpmte te)
385 /*@-compdef -refcounttrans -retalias -retexpose -usereleased @*/
386 return (te != NULL ? te->fd : NULL);
387 /*@=compdef =refcounttrans =retalias =retexpose =usereleased @*/
390 fnpyKey rpmteKey(rpmte te)
392 return (te != NULL ? te->key : NULL);
395 rpmds rpmteDS(rpmte te, rpmTag tag)
397 /*@-compdef -refcounttrans -retalias -retexpose -usereleased @*/
401 if (tag == RPMTAG_NAME)
404 if (tag == RPMTAG_PROVIDENAME)
407 if (tag == RPMTAG_REQUIRENAME)
410 if (tag == RPMTAG_CONFLICTNAME)
411 return te->conflicts;
413 if (tag == RPMTAG_OBSOLETENAME)
414 return te->obsoletes;
417 /*@=compdef =refcounttrans =retalias =retexpose =usereleased @*/
420 rpmfi rpmteFI(rpmte te, rpmTag tag)
422 /*@-compdef -refcounttrans -retalias -retexpose -usereleased @*/
426 if (tag == RPMTAG_BASENAMES)
430 /*@=compdef =refcounttrans =retalias =retexpose =usereleased @*/
433 int rpmtsiOc(rpmtsi tsi)
438 rpmtsi XrpmtsiFree(/*@only@*//*@null@*/ rpmtsi tsi,
439 const char * fn, unsigned int ln)
441 /* XXX watchout: a funky recursion segfaults here iff nrefs is wrong. */
443 tsi->ts = rpmtsFree(tsi->ts);
447 fprintf(stderr, "*** tsi %p -- %s:%d\n", tsi, fn, ln);
452 rpmtsi XrpmtsiInit(rpmts ts, const char * fn, unsigned int ln)
456 tsi = xcalloc(1, sizeof(*tsi));
457 tsi->ts = rpmtsLink(ts, "rpmtsi");
458 tsi->reverse = ((rpmtsFlags(ts) & RPMTRANS_FLAG_REVERSE) ? 1 : 0);
459 tsi->oc = (tsi->reverse ? (rpmtsNElements(ts) - 1) : 0);
460 tsi->ocsave = tsi->oc;
463 fprintf(stderr, "*** tsi %p ++ %s:%d\n", tsi, fn, ln);
469 * Return next transaction element.
470 * @param tsi transaction element iterator
471 * @return transaction element, NULL on termination
473 static /*@dependent@*/ /*@null@*/
474 rpmte rpmtsiNextElement(rpmtsi tsi)
480 if (tsi == NULL || tsi->ts == NULL || rpmtsNElements(tsi->ts) <= 0)
484 if (tsi->oc >= 0) oc = tsi->oc--;
486 if (tsi->oc < rpmtsNElements(tsi->ts)) oc = tsi->oc++;
491 te = rpmtsElement(tsi->ts, oc);
496 rpmte rpmtsiNext(rpmtsi tsi, rpmElementType type)
500 while ((te = rpmtsiNextElement(tsi)) != NULL) {
501 if (type == 0 || (te->type & type) != 0)