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 ts transaction set
38 * @param p transaction element
40 * @param key (TR_ADDED) package retrieval key (e.g. file name)
41 * @param relocs (TR_ADDED) package file relocations
43 static void delTE(rpmte p)
44 /*@globals fileSystem @*/
45 /*@modifies p, fileSystem @*/
50 for (r = p->relocs; (r->oldPath || r->newPath); r++) {
51 r->oldPath = _free(r->oldPath);
52 r->newPath = _free(r->newPath);
54 p->relocs = _free(p->relocs);
59 p->fi = rpmfiFree(p->fi);
63 p->fd = fdFree(p->fd, "delTE");
67 p->arch = _free(p->arch);
68 p->epoch = _free(p->epoch);
69 p->name = _free(p->name);
70 p->NEVR = _free(p->NEVR);
72 p->h = headerFree(p->h);
75 memset(p, 0, sizeof(*p)); /* XXX trash and burn */
77 /*@-nullstate@*/ /* FIX: p->{NEVR,name} annotations */
83 * Initialize transaction element data from header.
84 * @param ts transaction set
85 * @param p transaction element
87 * @param key (TR_ADDED) package retrieval key (e.g. file name)
88 * @param relocs (TR_ADDED) package file relocations
91 static void addTE(rpmts ts, rpmte p, Header h,
92 /*@dependent@*/ /*@null@*/ fnpyKey key,
93 /*@null@*/ rpmRelocation * relocs)
94 /*@globals fileSystem @*/
95 /*@modifies ts, p, h, fileSystem @*/
98 HGE_t hge = (HGE_t)headerGetEntryMinMemory;
100 const char * arch, * os;
103 p->NEVR = hGetNEVR(h, NULL);
104 p->name = xstrdup(p->NEVR);
105 if ((p->release = strrchr(p->name, '-')) != NULL)
106 *p->release++ = '\0';
107 if ((p->version = strrchr(p->name, '-')) != NULL)
108 *p->version++ = '\0';
111 xx = hge(h, RPMTAG_ARCH, NULL, (void **)&arch, NULL);
112 p->arch = (arch != NULL ? xstrdup(arch) : NULL);
114 xx = hge(h, RPMTAG_OS, NULL, (void **)&os, NULL);
115 p->os = (os != NULL ? xstrdup(os) : NULL);
118 xx = hge(h, RPMTAG_EPOCH, NULL, (void **)&ep, NULL);
121 p->epoch = xmalloc(20);
122 sprintf(p->epoch, "%d", *ep);
127 p->this = rpmdsThis(h, RPMTAG_PROVIDENAME, RPMSENSE_EQUAL);
128 p->provides = rpmdsNew(h, RPMTAG_PROVIDENAME, scareMem);
129 p->fi = rpmfiNew(ts, h, RPMTAG_BASENAMES, scareMem);
130 p->requires = rpmdsNew(h, RPMTAG_REQUIRENAME, scareMem);
131 p->conflicts = rpmdsNew(h, RPMTAG_CONFLICTNAME, scareMem);
132 p->obsoletes = rpmdsNew(h, RPMTAG_OBSOLETENAME, scareMem);
140 if (relocs != NULL) {
144 for (i = 0, r = relocs; r->oldPath || r->newPath; i++, r++)
146 p->relocs = xmalloc((i + 1) * sizeof(*p->relocs));
148 for (i = 0, r = relocs; r->oldPath || r->newPath; i++, r++) {
149 p->relocs[i].oldPath = r->oldPath ? xstrdup(r->oldPath) : NULL;
150 p->relocs[i].newPath = r->newPath ? xstrdup(r->newPath) : NULL;
152 p->relocs[i].oldPath = NULL;
153 p->relocs[i].newPath = NULL;
160 rpmte rpmteFree(rpmte te)
164 memset(te, 0, sizeof(*te)); /* XXX trash and burn */
170 rpmte rpmteNew(const rpmts ts, Header h,
173 rpmRelocation * relocs,
177 rpmte te = xcalloc(1, sizeof(*te));
179 addTE(ts, te, h, key, relocs);
183 te->u.addedKey = pkgKey;
187 te->u.removed.dependsOnKey = pkgKey;
188 te->u.removed.dboffset = dboffset;
194 rpmElementType rpmteType(rpmte te)
196 return (te != NULL ? te->type : -1);
199 const char * rpmteN(rpmte te)
201 return (te != NULL ? te->name : NULL);
204 const char * rpmteE(rpmte te)
206 return (te != NULL ? te->epoch : NULL);
209 const char * rpmteV(rpmte te)
211 return (te != NULL ? te->version : NULL);
214 const char * rpmteR(rpmte te)
216 return (te != NULL ? te->release : NULL);
219 const char * rpmteA(rpmte te)
221 return (te != NULL ? te->arch : NULL);
224 const char * rpmteO(rpmte te)
226 return (te != NULL ? te->os : NULL);
229 int rpmteMultiLib(rpmte te)
231 return (te != NULL ? te->multiLib : 0);
234 int rpmteSetMultiLib(rpmte te, int nmultiLib)
238 omultiLib = te->multiLib;
239 te->multiLib = nmultiLib;
244 int rpmteDepth(rpmte te)
246 return (te != NULL ? te->depth : 0);
249 int rpmteSetDepth(rpmte te, int ndepth)
259 int rpmteNpreds(rpmte te)
261 return (te != NULL ? te->npreds : 0);
264 int rpmteSetNpreds(rpmte te, int npreds)
274 int rpmteTree(rpmte te)
276 return (te != NULL ? te->tree : 0);
279 int rpmteSetTree(rpmte te, int ntree)
289 rpmte rpmteParent(rpmte te)
291 return (te != NULL ? te->parent : NULL);
294 rpmte rpmteSetParent(rpmte te, rpmte pte)
300 /*@-assignexpose -temptrans@*/
302 /*@=assignexpose =temptrans@*/
308 int rpmteDegree(rpmte te)
310 return (te != NULL ? te->degree : 0);
313 int rpmteSetDegree(rpmte te, int ndegree)
317 odegree = te->degree;
318 te->degree = ndegree;
323 tsortInfo rpmteTSI(rpmte te)
325 /*@-compdef -retalias -retexpose -usereleased @*/
327 /*@=compdef =retalias =retexpose =usereleased @*/
330 void rpmteFreeTSI(rpmte te)
332 if (te != NULL && rpmteTSI(te) != NULL) {
335 /* Clean up tsort remnants (if any). */
336 while ((tsi = rpmteTSI(te)->tsi_next) != NULL) {
337 rpmteTSI(te)->tsi_next = tsi->tsi_next;
338 tsi->tsi_next = NULL;
341 te->tsi = _free(te->tsi);
343 /*@-nullstate@*/ /* FIX: te->tsi is NULL */
348 void rpmteNewTSI(rpmte te)
352 te->tsi = xcalloc(1, sizeof(*te->tsi));
356 alKey rpmteAddedKey(rpmte te)
358 return (te != NULL ? te->u.addedKey : RPMAL_NOMATCH);
361 alKey rpmteSetAddedKey(rpmte te, alKey npkgKey)
363 alKey opkgKey = RPMAL_NOMATCH;
365 opkgKey = te->u.addedKey;
366 te->u.addedKey = npkgKey;
372 alKey rpmteDependsOnKey(rpmte te)
374 return (te != NULL ? te->u.removed.dependsOnKey : RPMAL_NOMATCH);
377 int rpmteDBOffset(rpmte te)
379 return (te != NULL ? te->u.removed.dboffset : 0);
382 const char * rpmteNEVR(rpmte te)
384 return (te != NULL ? te->NEVR : NULL);
387 FD_t rpmteFd(rpmte te)
389 /*@-compdef -refcounttrans -retalias -retexpose -usereleased @*/
390 return (te != NULL ? te->fd : NULL);
391 /*@=compdef =refcounttrans =retalias =retexpose =usereleased @*/
394 fnpyKey rpmteKey(rpmte te)
396 return (te != NULL ? te->key : NULL);
399 rpmds rpmteDS(rpmte te, rpmTag tag)
401 /*@-compdef -refcounttrans -retalias -retexpose -usereleased @*/
405 if (tag == RPMTAG_NAME)
408 if (tag == RPMTAG_PROVIDENAME)
411 if (tag == RPMTAG_REQUIRENAME)
414 if (tag == RPMTAG_CONFLICTNAME)
415 return te->conflicts;
417 if (tag == RPMTAG_OBSOLETENAME)
418 return te->obsoletes;
421 /*@=compdef =refcounttrans =retalias =retexpose =usereleased @*/
424 rpmfi rpmteFI(rpmte te, rpmTag tag)
426 /*@-compdef -refcounttrans -retalias -retexpose -usereleased @*/
430 if (tag == RPMTAG_BASENAMES)
434 /*@=compdef =refcounttrans =retalias =retexpose =usereleased @*/
437 int rpmtsiOc(rpmtsi tsi)
442 rpmtsi XrpmtsiFree(/*@only@*//*@null@*/ rpmtsi tsi,
443 const char * fn, unsigned int ln)
445 /* XXX watchout: a funky recursion segfaults here iff nrefs is wrong. */
447 tsi->ts = rpmtsFree(tsi->ts);
451 fprintf(stderr, "*** tsi %p -- %s:%d\n", tsi, fn, ln);
456 rpmtsi XrpmtsiInit(rpmts ts, const char * fn, unsigned int ln)
460 tsi = xcalloc(1, sizeof(*tsi));
461 tsi->ts = rpmtsLink(ts, "rpmtsi");
462 tsi->reverse = ((rpmtsFlags(ts) & RPMTRANS_FLAG_REVERSE) ? 1 : 0);
463 tsi->oc = (tsi->reverse ? (rpmtsNElements(ts) - 1) : 0);
464 tsi->ocsave = tsi->oc;
467 fprintf(stderr, "*** tsi %p ++ %s:%d\n", tsi, fn, ln);
473 * Return next transaction element.
474 * @param tsi transaction element iterator
475 * @return transaction element, NULL on termination
477 static /*@dependent@*/ /*@null@*/
478 rpmte rpmtsiNextElement(rpmtsi tsi)
484 if (tsi == NULL || tsi->ts == NULL || rpmtsNElements(tsi->ts) <= 0)
488 if (tsi->oc >= 0) oc = tsi->oc--;
490 if (tsi->oc < rpmtsNElements(tsi->ts)) oc = tsi->oc++;
495 te = rpmtsElement(tsi->ts, oc);
500 rpmte rpmtsiNext(rpmtsi tsi, rpmElementType type)
504 while ((te = rpmtsiNextElement(tsi)) != NULL) {
505 if (type == 0 || (te->type & type) != 0)