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 rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
90 rpmGlobalMacroContext, fileSystem, internalState @*/
93 HGE_t hge = (HGE_t)headerGetEntryMinMemory;
96 const char * arch, * os;
101 p->NEVR = hGetNEVR(h, NULL);
102 p->name = xstrdup(p->NEVR);
103 if ((p->release = strrchr(p->name, '-')) != NULL)
104 *p->release++ = '\0';
105 if ((p->version = strrchr(p->name, '-')) != NULL)
106 *p->version++ = '\0';
108 /* Set db_instance to 0 as it has not been installed
114 xx = hge(h, RPMTAG_ARCH, NULL, (void **)&arch, NULL);
116 p->arch = xstrdup(arch);
117 p->archScore = rpmMachineScore(RPM_MACHTABLE_INSTARCH, arch);
123 xx = hge(h, RPMTAG_OS, NULL, (void **)&os, NULL);
126 p->osScore = rpmMachineScore(RPM_MACHTABLE_INSTOS, os);
132 nb = strlen(p->NEVR) + 1;
134 nb += strlen(p->arch) + 1;
138 t = stpcpy(t, p->NEVR);
140 t = stpcpy( stpcpy( t, "."), p->arch);
143 xx = hge(h, RPMTAG_EPOCH, NULL, (void **)&ep, NULL);
146 p->epoch = xmalloc(20);
147 sprintf(p->epoch, "%d", *ep);
154 if (relocs != NULL) {
158 for (r = relocs; r->oldPath || r->newPath; r++)
160 p->relocs = xmalloc((p->nrelocs + 1) * sizeof(*p->relocs));
162 for (i = 0, r = relocs; r->oldPath || r->newPath; i++, r++) {
163 p->relocs[i].oldPath = r->oldPath ? xstrdup(r->oldPath) : NULL;
164 p->relocs[i].newPath = r->newPath ? xstrdup(r->newPath) : NULL;
166 p->relocs[i].oldPath = NULL;
167 p->relocs[i].newPath = NULL;
169 p->autorelocatex = -1;
176 p->this = rpmdsThis(h, RPMTAG_PROVIDENAME, RPMSENSE_EQUAL);
177 p->provides = rpmdsNew(h, RPMTAG_PROVIDENAME, scareMem);
178 p->requires = rpmdsNew(h, RPMTAG_REQUIRENAME, scareMem);
179 p->conflicts = rpmdsNew(h, RPMTAG_CONFLICTNAME, scareMem);
180 p->obsoletes = rpmdsNew(h, RPMTAG_OBSOLETENAME, scareMem);
182 savep = rpmtsSetRelocateElement(ts, p);
183 p->fi = rpmfiNew(ts, h, RPMTAG_BASENAMES, scareMem);
184 (void) rpmtsSetRelocateElement(ts, savep);
186 rpmteColorDS(p, RPMTAG_PROVIDENAME);
187 rpmteColorDS(p, RPMTAG_REQUIRENAME);
194 rpmte rpmteFree(rpmte te)
198 memset(te, 0, sizeof(*te)); /* XXX trash and burn */
204 rpmte rpmteNew(const rpmts ts, Header h,
207 rpmRelocation * relocs,
211 rpmte p = xcalloc(1, sizeof(*p));
216 addTE(ts, p, h, key, relocs);
219 p->u.addedKey = pkgKey;
221 xx = headerGetEntry(h, RPMTAG_SIGSIZE, NULL, (void **)&ep, NULL);
222 /* XXX 256 is only an estimate of signature header. */
224 p->pkgFileSize += 96 + 256 + *ep;
227 p->u.removed.dependsOnKey = pkgKey;
228 p->u.removed.dboffset = dboffset;
234 /* Get the DB Instance value */
235 unsigned int rpmteDBInstance(rpmte te)
237 return (te != NULL ? te->db_instance : 0);
240 /* Set the DB Instance value */
241 void rpmteSetDBInstance(rpmte te, unsigned int instance)
244 te->db_instance = instance;
247 rpmElementType rpmteType(rpmte te)
249 return (te != NULL ? te->type : -1);
252 const char * rpmteN(rpmte te)
254 return (te != NULL ? te->name : NULL);
257 const char * rpmteE(rpmte te)
259 return (te != NULL ? te->epoch : NULL);
262 const char * rpmteV(rpmte te)
264 return (te != NULL ? te->version : NULL);
267 const char * rpmteR(rpmte te)
269 return (te != NULL ? te->release : NULL);
272 const char * rpmteA(rpmte te)
274 return (te != NULL ? te->arch : NULL);
277 const char * rpmteO(rpmte te)
279 return (te != NULL ? te->os : NULL);
282 uint_32 rpmteColor(rpmte te)
284 return (te != NULL ? te->color : 0);
287 uint_32 rpmteSetColor(rpmte te, uint_32 color)
297 uint_32 rpmtePkgFileSize(rpmte te)
299 return (te != NULL ? te->pkgFileSize : 0);
302 int rpmteDepth(rpmte te)
304 return (te != NULL ? te->depth : 0);
307 int rpmteSetDepth(rpmte te, int ndepth)
317 int rpmteNpreds(rpmte te)
319 return (te != NULL ? te->npreds : 0);
322 int rpmteSetNpreds(rpmte te, int npreds)
332 int rpmteTree(rpmte te)
334 return (te != NULL ? te->tree : 0);
337 int rpmteSetTree(rpmte te, int ntree)
347 rpmte rpmteParent(rpmte te)
349 return (te != NULL ? te->parent : NULL);
352 rpmte rpmteSetParent(rpmte te, rpmte pte)
358 /*@-assignexpose -temptrans@*/
360 /*@=assignexpose =temptrans@*/
366 int rpmteDegree(rpmte te)
368 return (te != NULL ? te->degree : 0);
371 int rpmteSetDegree(rpmte te, int ndegree)
375 odegree = te->degree;
376 te->degree = ndegree;
381 tsortInfo rpmteTSI(rpmte te)
383 /*@-compdef -retalias -retexpose -usereleased @*/
385 /*@=compdef =retalias =retexpose =usereleased @*/
388 void rpmteFreeTSI(rpmte te)
390 if (te != NULL && rpmteTSI(te) != NULL) {
393 /* Clean up tsort remnants (if any). */
394 while ((tsi = rpmteTSI(te)->tsi_next) != NULL) {
395 rpmteTSI(te)->tsi_next = tsi->tsi_next;
396 tsi->tsi_next = NULL;
399 te->tsi = _free(te->tsi);
401 /*@-nullstate@*/ /* FIX: te->tsi is NULL */
406 void rpmteNewTSI(rpmte te)
410 te->tsi = xcalloc(1, sizeof(*te->tsi));
414 alKey rpmteAddedKey(rpmte te)
416 return (te != NULL ? te->u.addedKey : RPMAL_NOMATCH);
419 alKey rpmteSetAddedKey(rpmte te, alKey npkgKey)
421 alKey opkgKey = RPMAL_NOMATCH;
423 opkgKey = te->u.addedKey;
424 te->u.addedKey = npkgKey;
430 alKey rpmteDependsOnKey(rpmte te)
432 return (te != NULL ? te->u.removed.dependsOnKey : RPMAL_NOMATCH);
435 int rpmteDBOffset(rpmte te)
437 return (te != NULL ? te->u.removed.dboffset : 0);
440 const char * rpmteNEVR(rpmte te)
442 return (te != NULL ? te->NEVR : NULL);
445 const char * rpmteNEVRA(rpmte te)
447 return (te != NULL ? te->NEVRA : NULL);
450 FD_t rpmteFd(rpmte te)
452 /*@-compdef -refcounttrans -retalias -retexpose -usereleased @*/
453 return (te != NULL ? te->fd : NULL);
454 /*@=compdef =refcounttrans =retalias =retexpose =usereleased @*/
457 fnpyKey rpmteKey(rpmte te)
459 return (te != NULL ? te->key : NULL);
462 rpmds rpmteDS(rpmte te, rpmTag tag)
464 /*@-compdef -refcounttrans -retalias -retexpose -usereleased @*/
468 if (tag == RPMTAG_NAME)
471 if (tag == RPMTAG_PROVIDENAME)
474 if (tag == RPMTAG_REQUIRENAME)
477 if (tag == RPMTAG_CONFLICTNAME)
478 return te->conflicts;
480 if (tag == RPMTAG_OBSOLETENAME)
481 return te->obsoletes;
484 /*@=compdef =refcounttrans =retalias =retexpose =usereleased @*/
487 rpmfi rpmteFI(rpmte te, rpmTag tag)
489 /*@-compdef -refcounttrans -retalias -retexpose -usereleased @*/
493 if (tag == RPMTAG_BASENAMES)
497 /*@=compdef =refcounttrans =retalias =retexpose =usereleased @*/
500 void rpmteColorDS(rpmte te, rpmTag tag)
502 rpmfi fi = rpmteFI(te, RPMTAG_BASENAMES);
503 rpmds ds = rpmteDS(te, tag);
506 const int_32 * ddict;
515 if (!(te && (Count = rpmdsCount(ds)) > 0 && rpmfiFC(fi) > 0))
521 /*@notreached@*/ break;
522 case RPMTAG_PROVIDENAME:
525 case RPMTAG_REQUIRENAME:
530 nb = Count * sizeof(*colors);
531 colors = memset(alloca(nb), 0, nb);
532 nb = Count * sizeof(*refs);
533 refs = memset(alloca(nb), -1, nb);
535 /* Calculate dependency color and reference count. */
536 fi = rpmfiInit(fi, 0);
538 while (rpmfiNext(fi) >= 0) {
539 val = rpmfiFColor(fi);
541 ndx = rpmfiFDepends(fi, &ddict);
545 mydt = ((ix >> 24) & 0xff);
547 /*@innercontinue@*/ continue;
555 /* Set color/refs values in dependency set. */
557 while ((i = rpmdsNext(ds)) >= 0) {
560 (void) rpmdsSetColor(ds, val);
564 (void) rpmdsSetRefs(ds, val);
568 int rpmtsiOc(rpmtsi tsi)
573 rpmtsi XrpmtsiFree(/*@only@*//*@null@*/ rpmtsi tsi,
574 const char * fn, unsigned int ln)
576 /* XXX watchout: a funky recursion segfaults here iff nrefs is wrong. */
579 tsi->ts = rpmtsFree(tsi->ts);
584 fprintf(stderr, "*** tsi %p -- %s:%d\n", tsi, fn, ln);
589 rpmtsi XrpmtsiInit(rpmts ts, const char * fn, unsigned int ln)
593 tsi = xcalloc(1, sizeof(*tsi));
594 tsi->ts = rpmtsLink(ts, "rpmtsi");
595 tsi->reverse = ((rpmtsFlags(ts) & RPMTRANS_FLAG_REVERSE) ? 1 : 0);
596 tsi->oc = (tsi->reverse ? (rpmtsNElements(ts) - 1) : 0);
597 tsi->ocsave = tsi->oc;
600 fprintf(stderr, "*** tsi %p ++ %s:%d\n", tsi, fn, ln);
606 * Return next transaction element.
607 * @param tsi transaction element iterator
608 * @return transaction element, NULL on termination
610 static /*@null@*/ /*@dependent@*/
611 rpmte rpmtsiNextElement(rpmtsi tsi)
617 if (tsi == NULL || tsi->ts == NULL || rpmtsNElements(tsi->ts) <= 0)
621 if (tsi->oc >= 0) oc = tsi->oc--;
623 if (tsi->oc < rpmtsNElements(tsi->ts)) oc = tsi->oc++;
628 te = rpmtsElement(tsi->ts, oc);
633 rpmte rpmtsiNext(rpmtsi tsi, rpmElementType type)
637 while ((te = rpmtsiNextElement(tsi)) != NULL) {
638 if (type == 0 || (te->type & type) != 0)