00001
00006 #include "system.h"
00007
00008 #include <rpmio_internal.h>
00009 #include <rpmlib.h>
00010
00011 #include "cpio.h"
00012 #include "fsm.h"
00013
00014 #include "rpmds.h"
00015
00016 #define _RPMFI_INTERNAL
00017 #include "rpmfi.h"
00018
00019 #define _RPMTE_INTERNAL
00020 #include "rpmte.h"
00021 #include "rpmts.h"
00022
00023 #include "misc.h"
00024 #include "rpmmacro.h"
00025
00026 #include "debug.h"
00027
00028
00029
00030
00031 int _rpmfi_debug = 0;
00032
00033 rpmfi XrpmfiUnlink(rpmfi fi, const char * msg, const char * fn, unsigned ln)
00034 {
00035 if (fi == NULL) return NULL;
00036
00037 if (_rpmfi_debug && msg != NULL)
00038 fprintf(stderr, "--> fi %p -- %d %s at %s:%u\n", fi, fi->nrefs, msg, fn, ln);
00039
00040 fi->nrefs--;
00041 return NULL;
00042 }
00043
00044 rpmfi XrpmfiLink(rpmfi fi, const char * msg, const char * fn, unsigned ln)
00045 {
00046 if (fi == NULL) return NULL;
00047 fi->nrefs++;
00048
00049 if (_rpmfi_debug && msg != NULL)
00050 fprintf(stderr, "--> fi %p ++ %d %s at %s:%u\n", fi, fi->nrefs, msg, fn, ln);
00051
00052 return fi;
00053 }
00054
00055 int rpmfiFC(rpmfi fi)
00056 {
00057 return (fi != NULL ? fi->fc : 0);
00058 }
00059
00060 int rpmfiDC(rpmfi fi)
00061 {
00062 return (fi != NULL ? fi->dc : 0);
00063 }
00064
00065 #ifdef NOTYET
00066 int rpmfiDI(rpmfi fi)
00067 {
00068 }
00069 #endif
00070
00071 int rpmfiFX(rpmfi fi)
00072 {
00073 return (fi != NULL ? fi->i : -1);
00074 }
00075
00076 int rpmfiSetFX(rpmfi fi, int fx)
00077 {
00078 int i = -1;
00079
00080 if (fi != NULL && fx >= 0 && fx < fi->fc) {
00081 i = fi->i;
00082 fi->i = fx;
00083
00084 fi->j = fi->dil[fi->i];
00085
00086 }
00087 return i;
00088 }
00089
00090 int rpmfiDX(rpmfi fi)
00091 {
00092 return (fi != NULL ? fi->j : -1);
00093 }
00094
00095 int rpmfiSetDX(rpmfi fi, int dx)
00096 {
00097 int j = -1;
00098
00099 if (fi != NULL && dx >= 0 && dx < fi->dc) {
00100 j = fi->j;
00101 fi->j = dx;
00102 }
00103 return j;
00104 }
00105
00106 const char * rpmfiBN(rpmfi fi)
00107 {
00108 const char * BN = NULL;
00109
00110 if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
00111
00112 if (fi->bnl != NULL)
00113 BN = fi->bnl[fi->i];
00114
00115 }
00116 return BN;
00117 }
00118
00119 const char * rpmfiDN(rpmfi fi)
00120 {
00121 const char * DN = NULL;
00122
00123 if (fi != NULL && fi->j >= 0 && fi->j < fi->dc) {
00124
00125 if (fi->dnl != NULL)
00126 DN = fi->dnl[fi->j];
00127
00128 }
00129 return DN;
00130 }
00131
00132 const char * rpmfiFN(rpmfi fi)
00133 {
00134 const char * FN = "";
00135
00136
00137 if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
00138 char * t;
00139 if (fi->fn == NULL)
00140 fi->fn = xmalloc(fi->fnlen);
00141 FN = t = fi->fn;
00142
00143 *t = '\0';
00144 t = stpcpy(t, fi->dnl[fi->dil[fi->i]]);
00145 t = stpcpy(t, fi->bnl[fi->i]);
00146
00147 }
00148
00149 return FN;
00150 }
00151
00152 int_32 rpmfiFFlags(rpmfi fi)
00153 {
00154 int_32 FFlags = 0;
00155
00156 if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
00157
00158 if (fi->fflags != NULL)
00159 FFlags = fi->fflags[fi->i];
00160
00161 }
00162 return FFlags;
00163 }
00164
00165 int_32 rpmfiVFlags(rpmfi fi)
00166 {
00167 int_32 VFlags = 0;
00168
00169 if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
00170
00171 if (fi->vflags != NULL)
00172 VFlags = fi->vflags[fi->i];
00173
00174 }
00175 return VFlags;
00176 }
00177
00178 int_16 rpmfiFMode(rpmfi fi)
00179 {
00180 int_16 fmode = 0;
00181
00182 if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
00183
00184 if (fi->fmodes != NULL)
00185 fmode = fi->fmodes[fi->i];
00186
00187 }
00188 return fmode;
00189 }
00190
00191 rpmfileState rpmfiFState(rpmfi fi)
00192 {
00193 rpmfileState fstate = RPMFILE_STATE_MISSING;
00194
00195 if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
00196
00197 if (fi->fstates != NULL)
00198 fstate = fi->fstates[fi->i];
00199
00200 }
00201 return fstate;
00202 }
00203
00204 const unsigned char * rpmfiMD5(rpmfi fi)
00205 {
00206 unsigned char * MD5 = NULL;
00207
00208 if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
00209
00210 if (fi->md5s != NULL)
00211 MD5 = fi->md5s + (16 * fi->i);
00212
00213 }
00214 return MD5;
00215 }
00216
00217 const char * rpmfiFLink(rpmfi fi)
00218 {
00219 const char * flink = NULL;
00220
00221 if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
00222
00223 if (fi->flinks != NULL)
00224 flink = fi->flinks[fi->i];
00225
00226 }
00227 return flink;
00228 }
00229
00230 int_32 rpmfiFSize(rpmfi fi)
00231 {
00232 int_32 fsize = 0;
00233
00234 if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
00235
00236 if (fi->fsizes != NULL)
00237 fsize = fi->fsizes[fi->i];
00238
00239 }
00240 return fsize;
00241 }
00242
00243 int_16 rpmfiFRdev(rpmfi fi)
00244 {
00245 int_16 frdev = 0;
00246
00247 if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
00248
00249 if (fi->frdevs != NULL)
00250 frdev = fi->frdevs[fi->i];
00251
00252 }
00253 return frdev;
00254 }
00255
00256 int_32 rpmfiFInode(rpmfi fi)
00257 {
00258 int_32 finode = 0;
00259
00260 if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
00261
00262 if (fi->finodes != NULL)
00263 finode = fi->finodes[fi->i];
00264
00265 }
00266 return finode;
00267 }
00268
00269 uint_32 rpmfiColor(rpmfi fi)
00270 {
00271 uint_32 color = 0;
00272
00273 if (fi != NULL)
00274
00275 color = fi->color & 0xf;
00276 return color;
00277 }
00278
00279 uint_32 rpmfiFColor(rpmfi fi)
00280 {
00281 uint_32 fcolor = 0;
00282
00283 if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
00284
00285 if (fi->fcolors != NULL)
00286
00287 fcolor = (fi->fcolors[fi->i] & 0x0f);
00288
00289 }
00290 return fcolor;
00291 }
00292
00293 const char * rpmfiFClass(rpmfi fi)
00294 {
00295 const char * fclass = NULL;
00296 int cdictx;
00297
00298 if (fi != NULL && fi->fcdictx != NULL && fi->i >= 0 && fi->i < fi->fc) {
00299
00300 cdictx = fi->fcdictx[fi->i];
00301 if (fi->cdict != NULL && cdictx >= 0 && cdictx < fi->ncdict)
00302 fclass = fi->cdict[cdictx];
00303
00304 }
00305 return fclass;
00306 }
00307
00308 int_32 rpmfiFDepends(rpmfi fi, const int_32 ** fddictp)
00309 {
00310 int fddictx = -1;
00311 int fddictn = 0;
00312 const int_32 * fddict = NULL;
00313
00314 if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
00315
00316 if (fi->fddictn != NULL)
00317 fddictn = fi->fddictn[fi->i];
00318 if (fddictn > 0 && fi->fddictx != NULL)
00319 fddictx = fi->fddictx[fi->i];
00320 if (fi->ddict != NULL && fddictx >= 0 && (fddictx+fddictn) <= fi->nddict)
00321 fddict = fi->ddict + fddictx;
00322
00323 }
00324
00325 if (fddictp)
00326 *fddictp = fddict;
00327
00328 return fddictn;
00329 }
00330
00331 int_32 rpmfiFNlink(rpmfi fi)
00332 {
00333 int_32 nlink = 0;
00334
00335 if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
00336
00337
00338 if (fi->finodes && fi->frdevs) {
00339 int_32 finode = fi->finodes[fi->i];
00340 int_16 frdev = fi->frdevs[fi->i];
00341 int j;
00342
00343 for (j = 0; j < fi->fc; j++) {
00344 if (fi->frdevs[j] == frdev && fi->finodes[j] == finode)
00345 nlink++;
00346 }
00347 }
00348
00349 }
00350 return nlink;
00351 }
00352
00353 int_32 rpmfiFMtime(rpmfi fi)
00354 {
00355 int_32 fmtime = 0;
00356
00357 if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
00358
00359 if (fi->fmtimes != NULL)
00360 fmtime = fi->fmtimes[fi->i];
00361
00362 }
00363 return fmtime;
00364 }
00365
00366 const char * rpmfiFUser(rpmfi fi)
00367 {
00368 const char * fuser = NULL;
00369
00370
00371 if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
00372
00373 if (fi->fuser != NULL)
00374 fuser = fi->fuser[fi->i];
00375
00376 }
00377 return fuser;
00378 }
00379
00380 const char * rpmfiFGroup(rpmfi fi)
00381 {
00382 const char * fgroup = NULL;
00383
00384
00385 if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
00386
00387 if (fi->fgroup != NULL)
00388 fgroup = fi->fgroup[fi->i];
00389
00390 }
00391 return fgroup;
00392 }
00393
00394 int rpmfiNext(rpmfi fi)
00395 {
00396 int i = -1;
00397
00398 if (fi != NULL && ++fi->i >= 0) {
00399 if (fi->i < fi->fc) {
00400 i = fi->i;
00401
00402 if (fi->dil != NULL)
00403 fi->j = fi->dil[fi->i];
00404
00405 } else
00406 fi->i = -1;
00407
00408
00409 if (_rpmfi_debug < 0 && i != -1)
00410 fprintf(stderr, "*** fi %p\t%s[%d] %s%s\n", fi, (fi->Type ? fi->Type : "?Type?"), i, (i >= 0 ? fi->dnl[fi->j] : ""), (i >= 0 ? fi->bnl[fi->i] : ""));
00411
00412
00413 }
00414
00415 return i;
00416 }
00417
00418 rpmfi rpmfiInit(rpmfi fi, int fx)
00419 {
00420 if (fi != NULL) {
00421 if (fx >= 0 && fx < fi->fc) {
00422 fi->i = fx - 1;
00423 fi->j = -1;
00424 }
00425 }
00426
00427
00428 return fi;
00429
00430 }
00431
00432 int rpmfiNextD(rpmfi fi)
00433 {
00434 int j = -1;
00435
00436 if (fi != NULL && ++fi->j >= 0) {
00437 if (fi->j < fi->dc)
00438 j = fi->j;
00439 else
00440 fi->j = -1;
00441
00442
00443 if (_rpmfi_debug < 0 && j != -1)
00444 fprintf(stderr, "*** fi %p\t%s[%d]\n", fi, (fi->Type ? fi->Type : "?Type?"), j);
00445
00446
00447 }
00448
00449 return j;
00450 }
00451
00452 rpmfi rpmfiInitD(rpmfi fi, int dx)
00453 {
00454 if (fi != NULL) {
00455 if (dx >= 0 && dx < fi->fc)
00456 fi->j = dx - 1;
00457 else
00458 fi = NULL;
00459 }
00460
00461
00462 return fi;
00463
00464 }
00465
00471 static
00472 const char *const ftstring (fileTypes ft)
00473
00474 {
00475 switch (ft) {
00476 case XDIR: return "directory";
00477 case CDEV: return "char dev";
00478 case BDEV: return "block dev";
00479 case LINK: return "link";
00480 case SOCK: return "sock";
00481 case PIPE: return "fifo/pipe";
00482 case REG: return "file";
00483 default: return "unknown file type";
00484 }
00485
00486 }
00487
00488 fileTypes whatis(uint_16 mode)
00489 {
00490 if (S_ISDIR(mode)) return XDIR;
00491 if (S_ISCHR(mode)) return CDEV;
00492 if (S_ISBLK(mode)) return BDEV;
00493 if (S_ISLNK(mode)) return LINK;
00494
00495 if (S_ISSOCK(mode)) return SOCK;
00496
00497 if (S_ISFIFO(mode)) return PIPE;
00498 return REG;
00499 }
00500
00501
00502 int rpmfiCompare(const rpmfi afi, const rpmfi bfi)
00503
00504 {
00505 fileTypes awhat = whatis(rpmfiFMode(afi));
00506 fileTypes bwhat = whatis(rpmfiFMode(bfi));
00507
00508 if (awhat != bwhat) return 1;
00509
00510 if (awhat == LINK) {
00511 const char * alink = rpmfiFLink(afi);
00512 const char * blink = rpmfiFLink(bfi);
00513 if (alink == blink) return 0;
00514 if (alink == NULL) return 1;
00515 if (blink == NULL) return -1;
00516 return strcmp(alink, blink);
00517 } else if (awhat == REG) {
00518 const unsigned char * amd5 = rpmfiMD5(afi);
00519 const unsigned char * bmd5 = rpmfiMD5(bfi);
00520 if (amd5 == bmd5) return 0;
00521 if (amd5 == NULL) return 1;
00522 if (bmd5 == NULL) return -1;
00523 return memcmp(amd5, bmd5, 16);
00524 }
00525
00526 return 0;
00527 }
00528
00529
00530
00531 fileAction rpmfiDecideFate(const rpmfi ofi, rpmfi nfi, int skipMissing)
00532 {
00533 const char * fn = rpmfiFN(nfi);
00534 int newFlags = rpmfiFFlags(nfi);
00535 char buffer[1024];
00536 fileTypes dbWhat, newWhat, diskWhat;
00537 struct stat sb;
00538 int save = (newFlags & RPMFILE_NOREPLACE) ? FA_ALTNAME : FA_SAVE;
00539
00540 if (lstat(fn, &sb)) {
00541
00542
00543
00544
00545 if (skipMissing && (newFlags & RPMFILE_MISSINGOK)) {
00546 rpmMessage(RPMMESS_DEBUG, _("%s skipped due to missingok flag\n"),
00547 fn);
00548 return FA_SKIP;
00549 } else {
00550 return FA_CREATE;
00551 }
00552 }
00553
00554 diskWhat = whatis((int_16)sb.st_mode);
00555 dbWhat = whatis(rpmfiFMode(ofi));
00556 newWhat = whatis(rpmfiFMode(nfi));
00557
00558
00559
00560
00561
00562 if (newWhat == XDIR)
00563 return FA_CREATE;
00564
00565 if (diskWhat != newWhat)
00566 return save;
00567 else if (newWhat != dbWhat && diskWhat != dbWhat)
00568 return save;
00569 else if (dbWhat != newWhat)
00570 return FA_CREATE;
00571 else if (dbWhat != LINK && dbWhat != REG)
00572 return FA_CREATE;
00573
00574
00575
00576
00577
00578 if (dbWhat == REG) {
00579 const unsigned char * omd5, * nmd5;
00580 if (domd5(fn, buffer, 0, NULL))
00581 return FA_CREATE;
00582 omd5 = rpmfiMD5(ofi);
00583 if (omd5 && !memcmp(omd5, buffer, 16))
00584 return FA_CREATE;
00585 nmd5 = rpmfiMD5(nfi);
00586
00587 if (omd5 && nmd5 && !memcmp(omd5, nmd5, 16))
00588 return FA_SKIP;
00589
00590 } else {
00591 const char * oFLink, * nFLink;
00592 memset(buffer, 0, sizeof(buffer));
00593 if (readlink(fn, buffer, sizeof(buffer) - 1) == -1)
00594 return FA_CREATE;
00595 oFLink = rpmfiFLink(ofi);
00596 if (oFLink && !strcmp(oFLink, buffer))
00597 return FA_CREATE;
00598 nFLink = rpmfiFLink(nfi);
00599
00600 if (oFLink && nFLink && !strcmp(oFLink, nFLink))
00601 return FA_SKIP;
00602
00603 }
00604
00605
00606
00607
00608
00609
00610
00611 return save;
00612 }
00613
00614
00615
00616 const char *const rpmfiTypeString(rpmfi fi)
00617 {
00618 switch(rpmteType(fi->te)) {
00619 case TR_ADDED: return " install";
00620 case TR_REMOVED: return " erase";
00621 default: return "???";
00622 }
00623
00624 }
00625
00626 #define alloca_strdup(_s) strcpy(alloca(strlen(_s)+1), (_s))
00627
00637
00638 static
00639 Header relocateFileList(const rpmts ts, rpmfi fi,
00640 Header origH, fileAction * actions)
00641
00642 {
00643 rpmte p = rpmtsRelocateElement(ts);
00644 HGE_t hge = fi->hge;
00645 HAE_t hae = fi->hae;
00646 HME_t hme = fi->hme;
00647 HFD_t hfd = (fi->hfd ? fi->hfd : headerFreeData);
00648 static int _printed = 0;
00649 int allowBadRelocate = (rpmtsFilterFlags(ts) & RPMPROB_FILTER_FORCERELOCATE);
00650 rpmRelocation * relocations = NULL;
00651 int numRelocations;
00652 const char ** validRelocations;
00653 rpmTagType validType;
00654 int numValid;
00655 const char ** baseNames;
00656 const char ** dirNames;
00657 int_32 * dirIndexes;
00658 int_32 * newDirIndexes;
00659 int_32 fileCount;
00660 int_32 dirCount;
00661 uint_32 mydColor = rpmExpandNumeric("%{?_autorelocate_dcolor}");
00662 uint_32 * fFlags = NULL;
00663 uint_32 * fColors = NULL;
00664 uint_32 * dColors = NULL;
00665 uint_16 * fModes = NULL;
00666 Header h;
00667 int nrelocated = 0;
00668 int fileAlloced = 0;
00669 char * fn = NULL;
00670 int haveRelocatedFile = 0;
00671 int reldel = 0;
00672 int len;
00673 int i, j, xx;
00674
00675 if (!hge(origH, RPMTAG_PREFIXES, &validType,
00676 (void **) &validRelocations, &numValid))
00677 numValid = 0;
00678
00679 assert(p != NULL);
00680 numRelocations = 0;
00681 if (p->relocs)
00682 while (p->relocs[numRelocations].newPath ||
00683 p->relocs[numRelocations].oldPath)
00684 numRelocations++;
00685
00686
00687
00688
00689
00690
00691
00692 if (p->relocs == NULL || numRelocations == 0) {
00693 if (numValid) {
00694 if (!headerIsEntry(origH, RPMTAG_INSTPREFIXES))
00695 xx = hae(origH, RPMTAG_INSTPREFIXES,
00696 validType, validRelocations, numValid);
00697 validRelocations = hfd(validRelocations, validType);
00698 }
00699
00700 return headerLink(origH);
00701 }
00702
00703 h = headerLink(origH);
00704
00705 relocations = alloca(sizeof(*relocations) * numRelocations);
00706
00707
00708 for (i = 0; i < numRelocations; i++) {
00709 char * t;
00710
00711
00712
00713
00714
00715 if (p->relocs[i].oldPath == NULL) continue;
00716
00717
00718
00719 t = alloca_strdup(p->relocs[i].oldPath);
00720
00721 relocations[i].oldPath = (t[0] == '/' && t[1] == '\0')
00722 ? t
00723 : stripTrailingChar(t, '/');
00724
00725
00726
00727 if (p->relocs[i].newPath) {
00728 int del;
00729
00730 t = alloca_strdup(p->relocs[i].newPath);
00731
00732 relocations[i].newPath = (t[0] == '/' && t[1] == '\0')
00733 ? t
00734 : stripTrailingChar(t, '/');
00735
00736
00737
00738
00739 for (j = 0; j < numValid; j++) {
00740 if (!strcmp(validRelocations[j], relocations[i].oldPath))
00741 break;
00742 }
00743
00744
00745 if (j == numValid && !allowBadRelocate && actions) {
00746 rpmps ps = rpmtsProblems(ts);
00747 rpmpsAppend(ps, RPMPROB_BADRELOCATE,
00748 rpmteNEVR(p), rpmteKey(p),
00749 relocations[i].oldPath, NULL, NULL, 0);
00750 ps = rpmpsFree(ps);
00751 }
00752 del =
00753 strlen(relocations[i].newPath) - strlen(relocations[i].oldPath);
00754
00755
00756 if (del > reldel)
00757 reldel = del;
00758 } else {
00759 relocations[i].newPath = NULL;
00760 }
00761 }
00762
00763
00764 for (i = 0; i < numRelocations; i++) {
00765 int madeSwap;
00766 madeSwap = 0;
00767 for (j = 1; j < numRelocations; j++) {
00768 rpmRelocation tmpReloc;
00769 if (relocations[j - 1].oldPath == NULL ||
00770 relocations[j ].oldPath == NULL ||
00771 strcmp(relocations[j - 1].oldPath, relocations[j].oldPath) <= 0)
00772 continue;
00773
00774 tmpReloc = relocations[j - 1];
00775 relocations[j - 1] = relocations[j];
00776 relocations[j] = tmpReloc;
00777
00778 madeSwap = 1;
00779 }
00780 if (!madeSwap) break;
00781 }
00782
00783 if (!_printed) {
00784 _printed = 1;
00785 rpmMessage(RPMMESS_DEBUG, _("========== relocations\n"));
00786 for (i = 0; i < numRelocations; i++) {
00787 if (relocations[i].oldPath == NULL) continue;
00788 if (relocations[i].newPath == NULL)
00789 rpmMessage(RPMMESS_DEBUG, _("%5d exclude %s\n"),
00790 i, relocations[i].oldPath);
00791 else
00792 rpmMessage(RPMMESS_DEBUG, _("%5d relocate %s -> %s\n"),
00793 i, relocations[i].oldPath, relocations[i].newPath);
00794 }
00795 }
00796
00797
00798 if (numValid) {
00799 const char ** actualRelocations;
00800 int numActual;
00801
00802 actualRelocations = xmalloc(numValid * sizeof(*actualRelocations));
00803 numActual = 0;
00804 for (i = 0; i < numValid; i++) {
00805 for (j = 0; j < numRelocations; j++) {
00806 if (relocations[j].oldPath == NULL ||
00807 strcmp(validRelocations[i], relocations[j].oldPath))
00808 continue;
00809
00810 if (relocations[j].newPath) {
00811 actualRelocations[numActual] = relocations[j].newPath;
00812 numActual++;
00813 }
00814 break;
00815 }
00816 if (j == numRelocations) {
00817 actualRelocations[numActual] = validRelocations[i];
00818 numActual++;
00819 }
00820 }
00821
00822 if (numActual)
00823 xx = hae(h, RPMTAG_INSTPREFIXES, RPM_STRING_ARRAY_TYPE,
00824 (void **) actualRelocations, numActual);
00825
00826 actualRelocations = _free(actualRelocations);
00827 validRelocations = hfd(validRelocations, validType);
00828 }
00829
00830 xx = hge(h, RPMTAG_BASENAMES, NULL, (void **) &baseNames, &fileCount);
00831 xx = hge(h, RPMTAG_DIRINDEXES, NULL, (void **) &dirIndexes, NULL);
00832 xx = hge(h, RPMTAG_DIRNAMES, NULL, (void **) &dirNames, &dirCount);
00833 xx = hge(h, RPMTAG_FILEFLAGS, NULL, (void **) &fFlags, NULL);
00834 xx = hge(h, RPMTAG_FILECOLORS, NULL, (void **) &fColors, NULL);
00835 xx = hge(h, RPMTAG_FILEMODES, NULL, (void **) &fModes, NULL);
00836
00837 dColors = alloca(dirCount * sizeof(*dColors));
00838 memset(dColors, 0, dirCount * sizeof(*dColors));
00839
00840 newDirIndexes = alloca(sizeof(*newDirIndexes) * fileCount);
00841 memcpy(newDirIndexes, dirIndexes, sizeof(*newDirIndexes) * fileCount);
00842 dirIndexes = newDirIndexes;
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852 for (i = fileCount - 1; i >= 0; i--) {
00853 fileTypes ft;
00854 int fnlen;
00855
00856 len = reldel +
00857 strlen(dirNames[dirIndexes[i]]) + strlen(baseNames[i]) + 1;
00858
00859 if (len >= fileAlloced) {
00860 fileAlloced = len * 2;
00861 fn = xrealloc(fn, fileAlloced);
00862 }
00863
00864
00865 assert(fn != NULL);
00866 *fn = '\0';
00867 fnlen = stpcpy( stpcpy(fn, dirNames[dirIndexes[i]]), baseNames[i]) - fn;
00868
00869 if (fColors != NULL) {
00870
00871 for (j = 0; j < dirCount; j++) {
00872 if (strcmp(dirNames[dirIndexes[i]], dirNames[j])) continue;
00873 dColors[j] |= fColors[i];
00874 }
00875 }
00876
00877
00878
00879
00880
00881
00882
00883
00884 for (j = numRelocations - 1; j >= 0; j--) {
00885 if (relocations[j].oldPath == NULL)
00886 continue;
00887 len = strcmp(relocations[j].oldPath, "/")
00888 ? strlen(relocations[j].oldPath)
00889 : 0;
00890
00891 if (fnlen < len)
00892 continue;
00893
00894
00895
00896
00897 if (!(fn[len] == '/' || fnlen == len))
00898 continue;
00899
00900 if (strncmp(relocations[j].oldPath, fn, len))
00901 continue;
00902 break;
00903 }
00904 if (j < 0) continue;
00905
00906
00907 ft = whatis(fModes[i]);
00908
00909
00910
00911 if (relocations[j].newPath == NULL) {
00912 if (ft == XDIR) {
00913
00914 for (j = dirIndexes[i]; j < dirCount; j++) {
00915 len = strlen(dirNames[j]) - 1;
00916 while (len > 0 && dirNames[j][len-1] == '/') len--;
00917 if (fnlen != len)
00918 continue;
00919 if (strncmp(fn, dirNames[j], fnlen))
00920 continue;
00921 break;
00922 }
00923 }
00924 if (actions) {
00925 actions[i] = FA_SKIPNSTATE;
00926 rpmMessage(RPMMESS_DEBUG, _("excluding %s %s\n"),
00927 ftstring(ft), fn);
00928 }
00929 continue;
00930 }
00931
00932
00933 if (fnlen != len) continue;
00934
00935 if (actions)
00936 rpmMessage(RPMMESS_DEBUG, _("relocating %s to %s\n"),
00937 fn, relocations[j].newPath);
00938 nrelocated++;
00939
00940 strcpy(fn, relocations[j].newPath);
00941 { char * te = strrchr(fn, '/');
00942 if (te) {
00943 if (te > fn) te++;
00944 fnlen = te - fn;
00945 } else
00946 te = fn + strlen(fn);
00947
00948 if (strcmp(baseNames[i], te))
00949 baseNames[i] = alloca_strdup(te);
00950 *te = '\0';
00951
00952 }
00953
00954
00955 for (j = 0; j < dirCount; j++) {
00956 if (fnlen != strlen(dirNames[j]))
00957 continue;
00958 if (strncmp(fn, dirNames[j], fnlen))
00959 continue;
00960 break;
00961 }
00962
00963 if (j < dirCount) {
00964 dirIndexes[i] = j;
00965 continue;
00966 }
00967
00968
00969 if (!haveRelocatedFile) {
00970 const char ** newDirList;
00971
00972 haveRelocatedFile = 1;
00973 newDirList = xmalloc((dirCount + 1) * sizeof(*newDirList));
00974 for (j = 0; j < dirCount; j++)
00975 newDirList[j] = alloca_strdup(dirNames[j]);
00976 dirNames = hfd(dirNames, RPM_STRING_ARRAY_TYPE);
00977 dirNames = newDirList;
00978 } else {
00979 dirNames = xrealloc(dirNames,
00980 sizeof(*dirNames) * (dirCount + 1));
00981 }
00982
00983 dirNames[dirCount] = alloca_strdup(fn);
00984 dirIndexes[i] = dirCount;
00985 dirCount++;
00986 }
00987
00988
00989 for (i = dirCount - 1; i >= 0; i--) {
00990 for (j = numRelocations - 1; j >= 0; j--) {
00991
00992
00993 if (j == p->autorelocatex
00994 && (dColors[i] == 0 || !(dColors[i] & mydColor)))
00995 continue;
00996
00997 if (relocations[j].oldPath == NULL)
00998 continue;
00999 len = strcmp(relocations[j].oldPath, "/")
01000 ? strlen(relocations[j].oldPath)
01001 : 0;
01002
01003 if (len && strncmp(relocations[j].oldPath, dirNames[i], len))
01004 continue;
01005
01006
01007
01008
01009
01010 if (dirNames[i][len] != '/')
01011 continue;
01012
01013 if (relocations[j].newPath) {
01014 const char * s = relocations[j].newPath;
01015 char * t = alloca(strlen(s) + strlen(dirNames[i]) - len + 1);
01016 size_t slen;
01017
01018 (void) stpcpy( stpcpy(t, s) , dirNames[i] + len);
01019
01020
01021 (void) rpmCleanPath(t);
01022 slen = strlen(t);
01023 t[slen] = '/';
01024 t[slen+1] = '\0';
01025
01026 if (actions)
01027 rpmMessage(RPMMESS_DEBUG,
01028 _("relocating directory %s to %s\n"), dirNames[i], t);
01029 dirNames[i] = t;
01030 nrelocated++;
01031 }
01032 }
01033 }
01034
01035
01036 if (nrelocated) {
01037 int c;
01038 void * d;
01039 rpmTagType t;
01040
01041 d = NULL;
01042 xx = hge(h, RPMTAG_BASENAMES, &t, &d, &c);
01043 xx = hae(h, RPMTAG_ORIGBASENAMES, t, d, c);
01044 d = hfd(d, t);
01045
01046 d = NULL;
01047 xx = hge(h, RPMTAG_DIRNAMES, &t, &d, &c);
01048 xx = hae(h, RPMTAG_ORIGDIRNAMES, t, d, c);
01049 d = hfd(d, t);
01050
01051 d = NULL;
01052 xx = hge(h, RPMTAG_DIRINDEXES, &t, &d, &c);
01053 xx = hae(h, RPMTAG_ORIGDIRINDEXES, t, d, c);
01054 d = hfd(d, t);
01055
01056 xx = hme(h, RPMTAG_BASENAMES, RPM_STRING_ARRAY_TYPE,
01057 baseNames, fileCount);
01058 fi->bnl = hfd(fi->bnl, RPM_STRING_ARRAY_TYPE);
01059 xx = hge(h, RPMTAG_BASENAMES, NULL, (void **) &fi->bnl, &fi->fc);
01060
01061 xx = hme(h, RPMTAG_DIRNAMES, RPM_STRING_ARRAY_TYPE,
01062 dirNames, dirCount);
01063 fi->dnl = hfd(fi->dnl, RPM_STRING_ARRAY_TYPE);
01064 xx = hge(h, RPMTAG_DIRNAMES, NULL, (void **) &fi->dnl, &fi->dc);
01065
01066 xx = hme(h, RPMTAG_DIRINDEXES, RPM_INT32_TYPE,
01067 dirIndexes, fileCount);
01068 xx = hge(h, RPMTAG_DIRINDEXES, NULL, (void **) &fi->dil, NULL);
01069 }
01070
01071 baseNames = hfd(baseNames, RPM_STRING_ARRAY_TYPE);
01072 dirNames = hfd(dirNames, RPM_STRING_ARRAY_TYPE);
01073
01074 fn = _free(fn);
01075
01076
01077 return h;
01078 }
01079
01080
01081 rpmfi rpmfiFree(rpmfi fi)
01082 {
01083 HFD_t hfd = headerFreeData;
01084
01085 if (fi == NULL) return NULL;
01086
01087 if (fi->nrefs > 1)
01088 return rpmfiUnlink(fi, fi->Type);
01089
01090
01091 if (_rpmfi_debug < 0)
01092 fprintf(stderr, "*** fi %p\t%s[%d]\n", fi, fi->Type, fi->fc);
01093
01094
01095
01096 if (fi->fc > 0) {
01097 fi->bnl = hfd(fi->bnl, -1);
01098 fi->dnl = hfd(fi->dnl, -1);
01099
01100 fi->flinks = hfd(fi->flinks, -1);
01101 fi->flangs = hfd(fi->flangs, -1);
01102 fi->fmd5s = hfd(fi->fmd5s, -1);
01103 fi->md5s = _free(fi->md5s);
01104
01105 fi->cdict = hfd(fi->cdict, -1);
01106
01107 fi->fuser = hfd(fi->fuser, -1);
01108 fi->fgroup = hfd(fi->fgroup, -1);
01109
01110 fi->fstates = _free(fi->fstates);
01111
01112
01113 if (!fi->keep_header && fi->h == NULL) {
01114 fi->fmtimes = _free(fi->fmtimes);
01115 fi->fmodes = _free(fi->fmodes);
01116 fi->fflags = _free(fi->fflags);
01117 fi->vflags = _free(fi->vflags);
01118 fi->fsizes = _free(fi->fsizes);
01119 fi->frdevs = _free(fi->frdevs);
01120 fi->finodes = _free(fi->finodes);
01121 fi->dil = _free(fi->dil);
01122
01123 fi->fcolors = _free(fi->fcolors);
01124 fi->fcdictx = _free(fi->fcdictx);
01125 fi->ddict = _free(fi->ddict);
01126 fi->fddictx = _free(fi->fddictx);
01127 fi->fddictn = _free(fi->fddictn);
01128
01129 }
01130
01131 }
01132
01133
01134 fi->fsm = freeFSM(fi->fsm);
01135
01136 fi->fn = _free(fi->fn);
01137 fi->apath = _free(fi->apath);
01138 fi->fmapflags = _free(fi->fmapflags);
01139
01140 fi->obnl = hfd(fi->obnl, -1);
01141 fi->odnl = hfd(fi->odnl, -1);
01142
01143 fi->actions = _free(fi->actions);
01144 fi->replacedSizes = _free(fi->replacedSizes);
01145 fi->replaced = _free(fi->replaced);
01146
01147 fi->h = headerFree(fi->h);
01148
01149
01150 (void) rpmfiUnlink(fi, fi->Type);
01151 memset(fi, 0, sizeof(*fi));
01152 fi = _free(fi);
01153
01154
01155 return NULL;
01156 }
01157
01163 static inline unsigned char nibble(char c)
01164
01165 {
01166 if (c >= '0' && c <= '9')
01167 return (c - '0');
01168 if (c >= 'A' && c <= 'F')
01169 return (c - 'A') + 10;
01170 if (c >= 'a' && c <= 'f')
01171 return (c - 'a') + 10;
01172 return 0;
01173 }
01174
01175 #define _fdupe(_fi, _data) \
01176 if ((_fi)->_data != NULL) \
01177 (_fi)->_data = memcpy(xmalloc((_fi)->fc * sizeof(*(_fi)->_data)), \
01178 (_fi)->_data, (_fi)->fc * sizeof(*(_fi)->_data))
01179
01180 rpmfi rpmfiNew(rpmts ts, Header h, rpmTag tagN, int scareMem)
01181 {
01182 HGE_t hge =
01183 (scareMem ? (HGE_t) headerGetEntryMinMemory : (HGE_t) headerGetEntry);
01184 HFD_t hfd = headerFreeData;
01185 rpmte p;
01186 rpmfi fi = NULL;
01187 const char * Type;
01188 uint_32 * uip;
01189 int dnlmax, bnlmax;
01190 unsigned char * t;
01191 int len;
01192 int xx;
01193 int i;
01194
01195 if (tagN == RPMTAG_BASENAMES) {
01196 Type = "Files";
01197 } else {
01198 Type = "?Type?";
01199 goto exit;
01200 }
01201
01202 fi = xcalloc(1, sizeof(*fi));
01203 if (fi == NULL)
01204 goto exit;
01205
01206 fi->magic = RPMFIMAGIC;
01207 fi->Type = Type;
01208 fi->i = -1;
01209 fi->tagN = tagN;
01210
01211 fi->hge = hge;
01212 fi->hae = (HAE_t) headerAddEntry;
01213 fi->hme = (HME_t) headerModifyEntry;
01214 fi->hre = (HRE_t) headerRemoveEntry;
01215 fi->hfd = headerFreeData;
01216
01217 fi->h = (scareMem ? headerLink(h) : NULL);
01218
01219 if (fi->fsm == NULL)
01220 fi->fsm = newFSM();
01221
01222
01223 xx = hge(h, RPMTAG_ARCHIVESIZE, NULL, (void **) &uip, NULL);
01224 fi->archivePos = 0;
01225 fi->archiveSize = (xx ? *uip : 0);
01226
01227 if (!hge(h, RPMTAG_BASENAMES, NULL, (void **) &fi->bnl, &fi->fc)) {
01228 fi->fc = 0;
01229 fi->dc = 0;
01230 goto exit;
01231 }
01232 xx = hge(h, RPMTAG_DIRNAMES, NULL, (void **) &fi->dnl, &fi->dc);
01233 xx = hge(h, RPMTAG_DIRINDEXES, NULL, (void **) &fi->dil, NULL);
01234 xx = hge(h, RPMTAG_FILEMODES, NULL, (void **) &fi->fmodes, NULL);
01235 xx = hge(h, RPMTAG_FILEFLAGS, NULL, (void **) &fi->fflags, NULL);
01236 xx = hge(h, RPMTAG_FILEVERIFYFLAGS, NULL, (void **) &fi->vflags, NULL);
01237 xx = hge(h, RPMTAG_FILESIZES, NULL, (void **) &fi->fsizes, NULL);
01238
01239 xx = hge(h, RPMTAG_FILECOLORS, NULL, (void **) &fi->fcolors, NULL);
01240 fi->color = 0;
01241 if (fi->fcolors != NULL)
01242 for (i = 0; i < fi->fc; i++)
01243 fi->color |= fi->fcolors[i];
01244 xx = hge(h, RPMTAG_CLASSDICT, NULL, (void **) &fi->cdict, &fi->ncdict);
01245 xx = hge(h, RPMTAG_FILECLASS, NULL, (void **) &fi->fcdictx, NULL);
01246
01247 xx = hge(h, RPMTAG_DEPENDSDICT, NULL, (void **) &fi->ddict, &fi->nddict);
01248 xx = hge(h, RPMTAG_FILEDEPENDSX, NULL, (void **) &fi->fddictx, NULL);
01249 xx = hge(h, RPMTAG_FILEDEPENDSN, NULL, (void **) &fi->fddictn, NULL);
01250
01251 xx = hge(h, RPMTAG_FILESTATES, NULL, (void **) &fi->fstates, NULL);
01252 if (xx == 0 || fi->fstates == NULL)
01253 fi->fstates = xcalloc(fi->fc, sizeof(*fi->fstates));
01254 else
01255 _fdupe(fi, fstates);
01256
01257 fi->action = FA_UNKNOWN;
01258 fi->flags = 0;
01259
01260 if (fi->actions == NULL)
01261 fi->actions = xcalloc(fi->fc, sizeof(*fi->actions));
01262
01263 fi->keep_header = (scareMem ? 1 : 0);
01264
01265
01266 fi->mapflags =
01267 CPIO_MAP_PATH | CPIO_MAP_MODE | CPIO_MAP_UID | CPIO_MAP_GID;
01268
01269 xx = hge(h, RPMTAG_FILELINKTOS, NULL, (void **) &fi->flinks, NULL);
01270 xx = hge(h, RPMTAG_FILELANGS, NULL, (void **) &fi->flangs, NULL);
01271
01272 fi->fmd5s = NULL;
01273 xx = hge(h, RPMTAG_FILEMD5S, NULL, (void **) &fi->fmd5s, NULL);
01274
01275 fi->md5s = NULL;
01276 if (fi->fmd5s) {
01277 t = xmalloc(fi->fc * 16);
01278 fi->md5s = t;
01279 for (i = 0; i < fi->fc; i++) {
01280 const char * fmd5;
01281 int j;
01282
01283 fmd5 = fi->fmd5s[i];
01284 if (!(fmd5 && *fmd5 != '\0')) {
01285 memset(t, 0, 16);
01286 t += 16;
01287 continue;
01288 }
01289 for (j = 0; j < 16; j++, t++, fmd5 += 2)
01290 *t = (nibble(fmd5[0]) << 4) | nibble(fmd5[1]);
01291 }
01292 fi->fmd5s = hfd(fi->fmd5s, -1);
01293 }
01294
01295
01296 xx = hge(h, RPMTAG_FILEMTIMES, NULL, (void **) &fi->fmtimes, NULL);
01297 xx = hge(h, RPMTAG_FILERDEVS, NULL, (void **) &fi->frdevs, NULL);
01298 xx = hge(h, RPMTAG_FILEINODES, NULL, (void **) &fi->finodes, NULL);
01299
01300 fi->replacedSizes = xcalloc(fi->fc, sizeof(*fi->replacedSizes));
01301
01302 xx = hge(h, RPMTAG_FILEUSERNAME, NULL, (void **) &fi->fuser, NULL);
01303 xx = hge(h, RPMTAG_FILEGROUPNAME, NULL, (void **) &fi->fgroup, NULL);
01304
01305 if (ts != NULL)
01306 if (fi != NULL)
01307 if ((p = rpmtsRelocateElement(ts)) != NULL && rpmteType(p) == TR_ADDED
01308 && !headerIsEntry(h, RPMTAG_SOURCEPACKAGE)
01309 && !headerIsEntry(h, RPMTAG_ORIGBASENAMES))
01310 {
01311 const char * fmt = rpmGetPath("%{?_autorelocate_path}", NULL);
01312 const char * errstr;
01313 char * newPath;
01314 Header foo;
01315
01316
01317 newPath = headerSprintf(h, fmt, rpmTagTable, rpmHeaderFormats, &errstr);
01318 fmt = _free(fmt);
01319
01320 #if __ia64__
01321
01322 if (newPath != NULL && *newPath != '\0'
01323 && strlen(newPath) >= (sizeof("/emul/i386")-1)
01324 && newPath[0] == '/' && newPath[1] == 'e' && newPath[2] == 'm'
01325 && newPath[3] == 'u' && newPath[4] == 'l' && newPath[5] == '/'
01326 && newPath[6] == 'i' && newPath[8] == '8' && newPath[9] == '6')
01327 {
01328 newPath[7] = 'a';
01329 newPath[8] = '3';
01330 newPath[9] = '2';
01331 }
01332 #endif
01333
01334
01335 i = p->nrelocs;
01336 if (newPath != NULL && *newPath != '\0' && p->relocs != NULL)
01337 for (i = 0; i < p->nrelocs; i++) {
01338
01339 if (strcmp(p->relocs[i].oldPath, "/"))
01340 continue;
01341 if (strcmp(p->relocs[i].newPath, newPath))
01342 continue;
01343
01344 break;
01345 }
01346
01347
01348 if (newPath != NULL && *newPath != '\0' && i == p->nrelocs
01349 && p->archScore == 0)
01350 {
01351
01352 p->relocs =
01353 xrealloc(p->relocs, (p->nrelocs + 2) * sizeof(*p->relocs));
01354 p->relocs[p->nrelocs].oldPath = xstrdup("/");
01355 p->relocs[p->nrelocs].newPath = xstrdup(newPath);
01356 p->autorelocatex = p->nrelocs;
01357 p->nrelocs++;
01358 p->relocs[p->nrelocs].oldPath = NULL;
01359 p->relocs[p->nrelocs].newPath = NULL;
01360 }
01361 newPath = _free(newPath);
01362
01363
01364 if (fi->actions == NULL)
01365 fi->actions = xcalloc(fi->fc, sizeof(*fi->actions));
01366
01367 foo = relocateFileList(ts, fi, h, fi->actions);
01368
01369 fi->h = headerFree(fi->h);
01370 fi->h = headerLink(foo);
01371 foo = headerFree(foo);
01372 }
01373
01374 if (!scareMem) {
01375 _fdupe(fi, fmtimes);
01376 _fdupe(fi, frdevs);
01377 _fdupe(fi, finodes);
01378 _fdupe(fi, fsizes);
01379 _fdupe(fi, fflags);
01380 _fdupe(fi, vflags);
01381 _fdupe(fi, fmodes);
01382 _fdupe(fi, dil);
01383
01384 _fdupe(fi, fcolors);
01385 _fdupe(fi, fcdictx);
01386
01387 if (fi->ddict != NULL)
01388 fi->ddict = memcpy(xmalloc(fi->nddict * sizeof(*fi->ddict)),
01389 fi->ddict, fi->nddict * sizeof(*fi->ddict));
01390
01391 _fdupe(fi, fddictx);
01392 _fdupe(fi, fddictn);
01393
01394 fi->h = headerFree(fi->h);
01395 }
01396
01397 dnlmax = -1;
01398 for (i = 0; i < fi->dc; i++) {
01399 if ((len = strlen(fi->dnl[i])) > dnlmax)
01400 dnlmax = len;
01401 }
01402 bnlmax = -1;
01403 for (i = 0; i < fi->fc; i++) {
01404 if ((len = strlen(fi->bnl[i])) > bnlmax)
01405 bnlmax = len;
01406 }
01407 fi->fnlen = dnlmax + bnlmax + 1;
01408 fi->fn = NULL;
01409
01410 fi->dperms = 0755;
01411 fi->fperms = 0644;
01412
01413 exit:
01414
01415 if (_rpmfi_debug < 0)
01416 fprintf(stderr, "*** fi %p\t%s[%d]\n", fi, Type, (fi ? fi->fc : 0));
01417
01418
01419
01420 return rpmfiLink(fi, (fi ? fi->Type : NULL));
01421
01422 }
01423
01424 void rpmfiBuildFClasses(Header h,
01425 const char *** fclassp, int * fcp)
01426 {
01427 int scareMem = 1;
01428 rpmfi fi = rpmfiNew(NULL, h, RPMTAG_BASENAMES, scareMem);
01429 const char * FClass;
01430 const char ** av;
01431 int ac;
01432 size_t nb;
01433 char * t;
01434
01435 if ((ac = rpmfiFC(fi)) <= 0) {
01436 av = NULL;
01437 ac = 0;
01438 goto exit;
01439 }
01440
01441
01442 nb = (ac + 1) * sizeof(*av);
01443 fi = rpmfiInit(fi, 0);
01444 if (fi != NULL)
01445 while (rpmfiNext(fi) >= 0) {
01446 FClass = rpmfiFClass(fi);
01447 if (FClass && *FClass != '\0')
01448 nb += strlen(FClass);
01449 nb += 1;
01450 }
01451
01452
01453 av = xmalloc(nb);
01454 t = ((char *) av) + ((ac + 1) * sizeof(*av));
01455 ac = 0;
01456 fi = rpmfiInit(fi, 0);
01457 if (fi != NULL)
01458 while (rpmfiNext(fi) >= 0) {
01459 FClass = rpmfiFClass(fi);
01460 av[ac++] = t;
01461 if (FClass && *FClass != '\0')
01462 t = stpcpy(t, FClass);
01463 *t++ = '\0';
01464 }
01465 av[ac] = NULL;
01466
01467
01468 exit:
01469 fi = rpmfiFree(fi);
01470
01471 if (fclassp)
01472 *fclassp = av;
01473 else
01474 av = _free(av);
01475
01476 if (fcp) *fcp = ac;
01477 }
01478
01479 void rpmfiBuildFDeps(Header h, rpmTag tagN,
01480 const char *** fdepsp, int * fcp)
01481 {
01482 int scareMem = 1;
01483 rpmfi fi = rpmfiNew(NULL, h, RPMTAG_BASENAMES, scareMem);
01484 rpmds ds = NULL;
01485 const char ** av;
01486 int ac;
01487 size_t nb;
01488 char * t;
01489 char deptype = 'R';
01490 char mydt;
01491 const char * DNEVR;
01492 const int_32 * ddict;
01493 unsigned ix;
01494 int ndx;
01495
01496 if ((ac = rpmfiFC(fi)) <= 0) {
01497 av = NULL;
01498 ac = 0;
01499 goto exit;
01500 }
01501
01502 if (tagN == RPMTAG_PROVIDENAME)
01503 deptype = 'P';
01504 else if (tagN == RPMTAG_REQUIRENAME)
01505 deptype = 'R';
01506
01507 ds = rpmdsNew(h, tagN, scareMem);
01508
01509
01510 nb = (ac + 1) * sizeof(*av);
01511 fi = rpmfiInit(fi, 0);
01512 if (fi != NULL)
01513 while (rpmfiNext(fi) >= 0) {
01514 ddict = NULL;
01515 ndx = rpmfiFDepends(fi, &ddict);
01516 if (ddict != NULL)
01517 while (ndx-- > 0) {
01518 ix = *ddict++;
01519 mydt = ((ix >> 24) & 0xff);
01520 if (mydt != deptype)
01521 continue;
01522 ix &= 0x00ffffff;
01523 (void) rpmdsSetIx(ds, ix-1);
01524 if (rpmdsNext(ds) < 0)
01525 continue;
01526 DNEVR = rpmdsDNEVR(ds);
01527 if (DNEVR != NULL)
01528 nb += strlen(DNEVR+2) + 1;
01529 }
01530 nb += 1;
01531 }
01532
01533
01534 av = xmalloc(nb);
01535 t = ((char *) av) + ((ac + 1) * sizeof(*av));
01536 ac = 0;
01537
01538 fi = rpmfiInit(fi, 0);
01539 if (fi != NULL)
01540 while (rpmfiNext(fi) >= 0) {
01541 av[ac++] = t;
01542 ddict = NULL;
01543 ndx = rpmfiFDepends(fi, &ddict);
01544 if (ddict != NULL)
01545 while (ndx-- > 0) {
01546 ix = *ddict++;
01547 mydt = ((ix >> 24) & 0xff);
01548 if (mydt != deptype)
01549 continue;
01550 ix &= 0x00ffffff;
01551 (void) rpmdsSetIx(ds, ix-1);
01552 if (rpmdsNext(ds) < 0)
01553 continue;
01554 DNEVR = rpmdsDNEVR(ds);
01555 if (DNEVR != NULL) {
01556 t = stpcpy(t, DNEVR+2);
01557 *t++ = ' ';
01558 *t = '\0';
01559 }
01560 }
01561 *t++ = '\0';
01562 }
01563
01564 av[ac] = NULL;
01565
01566 exit:
01567 fi = rpmfiFree(fi);
01568 ds = rpmdsFree(ds);
01569
01570 if (fdepsp)
01571 *fdepsp = av;
01572 else
01573 av = _free(av);
01574
01575 if (fcp) *fcp = ac;
01576 }