3 * Routine(s) to handle an "rpmte" transaction element.
13 #define _RPMTE_INTERNAL
25 void rpmteCleanDS(rpmte te)
27 te->this = rpmdsFree(te->this);
28 te->provides = rpmdsFree(te->provides);
29 te->requires = rpmdsFree(te->requires);
30 te->conflicts = rpmdsFree(te->conflicts);
31 te->obsoletes = rpmdsFree(te->obsoletes);
35 * Destroy transaction element data.
36 * @param p transaction element
38 static void delTE(rpmte p)
39 /*@globals fileSystem @*/
40 /*@modifies p, fileSystem @*/
45 for (r = p->relocs; (r->oldPath || r->newPath); r++) {
46 r->oldPath = _free(r->oldPath);
47 r->newPath = _free(r->newPath);
49 p->relocs = _free(p->relocs);
54 p->fi = rpmfiFree(p->fi);
57 p->fd = fdFree(p->fd, "delTE");
60 p->arch = _free(p->arch);
61 p->epoch = _free(p->epoch);
62 p->name = _free(p->name);
63 p->NEVR = _free(p->NEVR);
64 p->NEVRA = _free(p->NEVRA);
66 p->h = headerFree(p->h);
69 memset(p, 0, sizeof(*p)); /* XXX trash and burn */
71 /*@-nullstate@*/ /* FIX: p->{NEVR,name} annotations */
77 * Initialize transaction element data from header.
78 * @param ts transaction set
79 * @param p transaction element
81 * @param key (TR_ADDED) package retrieval key (e.g. file name)
82 * @param relocs (TR_ADDED) package file relocations
85 static void addTE(rpmts ts, rpmte p, Header h,
86 /*@dependent@*/ /*@null@*/ fnpyKey key,
87 /*@null@*/ rpmRelocation * relocs)
88 /*@globals fileSystem @*/
89 /*@modifies ts, p, h, fileSystem @*/
92 HGE_t hge = (HGE_t)headerGetEntryMinMemory;
95 const char * arch, * os;
100 p->NEVR = hGetNEVR(h, NULL);
101 p->name = xstrdup(p->NEVR);
102 if ((p->release = strrchr(p->name, '-')) != NULL)
103 *p->release++ = '\0';
104 if ((p->version = strrchr(p->name, '-')) != NULL)
105 *p->version++ = '\0';
108 xx = hge(h, RPMTAG_ARCH, NULL, (void **)&arch, NULL);
109 p->arch = (arch != NULL ? xstrdup(arch) : NULL);
111 xx = hge(h, RPMTAG_OS, NULL, (void **)&os, NULL);
112 p->os = (os != NULL ? xstrdup(os) : NULL);
114 nb = strlen(p->NEVR) + 1;
116 nb += strlen(p->arch) + 1;
120 t = stpcpy(t, p->NEVR);
122 t = stpcpy( stpcpy( t, "."), p->arch);
125 xx = hge(h, RPMTAG_EPOCH, NULL, (void **)&ep, NULL);
128 p->epoch = xmalloc(20);
129 sprintf(p->epoch, "%d", *ep);
134 if (relocs != NULL) {
138 for (i = 0, r = relocs; r->oldPath || r->newPath; i++, r++)
140 p->relocs = xmalloc((i + 1) * sizeof(*p->relocs));
142 for (i = 0, r = relocs; r->oldPath || r->newPath; i++, r++) {
143 p->relocs[i].oldPath = r->oldPath ? xstrdup(r->oldPath) : NULL;
144 p->relocs[i].newPath = r->newPath ? xstrdup(r->newPath) : NULL;
146 p->relocs[i].oldPath = NULL;
147 p->relocs[i].newPath = NULL;
157 p->this = rpmdsThis(h, RPMTAG_PROVIDENAME, RPMSENSE_EQUAL);
158 p->provides = rpmdsNew(h, RPMTAG_PROVIDENAME, scareMem);
159 p->requires = rpmdsNew(h, RPMTAG_REQUIRENAME, scareMem);
160 p->conflicts = rpmdsNew(h, RPMTAG_CONFLICTNAME, scareMem);
161 p->obsoletes = rpmdsNew(h, RPMTAG_OBSOLETENAME, scareMem);
163 savep = rpmtsSetRelocateElement(ts, p);
164 p->fi = rpmfiNew(ts, h, RPMTAG_BASENAMES, scareMem);
165 (void) rpmtsSetRelocateElement(ts, savep);
167 rpmteColorDS(p, RPMTAG_PROVIDENAME);
168 rpmteColorDS(p, RPMTAG_REQUIRENAME);
175 rpmte rpmteFree(rpmte te)
179 memset(te, 0, sizeof(*te)); /* XXX trash and burn */
185 rpmte rpmteNew(const rpmts ts, Header h,
188 rpmRelocation * relocs,
192 rpmte p = xcalloc(1, sizeof(*p));
196 addTE(ts, p, h, key, relocs);
200 p->u.addedKey = pkgKey;
202 xx = headerGetEntry(h, RPMTAG_SIGSIZE, NULL, (void **)&ep, NULL);
203 /* XXX 256 is only an estimate of signature header. */
205 p->pkgFileSize += 96 + 256 + *ep;
209 p->u.removed.dependsOnKey = pkgKey;
210 p->u.removed.dboffset = dboffset;
216 rpmElementType rpmteType(rpmte te)
218 return (te != NULL ? te->type : -1);
221 const char * rpmteN(rpmte te)
223 return (te != NULL ? te->name : NULL);
226 const char * rpmteE(rpmte te)
228 return (te != NULL ? te->epoch : NULL);
231 const char * rpmteV(rpmte te)
233 return (te != NULL ? te->version : NULL);
236 const char * rpmteR(rpmte te)
238 return (te != NULL ? te->release : NULL);
241 const char * rpmteA(rpmte te)
243 return (te != NULL ? te->arch : NULL);
246 const char * rpmteO(rpmte te)
248 return (te != NULL ? te->os : NULL);
251 uint_32 rpmteColor(rpmte te)
253 return (te != NULL ? te->color : 0);
256 uint_32 rpmteSetColor(rpmte te, uint_32 color)
266 uint_32 rpmtePkgFileSize(rpmte te)
268 return (te != NULL ? te->pkgFileSize : 0);
271 int rpmteDepth(rpmte te)
273 return (te != NULL ? te->depth : 0);
276 int rpmteSetDepth(rpmte te, int ndepth)
286 int rpmteNpreds(rpmte te)
288 return (te != NULL ? te->npreds : 0);
291 int rpmteSetNpreds(rpmte te, int npreds)
301 int rpmteTree(rpmte te)
303 return (te != NULL ? te->tree : 0);
306 int rpmteSetTree(rpmte te, int ntree)
316 rpmte rpmteParent(rpmte te)
318 return (te != NULL ? te->parent : NULL);
321 rpmte rpmteSetParent(rpmte te, rpmte pte)
327 /*@-assignexpose -temptrans@*/
329 /*@=assignexpose =temptrans@*/
335 int rpmteDegree(rpmte te)
337 return (te != NULL ? te->degree : 0);
340 int rpmteSetDegree(rpmte te, int ndegree)
344 odegree = te->degree;
345 te->degree = ndegree;
350 tsortInfo rpmteTSI(rpmte te)
352 /*@-compdef -retalias -retexpose -usereleased @*/
354 /*@=compdef =retalias =retexpose =usereleased @*/
357 void rpmteFreeTSI(rpmte te)
359 if (te != NULL && rpmteTSI(te) != NULL) {
362 /* Clean up tsort remnants (if any). */
363 while ((tsi = rpmteTSI(te)->tsi_next) != NULL) {
364 rpmteTSI(te)->tsi_next = tsi->tsi_next;
365 tsi->tsi_next = NULL;
368 te->tsi = _free(te->tsi);
370 /*@-nullstate@*/ /* FIX: te->tsi is NULL */
375 void rpmteNewTSI(rpmte te)
379 te->tsi = xcalloc(1, sizeof(*te->tsi));
383 alKey rpmteAddedKey(rpmte te)
385 return (te != NULL ? te->u.addedKey : RPMAL_NOMATCH);
388 alKey rpmteSetAddedKey(rpmte te, alKey npkgKey)
390 alKey opkgKey = RPMAL_NOMATCH;
392 opkgKey = te->u.addedKey;
393 te->u.addedKey = npkgKey;
399 alKey rpmteDependsOnKey(rpmte te)
401 return (te != NULL ? te->u.removed.dependsOnKey : RPMAL_NOMATCH);
404 int rpmteDBOffset(rpmte te)
406 return (te != NULL ? te->u.removed.dboffset : 0);
409 const char * rpmteNEVR(rpmte te)
411 return (te != NULL ? te->NEVR : NULL);
414 const char * rpmteNEVRA(rpmte te)
416 return (te != NULL ? te->NEVRA : NULL);
419 FD_t rpmteFd(rpmte te)
421 /*@-compdef -refcounttrans -retalias -retexpose -usereleased @*/
422 return (te != NULL ? te->fd : NULL);
423 /*@=compdef =refcounttrans =retalias =retexpose =usereleased @*/
426 fnpyKey rpmteKey(rpmte te)
428 return (te != NULL ? te->key : NULL);
431 rpmds rpmteDS(rpmte te, rpmTag tag)
433 /*@-compdef -refcounttrans -retalias -retexpose -usereleased @*/
437 if (tag == RPMTAG_NAME)
440 if (tag == RPMTAG_PROVIDENAME)
443 if (tag == RPMTAG_REQUIRENAME)
446 if (tag == RPMTAG_CONFLICTNAME)
447 return te->conflicts;
449 if (tag == RPMTAG_OBSOLETENAME)
450 return te->obsoletes;
453 /*@=compdef =refcounttrans =retalias =retexpose =usereleased @*/
456 rpmfi rpmteFI(rpmte te, rpmTag tag)
458 /*@-compdef -refcounttrans -retalias -retexpose -usereleased @*/
462 if (tag == RPMTAG_BASENAMES)
466 /*@=compdef =refcounttrans =retalias =retexpose =usereleased @*/
469 void rpmteColorDS(rpmte te, rpmTag tag)
471 rpmfi fi = rpmteFI(te, RPMTAG_BASENAMES);
472 rpmds ds = rpmteDS(te, tag);
475 const int_32 * ddict;
484 if (!(te && (Count = rpmdsCount(ds)) > 0 && rpmfiFC(fi) > 0))
490 /*@notreached@*/ break;
491 case RPMTAG_PROVIDENAME:
494 case RPMTAG_REQUIRENAME:
499 nb = Count * sizeof(*colors);
500 colors = memset(alloca(nb), 0, nb);
501 nb = Count * sizeof(*refs);
502 refs = memset(alloca(nb), -1, nb);
504 /* Calculate dependency color and reference count. */
505 fi = rpmfiInit(fi, 0);
507 while (rpmfiNext(fi) >= 0) {
508 val = rpmfiFColor(fi);
510 ndx = rpmfiFDepends(fi, &ddict);
514 mydt = ((ix >> 24) & 0xff);
516 /*@innercontinue@*/ continue;
524 /* Set color/refs values in dependency set. */
526 while ((i = rpmdsNext(ds)) >= 0) {
529 (void) rpmdsSetColor(ds, val);
533 (void) rpmdsSetRefs(ds, val);
537 int rpmtsiOc(rpmtsi tsi)
542 rpmtsi XrpmtsiFree(/*@only@*//*@null@*/ rpmtsi tsi,
543 const char * fn, unsigned int ln)
545 /* XXX watchout: a funky recursion segfaults here iff nrefs is wrong. */
548 tsi->ts = rpmtsFree(tsi->ts);
553 fprintf(stderr, "*** tsi %p -- %s:%d\n", tsi, fn, ln);
558 rpmtsi XrpmtsiInit(rpmts ts, const char * fn, unsigned int ln)
562 tsi = xcalloc(1, sizeof(*tsi));
563 tsi->ts = rpmtsLink(ts, "rpmtsi");
564 tsi->reverse = ((rpmtsFlags(ts) & RPMTRANS_FLAG_REVERSE) ? 1 : 0);
565 tsi->oc = (tsi->reverse ? (rpmtsNElements(ts) - 1) : 0);
566 tsi->ocsave = tsi->oc;
569 fprintf(stderr, "*** tsi %p ++ %s:%d\n", tsi, fn, ln);
575 * Return next transaction element.
576 * @param tsi transaction element iterator
577 * @return transaction element, NULL on termination
579 static /*@null@*/ /*@dependent@*/
580 rpmte rpmtsiNextElement(rpmtsi tsi)
586 if (tsi == NULL || tsi->ts == NULL || rpmtsNElements(tsi->ts) <= 0)
590 if (tsi->oc >= 0) oc = tsi->oc--;
592 if (tsi->oc < rpmtsNElements(tsi->ts)) oc = tsi->oc++;
597 te = rpmtsElement(tsi->ts, oc);
602 rpmte rpmtsiNext(rpmtsi tsi, rpmElementType type)
606 while ((te = rpmtsiNextElement(tsi)) != NULL) {
607 if (type == 0 || (te->type & type) != 0)