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