|
rpm
5.4.4
|
00001 00005 #include "system.h" 00006 00007 #include <rpmio.h> 00008 #include <rpmiotypes.h> /* XXX fnpyKey */ 00009 00010 #include <rpmtypes.h> 00011 #include <rpmtag.h> 00012 #include <rpmdb.h> /* rpmmiFoo */ 00013 #include <pkgio.h> /* rpmReadPackageFile */ 00014 00015 #include "rpmds.h" 00016 #define _RPMFI_INTERNAL /* pre/post trans scripts */ 00017 #include "rpmfi.h" 00018 00019 #define _RPMTE_INTERNAL 00020 #include "rpmte.h" 00021 #include "rpmts.h" 00022 00023 #include "debug.h" 00024 00025 /*@unchecked@*/ 00026 int _rpmte_debug = 0; 00027 00028 /*@access alKey @*/ 00029 /*@access rpmts @*/ /* XXX cast */ 00030 /*@access rpmtsi @*/ 00031 00032 void rpmteCleanDS(rpmte te) 00033 { 00034 te->PRCO = rpmdsFreePRCO(te->PRCO); 00035 } 00036 00041 static void delTE(rpmte p) 00042 /*@globals fileSystem @*/ 00043 /*@modifies p, fileSystem @*/ 00044 { 00045 p->relocs = rpmfiFreeRelocations(p->relocs); 00046 00047 rpmteCleanDS(p); 00048 00049 /*@-refcounttrans@*/ /* FIX: XfdFree annotation */ 00050 if (p->fd != NULL) 00051 p->fd = fdFree(p->fd, "delTE"); 00052 /*@=refcounttrans@*/ 00053 00054 p->os = _free(p->os); 00055 p->arch = _free(p->arch); 00056 p->epoch = _free(p->epoch); 00057 p->name = _free(p->name); 00058 p->version = _free(p->version); 00059 p->release = _free(p->release); 00060 #ifdef RPM_VENDOR_MANDRIVA 00061 p->distepoch = _free(p->distepoch); 00062 #endif 00063 p->NEVR = _free(p->NEVR); 00064 p->NEVRA = _free(p->NEVRA); 00065 p->pkgid = _free(p->pkgid); 00066 p->hdrid = _free(p->hdrid); 00067 p->sourcerpm = _free(p->sourcerpm); 00068 00069 p->replaced = _free(p->replaced); 00070 00071 p->flink.NEVRA = argvFree(p->flink.NEVRA); 00072 p->flink.Pkgid = argvFree(p->flink.Pkgid); 00073 p->flink.Hdrid = argvFree(p->flink.Hdrid); 00074 p->blink.NEVRA = argvFree(p->blink.NEVRA); 00075 p->blink.Pkgid = argvFree(p->blink.Pkgid); 00076 p->blink.Hdrid = argvFree(p->blink.Hdrid); 00077 00078 assert(p->txn == NULL); /* XXX FIXME */ 00079 p->txn = NULL; 00080 p->fi = rpmfiFree(p->fi); 00081 00082 (void)headerFree(p->h); 00083 p->h = NULL; 00084 00085 /*@-nullstate@*/ /* FIX: p->{NEVR,name} annotations */ 00086 return; 00087 /*@=nullstate@*/ 00088 } 00089 00098 static void addTE(rpmts ts, rpmte p, Header h, 00099 /*@dependent@*/ /*@null@*/ fnpyKey key, 00100 /*@null@*/ rpmRelocation relocs) 00101 /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/ 00102 /*@modifies ts, p, h, 00103 rpmGlobalMacroContext, fileSystem, internalState @*/ 00104 { 00105 int scareMem = 0; 00106 HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he)); 00107 int xx; 00108 00109 he->tag = RPMTAG_NVRA; 00110 xx = headerGet(h, he, 0); 00111 assert(he->p.str != NULL); 00112 p->NEVR = (xx ? he->p.str : xstrdup("?N-?V-?R.?A")); 00113 00114 he->tag = RPMTAG_NAME; 00115 xx = headerGet(h, he, 0); 00116 p->name = (xx ? he->p.str : xstrdup("?RPMTAG_NAME?")); 00117 he->tag = RPMTAG_VERSION; 00118 xx = headerGet(h, he, 0); 00119 p->version = (char *)(xx ? he->p.str : xstrdup("?RPMTAG_VERSION?")); 00120 he->tag = RPMTAG_RELEASE; 00121 xx = headerGet(h, he, 0); 00122 p->release = (char *)(xx ? he->p.str : xstrdup("?RPMTAG_RELEASE?")); 00123 00124 p->db_instance = 0; 00125 00126 he->tag = RPMTAG_PKGID; 00127 xx = headerGet(h, he, 0); 00128 if (he->p.ui8p != NULL) { 00129 static const char hex[] = "0123456789abcdef"; 00130 char * t; 00131 rpmuint32_t i; 00132 00133 p->pkgid = t = xmalloc((2*he->c) + 1); 00134 for (i = 0 ; i < he->c; i++) { 00135 *t++ = hex[ (unsigned)((he->p.ui8p[i] >> 4) & 0x0f) ]; 00136 *t++ = hex[ (unsigned)((he->p.ui8p[i] ) & 0x0f) ]; 00137 } 00138 *t = '\0'; 00139 he->p.ptr = _free(he->p.ptr); 00140 } else 00141 p->pkgid = NULL; 00142 00143 he->tag = RPMTAG_HDRID; 00144 xx = headerGet(h, he, 0); 00145 p->hdrid = (xx ? he->p.str : xstrdup("?RPMTAG_HDRID?")); 00146 00147 he->tag = RPMTAG_SOURCERPM; 00148 xx = headerGet(h, he, 0); 00149 p->sourcerpm = (xx ? he->p.str : NULL); 00150 00151 he->tag = RPMTAG_ARCH; 00152 xx = headerGet(h, he, 0); 00153 p->arch = (xx ? he->p.str : xstrdup("?RPMTAG_ARCH?")); 00154 00155 he->tag = RPMTAG_OS; 00156 xx = headerGet(h, he, 0); 00157 p->os = (xx ? he->p.str : xstrdup("?RPMTAG_OS?")); 00158 00159 p->isSource = 00160 (headerIsEntry(h, RPMTAG_SOURCERPM) == 0 && 00161 headerIsEntry(h, RPMTAG_ARCH) != 0); 00162 00163 p->NEVRA = xstrdup(p->NEVR); 00164 00165 he->tag = RPMTAG_EPOCH; 00166 xx = headerGet(h, he, 0); 00167 if (he->p.ui32p != NULL) { 00168 p->epoch = xmalloc(20); 00169 sprintf(p->epoch, "%u", he->p.ui32p[0]); 00170 he->p.ptr = _free(he->p.ptr); 00171 } else 00172 p->epoch = NULL; 00173 00174 #ifdef RPM_VENDOR_MANDRIVA 00175 he->tag = RPMTAG_DISTEPOCH; 00176 xx = headerGet(h, he, 0); 00177 if (he->p.str != NULL) { 00178 p->distepoch = (char*)(xx ? he->p.str : xstrdup("?RPMTAG_DISTEPOCH?")); 00179 } else 00180 p->distepoch = NULL; 00181 #endif 00182 00183 p->installed = 0; 00184 00185 p->relocs = rpmfiDupeRelocations(relocs, &p->nrelocs); 00186 p->autorelocatex = -1; 00187 00188 p->key = key; 00189 p->fd = NULL; 00190 00191 p->replaced = NULL; 00192 00193 p->pkgFileSize = 0; 00194 memset(p->originTid, 0, sizeof(p->originTid)); 00195 memset(p->originTime, 0, sizeof(p->originTime)); 00196 00197 p->PRCO = rpmdsNewPRCO(h); 00198 00199 { rpmte savep = rpmtsSetRelocateElement(ts, p); 00200 p->fi = rpmfiNew(ts, h, RPMTAG_BASENAMES, scareMem); 00201 (void) rpmtsSetRelocateElement(ts, savep); 00202 } 00203 p->txn = NULL; 00204 00205 rpmteColorDS(p, RPMTAG_PROVIDENAME); 00206 rpmteColorDS(p, RPMTAG_REQUIRENAME); 00207 /*@-compdef@*/ 00208 return; 00209 /*@=compdef@*/ 00210 } 00211 00212 static void rpmteFini(void * _te) 00213 /*@modifies _te @*/ 00214 { 00215 rpmte te = _te; 00216 00217 delTE(te); 00218 } 00219 00220 /*@unchecked@*/ /*@only@*/ /*@null@*/ 00221 rpmioPool _rpmtePool; 00222 00223 static rpmte rpmteGetPool(/*@null@*/ rpmioPool pool) 00224 /*@globals _rpmtePool, fileSystem, internalState @*/ 00225 /*@modifies pool, _rpmtePool, fileSystem, internalState @*/ 00226 { 00227 rpmte te; 00228 00229 if (_rpmtePool == NULL) { 00230 _rpmtePool = rpmioNewPool("te", sizeof(*te), -1, _rpmte_debug, 00231 NULL, NULL, rpmteFini); 00232 pool = _rpmtePool; 00233 } 00234 te = (rpmte) rpmioGetPool(pool, sizeof(*te)); 00235 memset(((char *)te)+sizeof(te->_item), 0, sizeof(*te)-sizeof(te->_item)); 00236 return te; 00237 } 00238 00239 rpmte rpmteNew(const rpmts ts, Header h, 00240 rpmElementType type, 00241 fnpyKey key, 00242 rpmRelocation relocs, 00243 uint32_t dboffset, 00244 alKey pkgKey) 00245 { 00246 HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he)); 00247 rpmte p = rpmteGetPool(_rpmtePool); 00248 int xx; 00249 00250 p->type = type; 00251 00252 addTE(ts, p, h, key, relocs); 00253 switch (type) { 00254 case TR_ADDED: 00255 p->u.addedKey = pkgKey; 00256 /* XXX 256 is only an estimate of signature header. */ 00257 p->pkgFileSize = 96 + 256; 00258 he->tag = RPMTAG_SIGSIZE; 00259 xx = headerGet(h, he, 0); 00260 if (xx && he->p.ui32p) 00261 p->pkgFileSize += *he->p.ui32p; 00262 he->p.ptr = _free(he->p.ptr); 00263 break; 00264 case TR_REMOVED: 00265 p->u.addedKey = pkgKey; 00266 p->u.removed.dboffset = dboffset; 00267 break; 00268 } 00269 return p; 00270 } 00271 00272 /* Get the DB Instance value */ 00273 uint32_t rpmteDBInstance(rpmte te) 00274 { 00275 return (te != NULL ? te->db_instance : 0); 00276 } 00277 00278 /* Set the DB Instance value */ 00279 void rpmteSetDBInstance(rpmte te, unsigned int instance) 00280 { 00281 if (te != NULL) 00282 te->db_instance = instance; 00283 } 00284 00285 Header rpmteHeader(rpmte te) 00286 { 00287 /*@-castexpose -retalias -retexpose @*/ 00288 return (te != NULL && te->h != NULL ? headerLink(te->h) : NULL); 00289 /*@=castexpose =retalias =retexpose @*/ 00290 } 00291 00292 Header rpmteSetHeader(rpmte te, Header h) 00293 { 00294 if (te != NULL) { 00295 (void)headerFree(te->h); 00296 te->h = NULL; 00297 /*@-assignexpose -castexpose @*/ 00298 if (h != NULL) 00299 te->h = headerLink(h); 00300 /*@=assignexpose =castexpose @*/ 00301 } 00302 return NULL; 00303 } 00304 00305 rpmElementType rpmteType(rpmte te) 00306 { 00307 return (te != NULL ? te->type : (rpmElementType)-1); 00308 } 00309 00310 const char * rpmteN(rpmte te) 00311 { 00312 return (te != NULL ? te->name : NULL); 00313 } 00314 00315 const char * rpmteE(rpmte te) 00316 { 00317 return (te != NULL ? te->epoch : NULL); 00318 } 00319 00320 const char * rpmteV(rpmte te) 00321 { 00322 return (te != NULL ? te->version : NULL); 00323 } 00324 00325 const char * rpmteR(rpmte te) 00326 { 00327 return (te != NULL ? te->release : NULL); 00328 } 00329 00330 const char * rpmteD(rpmte te) 00331 { 00332 #ifdef RPM_VENDOR_MANDRIVA 00333 return (te != NULL ? te->distepoch : NULL); 00334 #else 00335 return NULL; 00336 #endif 00337 } 00338 00339 const char * rpmteA(rpmte te) 00340 { 00341 return (te != NULL ? te->arch : NULL); 00342 } 00343 00344 const char * rpmteO(rpmte te) 00345 { 00346 return (te != NULL ? te->os : NULL); 00347 } 00348 00349 int rpmteIsSource(rpmte te) 00350 { 00351 return (te != NULL ? te->isSource : 0); 00352 } 00353 00354 rpmuint32_t rpmteColor(rpmte te) 00355 { 00356 return (te != NULL ? te->color : 0); 00357 } 00358 00359 rpmuint32_t rpmteSetColor(rpmte te, rpmuint32_t color) 00360 { 00361 int ocolor = 0; 00362 if (te != NULL) { 00363 ocolor = te->color; 00364 te->color = color; 00365 } 00366 return ocolor; 00367 } 00368 00369 rpmuint32_t rpmtePkgFileSize(rpmte te) 00370 { 00371 return (te != NULL ? te->pkgFileSize : 0); 00372 } 00373 00374 rpmuint32_t * rpmteOriginTid(rpmte te) 00375 { 00376 return te->originTid; 00377 } 00378 00379 rpmuint32_t * rpmteOriginTime(rpmte te) 00380 { 00381 return te->originTime; 00382 } 00383 00384 int rpmteDepth(rpmte te) 00385 { 00386 return (te != NULL ? te->depth : 0); 00387 } 00388 00389 int rpmteSetDepth(rpmte te, int ndepth) 00390 { 00391 int odepth = 0; 00392 if (te != NULL) { 00393 odepth = te->depth; 00394 te->depth = ndepth; 00395 } 00396 return odepth; 00397 } 00398 00399 int rpmteBreadth(rpmte te) 00400 { 00401 return (te != NULL ? te->depth : 0); 00402 } 00403 00404 int rpmteSetBreadth(rpmte te, int nbreadth) 00405 { 00406 int obreadth = 0; 00407 if (te != NULL) { 00408 obreadth = te->breadth; 00409 te->breadth = nbreadth; 00410 } 00411 return obreadth; 00412 } 00413 00414 int rpmteNpreds(rpmte te) 00415 { 00416 return (te != NULL ? te->npreds : 0); 00417 } 00418 00419 int rpmteSetNpreds(rpmte te, int npreds) 00420 { 00421 int opreds = 0; 00422 if (te != NULL) { 00423 opreds = te->npreds; 00424 te->npreds = npreds; 00425 } 00426 return opreds; 00427 } 00428 00429 int rpmteTree(rpmte te) 00430 { 00431 return (te != NULL ? te->tree : 0); 00432 } 00433 00434 int rpmteSetTree(rpmte te, int ntree) 00435 { 00436 int otree = 0; 00437 if (te != NULL) { 00438 otree = te->tree; 00439 te->tree = ntree; 00440 } 00441 return otree; 00442 } 00443 00444 rpmte rpmteParent(rpmte te) 00445 { 00446 return (te != NULL ? te->parent : NULL); 00447 } 00448 00449 rpmte rpmteSetParent(rpmte te, rpmte pte) 00450 { 00451 rpmte opte = NULL; 00452 if (te != NULL) { 00453 opte = te->parent; 00454 /*@-assignexpose -temptrans@*/ 00455 te->parent = pte; 00456 /*@=assignexpose =temptrans@*/ 00457 } 00458 return opte; 00459 } 00460 00461 int rpmteDegree(rpmte te) 00462 { 00463 return (te != NULL ? te->degree : 0); 00464 } 00465 00466 int rpmteSetDegree(rpmte te, int ndegree) 00467 { 00468 int odegree = 0; 00469 if (te != NULL) { 00470 odegree = te->degree; 00471 te->degree = ndegree; 00472 } 00473 return odegree; 00474 } 00475 00476 tsortInfo rpmteTSI(rpmte te) 00477 { 00478 /*@-compdef -retalias -retexpose -usereleased @*/ 00479 return te->tsi; 00480 /*@=compdef =retalias =retexpose =usereleased @*/ 00481 } 00482 00483 void rpmteFreeTSI(rpmte te) 00484 { 00485 if (te != NULL && rpmteTSI(te) != NULL) { 00486 tsortInfo tsi; 00487 00488 /* Clean up tsort remnants (if any). */ 00489 while ((tsi = rpmteTSI(te)->tsi_next) != NULL) { 00490 rpmteTSI(te)->tsi_next = tsi->tsi_next; 00491 tsi->tsi_next = NULL; 00492 tsi = _free(tsi); 00493 } 00494 te->tsi = _free(te->tsi); 00495 } 00496 /*@-nullstate@*/ /* FIX: te->tsi is NULL */ 00497 return; 00498 /*@=nullstate@*/ 00499 } 00500 00501 void rpmteNewTSI(rpmte te) 00502 { 00503 if (te != NULL) { 00504 rpmteFreeTSI(te); 00505 te->tsi = xcalloc(1, sizeof(*te->tsi)); 00506 } 00507 } 00508 00509 alKey rpmteAddedKey(rpmte te) 00510 { 00511 return (te != NULL ? te->u.addedKey : RPMAL_NOMATCH); 00512 } 00513 00514 alKey rpmteSetAddedKey(rpmte te, alKey npkgKey) 00515 { 00516 alKey opkgKey = RPMAL_NOMATCH; 00517 if (te != NULL) { 00518 opkgKey = te->u.addedKey; 00519 te->u.addedKey = npkgKey; 00520 } 00521 return opkgKey; 00522 } 00523 00524 00525 int rpmteDBOffset(rpmte te) 00526 { 00527 return (te != NULL ? te->u.removed.dboffset : 0); 00528 } 00529 00530 const char * rpmteNEVR(rpmte te) 00531 { 00532 return (te != NULL ? te->NEVR : NULL); 00533 } 00534 00535 const char * rpmteNEVRA(rpmte te) 00536 { 00537 return (te != NULL ? te->NEVRA : NULL); 00538 } 00539 00540 const char * rpmtePkgid(rpmte te) 00541 { 00542 return (te != NULL ? te->pkgid : NULL); 00543 } 00544 00545 const char * rpmteHdrid(rpmte te) 00546 { 00547 return (te != NULL ? te->hdrid : NULL); 00548 } 00549 00550 const char * rpmteSourcerpm(rpmte te) 00551 { 00552 return (te != NULL ? te->sourcerpm : NULL); 00553 } 00554 00555 FD_t rpmteFd(rpmte te) 00556 { 00557 /*@-compdef -refcounttrans -retalias -retexpose -usereleased @*/ 00558 return (te != NULL ? te->fd : NULL); 00559 /*@=compdef =refcounttrans =retalias =retexpose =usereleased @*/ 00560 } 00561 00562 fnpyKey rpmteKey(rpmte te) 00563 { 00564 return (te != NULL ? te->key : NULL); 00565 } 00566 00567 rpmds rpmteDS(rpmte te, rpmTag tag) 00568 { 00569 return (te != NULL ? rpmdsFromPRCO(te->PRCO, tag) : NULL); 00570 } 00571 00572 #ifdef REFERENCE 00573 rpmfi rpmteFI(rpmte te) 00574 { 00575 if (te == NULL) 00576 return NULL; 00577 00578 return te->fi; /* XXX take fi reference here? */ 00579 } 00580 #else 00581 rpmfi rpmteFI(rpmte te, rpmTag tag) 00582 { 00583 /*@-compdef -refcounttrans -retalias -retexpose -usereleased @*/ 00584 if (te == NULL) 00585 return NULL; 00586 00587 if (tag == RPMTAG_BASENAMES) 00588 return te->fi; 00589 else 00590 return NULL; 00591 /*@=compdef =refcounttrans =retalias =retexpose =usereleased @*/ 00592 } 00593 #endif 00594 00595 rpmfi rpmteSetFI(rpmte te, rpmfi fi) 00596 { 00597 if (te != NULL) { 00598 te->fi = rpmfiFree(te->fi); 00599 /*@-assignexpose -castexpose @*/ 00600 if (fi != NULL) 00601 te->fi = rpmfiLink(fi, __FUNCTION__); 00602 /*@=assignexpose =castexpose @*/ 00603 } 00604 return NULL; 00605 } 00606 00607 void rpmteColorDS(rpmte te, rpmTag tag) 00608 { 00609 rpmfi fi = rpmteFI(te, RPMTAG_BASENAMES); 00610 rpmds ds = rpmteDS(te, tag); 00611 char deptype = 'R'; 00612 char mydt; 00613 const rpmuint32_t * ddict; 00614 rpmuint32_t * colors; 00615 rpmuint32_t * refs; 00616 rpmuint32_t val; 00617 int Count; 00618 size_t nb; 00619 unsigned ix; 00620 int ndx, i; 00621 00622 if (!(te && (Count = rpmdsCount(ds)) > 0 && rpmfiFC(fi) > 0)) 00623 return; 00624 00625 switch (tag) { 00626 default: 00627 return; 00628 /*@notreached@*/ break; 00629 case RPMTAG_PROVIDENAME: 00630 deptype = 'P'; 00631 break; 00632 case RPMTAG_REQUIRENAME: 00633 deptype = 'R'; 00634 break; 00635 } 00636 00637 nb = Count * sizeof(*colors); 00638 colors = memset(alloca(nb), 0, nb); 00639 nb = Count * sizeof(*refs); 00640 refs = memset(alloca(nb), -1, nb); 00641 00642 /* Calculate dependency color and reference count. */ 00643 fi = rpmfiInit(fi, 0); 00644 if (fi != NULL) 00645 while (rpmfiNext(fi) >= 0) { 00646 val = rpmfiFColor(fi); 00647 ddict = NULL; 00648 ndx = rpmfiFDepends(fi, &ddict); 00649 if (ddict != NULL) 00650 while (ndx-- > 0) { 00651 ix = *ddict++; 00652 mydt = (char)((ix >> 24) & 0xff); 00653 if (mydt != deptype) 00654 /*@innercontinue@*/ continue; 00655 ix &= 0x00ffffff; 00656 assert ((int)ix < Count); 00657 colors[ix] |= val; 00658 refs[ix]++; 00659 } 00660 } 00661 00662 /* Set color/refs values in dependency set. */ 00663 ds = rpmdsInit(ds); 00664 while ((i = rpmdsNext(ds)) >= 0) { 00665 val = colors[i]; 00666 te->color |= val; 00667 (void) rpmdsSetColor(ds, val); 00668 val = refs[i]; 00669 (void) rpmdsSetRefs(ds, val); 00670 } 00671 } 00672 00673 /*@unchecked@*/ 00674 static int __mydebug = 0; 00675 00676 int rpmteChain(rpmte p, rpmte q, Header oh, const char * msg) 00677 { 00678 HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he)); 00679 const char * blinkNEVRA = NULL; 00680 const char * blinkPkgid = NULL; 00681 const char * blinkHdrid = NULL; 00682 int xx; 00683 00684 if (msg == NULL) 00685 msg = ""; 00686 he->tag = RPMTAG_NVRA; 00687 xx = headerGet(oh, he, 0); 00688 assert(he->p.str != NULL); 00689 blinkNEVRA = he->p.str; 00690 00691 /* 00692 * Convert binary pkgid to a string. 00693 * XXX Yum's borken conception of a "header" doesn't have signature 00694 * tags appended. 00695 */ 00696 he->tag = RPMTAG_PKGID; 00697 xx = headerGet(oh, he, 0); 00698 if (xx && he->p.ui8p != NULL) { 00699 static const char hex[] = "0123456789abcdef"; 00700 char * t; 00701 rpmuint32_t i; 00702 00703 blinkPkgid = t = xmalloc((2*he->c) + 1); 00704 for (i = 0 ; i < he->c; i++) { 00705 *t++ = hex[ ((he->p.ui8p[i] >> 4) & 0x0f) ]; 00706 *t++ = hex[ ((he->p.ui8p[i] ) & 0x0f) ]; 00707 } 00708 *t = '\0'; 00709 he->p.ptr = _free(he->p.ptr); 00710 } else 00711 blinkPkgid = NULL; 00712 00713 he->tag = RPMTAG_HDRID; 00714 xx = headerGet(oh, he, 0); 00715 blinkHdrid = he->p.str; 00716 00717 /*@-modfilesys@*/ 00718 if (__mydebug) 00719 fprintf(stderr, "%s argvAdd(&q->flink.NEVRA, \"%s\")\n", msg, p->NEVRA); 00720 xx = argvAdd(&q->flink.NEVRA, p->NEVRA); 00721 if (__mydebug) 00722 fprintf(stderr, "%s argvAdd(&p->blink.NEVRA, \"%s\")\n", msg, blinkNEVRA); 00723 xx = argvAdd(&p->blink.NEVRA, blinkNEVRA); 00724 if (__mydebug) 00725 fprintf(stderr, "%s argvAdd(&q->flink.Pkgid, \"%s\")\n", msg, p->pkgid); 00726 if (p->pkgid != NULL) 00727 xx = argvAdd(&q->flink.Pkgid, p->pkgid); 00728 if (__mydebug) 00729 fprintf(stderr, "%s argvAdd(&p->blink.Pkgid, \"%s\")\n", msg, blinkPkgid); 00730 if (blinkPkgid != NULL) 00731 xx = argvAdd(&p->blink.Pkgid, blinkPkgid); 00732 if (__mydebug) 00733 fprintf(stderr, "%s argvAdd(&q->flink.Hdrid, \"%s\")\n", msg, p->hdrid); 00734 if (p->hdrid != NULL) 00735 xx = argvAdd(&q->flink.Hdrid, p->hdrid); 00736 if (__mydebug) 00737 fprintf(stderr, "%s argvAdd(&p->blink.Hdrid, \"%s\")\n", msg, blinkHdrid); 00738 if (blinkHdrid != NULL) 00739 xx = argvAdd(&p->blink.Hdrid, blinkHdrid); 00740 /*@=modfilesys@*/ 00741 00742 blinkNEVRA = _free(blinkNEVRA); 00743 blinkPkgid = _free(blinkPkgid); 00744 blinkHdrid = _free(blinkHdrid); 00745 00746 return 0; 00747 } 00748 00749 int rpmtsiOc(rpmtsi tsi) 00750 { 00751 return tsi->ocsave; 00752 } 00753 00754 /*@-mustmod@*/ 00755 static void rpmtsiFini(void * _tsi) 00756 /*@modifies _tsi @*/ 00757 { 00758 rpmtsi tsi = _tsi; 00759 /*@-internalglobs@*/ 00760 (void)rpmtsFree(tsi->ts); 00761 tsi->ts = NULL; 00762 /*@=internalglobs@*/ 00763 } 00764 /*@=mustmod@*/ 00765 00766 /*@unchecked@*/ /*@only@*/ /*@null@*/ 00767 rpmioPool _rpmtsiPool; 00768 00769 static rpmtsi rpmtsiGetPool(/*@null@*/ rpmioPool pool) 00770 /*@globals _rpmtsiPool, fileSystem, internalState @*/ 00771 /*@modifies pool, _rpmtsiPool, fileSystem, internalState @*/ 00772 { 00773 rpmtsi tsi; 00774 00775 if (_rpmtsiPool == NULL) { 00776 _rpmtsiPool = rpmioNewPool("tsi", sizeof(*tsi), -1, _rpmte_debug, 00777 NULL, NULL, rpmtsiFini);/* XXX _rpmtsi_debug? */ 00778 pool = _rpmtsiPool; 00779 } 00780 tsi = (rpmtsi) rpmioGetPool(pool, sizeof(*tsi)); 00781 memset(((char *)tsi)+sizeof(tsi->_item), 0, sizeof(*tsi)-sizeof(tsi->_item)); 00782 return tsi; 00783 } 00784 00785 rpmtsi XrpmtsiInit(rpmts ts, const char * fn, unsigned int ln) 00786 { 00787 rpmtsi tsi = rpmtsiGetPool(_rpmtsiPool); 00788 00789 /*@-assignexpose -castexpose @*/ 00790 tsi->ts = rpmtsLink(ts, "rpmtsi"); 00791 /*@=assignexpose =castexpose @*/ 00792 tsi->reverse = 0; 00793 tsi->oc = (tsi->reverse ? (rpmtsNElements(ts) - 1) : 0); 00794 tsi->ocsave = tsi->oc; 00795 00796 return (rpmtsi) rpmioLinkPoolItem((rpmioItem)tsi, "rpmtsiInit", fn, ln); 00797 } 00798 00804 static /*@null@*/ /*@dependent@*/ 00805 rpmte rpmtsiNextElement(rpmtsi tsi) 00806 /*@modifies tsi @*/ 00807 { 00808 rpmte te = NULL; 00809 int oc = -1; 00810 00811 if (tsi == NULL || tsi->ts == NULL || rpmtsNElements(tsi->ts) <= 0) 00812 return te; 00813 00814 if (tsi->reverse) { 00815 if (tsi->oc >= 0) oc = tsi->oc--; 00816 } else { 00817 if (tsi->oc < rpmtsNElements(tsi->ts)) oc = tsi->oc++; 00818 } 00819 tsi->ocsave = oc; 00820 if (oc != -1) 00821 te = rpmtsElement(tsi->ts, oc); 00822 return te; 00823 } 00824 00825 rpmte rpmtsiNext(rpmtsi tsi, rpmElementType type) 00826 { 00827 rpmte te; 00828 00829 while ((te = rpmtsiNextElement(tsi)) != NULL) { 00830 if (type == 0 || (te->type & type) != 0) 00831 break; 00832 } 00833 return te; 00834 } 00835 00836 /*@-mods@*/ 00837 Header rpmteDBHeader(rpmts ts, uint32_t rec) 00838 { 00839 rpmmi mi = rpmtsInitIterator(ts, RPMDBI_PACKAGES, &rec, sizeof(rec)); 00840 Header h; 00841 00842 /* iterator returns weak refs, grab hold of header */ 00843 if ((h = rpmmiNext(mi)) != NULL) 00844 h = headerLink(h); 00845 mi = rpmmiFree(mi); 00846 return h; 00847 } 00848 /*@=mods@*/ 00849 00850 Header rpmteFDHeader(rpmts ts, rpmte te) 00851 { 00852 Header h = NULL; 00853 te->fd = rpmtsNotify(ts, te, RPMCALLBACK_INST_OPEN_FILE, 0, 0); 00854 if (te->fd != NULL) { 00855 rpmVSFlags ovsflags; 00856 rpmRC pkgrc; 00857 00858 ovsflags = rpmtsSetVSFlags(ts, rpmtsVSFlags(ts) | RPMVSF_NEEDPAYLOAD); 00859 pkgrc = rpmReadPackageFile(ts, rpmteFd(te), rpmteNEVR(te), &h); 00860 ovsflags = rpmtsSetVSFlags(ts, ovsflags); 00861 switch (pkgrc) { 00862 default: 00863 (void) rpmteClose(te, ts, 1); 00864 break; 00865 case RPMRC_NOTTRUSTED: 00866 case RPMRC_NOKEY: 00867 case RPMRC_OK: 00868 break; 00869 } 00870 } 00871 return h; 00872 } 00873 00874 /*@-mods@*/ 00875 int rpmteOpen(rpmte te, rpmts ts, int reload_fi) 00876 { 00877 Header h = NULL; 00878 uint32_t instance; 00879 int rc = 0; /* assume failure */ 00880 00881 if (te == NULL || ts == NULL) 00882 goto exit; 00883 00884 instance = rpmteDBInstance(te); 00885 (void) rpmteSetHeader(te, NULL); 00886 00887 switch (rpmteType(te)) { 00888 case TR_ADDED: 00889 h = instance ? rpmteDBHeader(ts, instance) : rpmteFDHeader(ts, te); 00890 break; 00891 case TR_REMOVED: 00892 h = rpmteDBHeader(ts, instance); 00893 break; 00894 } 00895 if (h != NULL) { 00896 #ifdef REFERENCE 00897 if (reload_fi) { 00898 te->fi = getFI(te, ts, h); 00899 } 00900 #else 00901 if (reload_fi) { 00902 static int scareMem = 0; 00903 te->fi = rpmfiNew(ts, h, RPMTAG_BASENAMES, scareMem); 00904 } 00905 #endif 00906 00907 (void) rpmteSetHeader(te, h); 00908 h = headerFree(h); 00909 rc = 1; 00910 } 00911 00912 exit: 00913 return rc; 00914 } 00915 /*@=mods@*/ 00916 00917 int rpmteClose(rpmte te, rpmts ts, int reset_fi) 00918 { 00919 if (te == NULL || ts == NULL) 00920 return 0; 00921 00922 switch (te->type) { 00923 case TR_ADDED: 00924 if (te->fd != NULL) { 00925 void * ptr; 00926 ptr = rpmtsNotify(ts, te, RPMCALLBACK_INST_CLOSE_FILE, 0, 0); 00927 te->fd = NULL; 00928 } 00929 break; 00930 case TR_REMOVED: 00931 /* eventually we'll want notifications for erase open too */ 00932 break; 00933 } 00934 (void) rpmteSetHeader(te, NULL); 00935 if (reset_fi) 00936 (void) rpmteSetFI(te, NULL); 00937 return 1; 00938 } 00939 00940 int rpmteFailed(rpmte te) 00941 { 00942 return (te != NULL) ? te->linkFailed : -1; 00943 } 00944 00945 int rpmteHaveTransScript(rpmte te, rpmTag tag) 00946 { 00947 rpmfi fi = (te ? te->fi : NULL); 00948 int rc = 0; 00949 00950 switch (tag) { 00951 default: 00952 break; 00953 case RPMTAG_PRETRANS: 00954 if (fi) 00955 rc = (fi->pretrans || fi->pretransprog) ? 1 : 0; 00956 break; 00957 case RPMTAG_POSTTRANS: 00958 if (fi) 00959 rc = (fi->posttrans || fi->posttransprog) ? 1 : 0; 00960 break; 00961 } 00962 return rc; 00963 } 00964 00965 #ifdef REFERENCE 00966 int rpmteMarkFailed(rpmte te, rpmts ts) 00967 { 00968 rpmtsi pi = rpmtsiInit(ts); 00969 int rc = 0; 00970 rpmte p; 00971 00972 te->failed = 1; 00973 /* XXX we can do a much better here than this... */ 00974 while ((p = rpmtsiNext(pi, TR_REMOVED))) { 00975 if (rpmteDependsOn(p) == te) { 00976 p->failed = 1; 00977 } 00978 } 00979 rpmtsiFree(pi); 00980 return rc; 00981 } 00982 00983 rpmps rpmteProblems(rpmte te) 00984 { 00985 return te ? te->probs : NULL; 00986 } 00987 00988 rpmfs rpmteGetFileStates(rpmte te) { 00989 return te->fs; 00990 } 00991 00992 rpmfs rpmfsNew(unsigned int fc, rpmElementType type) { 00993 rpmfs fs = xmalloc(sizeof(*fs)); 00994 fs->fc = fc; 00995 fs->replaced = NULL; 00996 fs->states = NULL; 00997 if (type == TR_ADDED) { 00998 fs->states = xmalloc(sizeof(*fs->states) * fs->fc); 00999 memset(fs->states, RPMFILE_STATE_NORMAL, fs->fc); 01000 } 01001 fs->actions = xmalloc(fc * sizeof(*fs->actions)); 01002 memset(fs->actions, FA_UNKNOWN, fc * sizeof(*fs->actions)); 01003 fs->numReplaced = fs->allocatedReplaced = 0; 01004 return fs; 01005 } 01006 01007 rpmfs rpmfsFree(rpmfs fs) { 01008 fs->replaced = _free(fs->replaced); 01009 fs->states = _free(fs->states); 01010 fs->actions = _free(fs->actions); 01011 01012 fs = _free(fs); 01013 return fs; 01014 } 01015 01016 rpm_count_t rpmfsFC(rpmfs fs) { 01017 return fs->fc; 01018 } 01019 01020 void rpmfsAddReplaced(rpmfs fs, int pkgFileNum, int otherPkg, int otherFileNum) 01021 { 01022 if (!fs->replaced) { 01023 fs->replaced = xcalloc(3, sizeof(*fs->replaced)); 01024 fs->allocatedReplaced = 3; 01025 } 01026 if (fs->numReplaced>=fs->allocatedReplaced) { 01027 fs->allocatedReplaced += (fs->allocatedReplaced>>1) + 2; 01028 fs->replaced = xrealloc(fs->replaced, fs->allocatedReplaced*sizeof(*fs->replaced)); 01029 } 01030 fs->replaced[fs->numReplaced].pkgFileNum = pkgFileNum; 01031 fs->replaced[fs->numReplaced].otherPkg = otherPkg; 01032 fs->replaced[fs->numReplaced].otherFileNum = otherFileNum; 01033 01034 fs->numReplaced++; 01035 } 01036 01037 sharedFileInfo rpmfsGetReplaced(rpmfs fs) 01038 { 01039 if (fs && fs->numReplaced) 01040 return fs->replaced; 01041 else 01042 return NULL; 01043 } 01044 01045 sharedFileInfo rpmfsNextReplaced(rpmfs fs , sharedFileInfo replaced) 01046 { 01047 if (fs && replaced) { 01048 replaced++; 01049 if (replaced - fs->replaced < fs->numReplaced) 01050 return replaced; 01051 } 01052 return NULL; 01053 } 01054 01055 void rpmfsSetState(rpmfs fs, unsigned int ix, rpmfileState state) 01056 { 01057 assert(ix < fs->fc); 01058 fs->states[ix] = state; 01059 } 01060 01061 rpmfileState rpmfsGetState(rpmfs fs, unsigned int ix) 01062 { 01063 assert(ix < fs->fc); 01064 if (fs->states) return fs->states[ix]; 01065 return RPMFILE_STATE_MISSING; 01066 } 01067 01068 rpm_fstate_t * rpmfsGetStates(rpmfs fs) 01069 { 01070 return fs->states; 01071 } 01072 01073 rpmFileAction rpmfsGetAction(rpmfs fs, unsigned int ix) 01074 { 01075 rpmFileAction action; 01076 if (fs->actions != NULL && ix < fs->fc) { 01077 action = fs->actions[ix]; 01078 } else { 01079 action = FA_UNKNOWN; 01080 } 01081 return action; 01082 } 01083 01084 void rpmfsSetAction(rpmfs fs, unsigned int ix, rpmFileAction action) 01085 { 01086 if (fs->actions != NULL && ix < fs->fc) { 01087 fs->actions[ix] = action; 01088 } 01089 } 01090 #endif /* REFERENCE */
1.7.5.1