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 * fFlags = NULL;
00662 uint_32 * fColors = NULL;
00663 uint_32 * dColors = NULL;
00664 uint_16 * fModes = NULL;
00665 Header h;
00666 int nrelocated = 0;
00667 int fileAlloced = 0;
00668 char * fn = NULL;
00669 int haveRelocatedFile = 0;
00670 int reldel = 0;
00671 int len;
00672 int i, j, xx;
00673
00674 if (!hge(origH, RPMTAG_PREFIXES, &validType,
00675 (void **) &validRelocations, &numValid))
00676 numValid = 0;
00677
00678 assert(p != NULL);
00679 numRelocations = 0;
00680 if (p->relocs)
00681 while (p->relocs[numRelocations].newPath ||
00682 p->relocs[numRelocations].oldPath)
00683 numRelocations++;
00684
00685
00686
00687
00688
00689
00690
00691 if (p->relocs == NULL || numRelocations == 0) {
00692 if (numValid) {
00693 if (!headerIsEntry(origH, RPMTAG_INSTPREFIXES))
00694 xx = hae(origH, RPMTAG_INSTPREFIXES,
00695 validType, validRelocations, numValid);
00696 validRelocations = hfd(validRelocations, validType);
00697 }
00698
00699 return headerLink(origH);
00700 }
00701
00702 h = headerLink(origH);
00703
00704 relocations = alloca(sizeof(*relocations) * numRelocations);
00705
00706
00707 for (i = 0; i < numRelocations; i++) {
00708 char * t;
00709
00710
00711
00712
00713
00714 if (p->relocs[i].oldPath == NULL) continue;
00715
00716
00717
00718 t = alloca_strdup(p->relocs[i].oldPath);
00719
00720 relocations[i].oldPath = (t[0] == '/' && t[1] == '\0')
00721 ? t
00722 : stripTrailingChar(t, '/');
00723
00724
00725
00726 if (p->relocs[i].newPath) {
00727 int del;
00728
00729 t = alloca_strdup(p->relocs[i].newPath);
00730
00731 relocations[i].newPath = (t[0] == '/' && t[1] == '\0')
00732 ? t
00733 : stripTrailingChar(t, '/');
00734
00735
00736
00737
00738 for (j = 0; j < numValid; j++) {
00739 if (!strcmp(validRelocations[j], relocations[i].oldPath))
00740 break;
00741 }
00742
00743
00744 if (j == numValid && !allowBadRelocate && actions) {
00745 rpmps ps = rpmtsProblems(ts);
00746 rpmpsAppend(ps, RPMPROB_BADRELOCATE,
00747 rpmteNEVR(p), rpmteKey(p),
00748 relocations[i].oldPath, NULL, NULL, 0);
00749 ps = rpmpsFree(ps);
00750 }
00751 del =
00752 strlen(relocations[i].newPath) - strlen(relocations[i].oldPath);
00753
00754
00755 if (del > reldel)
00756 reldel = del;
00757 } else {
00758 relocations[i].newPath = NULL;
00759 }
00760 }
00761
00762
00763 for (i = 0; i < numRelocations; i++) {
00764 int madeSwap;
00765 madeSwap = 0;
00766 for (j = 1; j < numRelocations; j++) {
00767 rpmRelocation tmpReloc;
00768 if (relocations[j - 1].oldPath == NULL ||
00769 relocations[j ].oldPath == NULL ||
00770 strcmp(relocations[j - 1].oldPath, relocations[j].oldPath) <= 0)
00771 continue;
00772
00773 tmpReloc = relocations[j - 1];
00774 relocations[j - 1] = relocations[j];
00775 relocations[j] = tmpReloc;
00776
00777 madeSwap = 1;
00778 }
00779 if (!madeSwap) break;
00780 }
00781
00782 if (!_printed) {
00783 _printed = 1;
00784 rpmMessage(RPMMESS_DEBUG, _("========== relocations\n"));
00785 for (i = 0; i < numRelocations; i++) {
00786 if (relocations[i].oldPath == NULL) continue;
00787 if (relocations[i].newPath == NULL)
00788 rpmMessage(RPMMESS_DEBUG, _("%5d exclude %s\n"),
00789 i, relocations[i].oldPath);
00790 else
00791 rpmMessage(RPMMESS_DEBUG, _("%5d relocate %s -> %s\n"),
00792 i, relocations[i].oldPath, relocations[i].newPath);
00793 }
00794 }
00795
00796
00797 if (numValid) {
00798 const char ** actualRelocations;
00799 int numActual;
00800
00801 actualRelocations = xmalloc(numValid * sizeof(*actualRelocations));
00802 numActual = 0;
00803 for (i = 0; i < numValid; i++) {
00804 for (j = 0; j < numRelocations; j++) {
00805 if (relocations[j].oldPath == NULL ||
00806 strcmp(validRelocations[i], relocations[j].oldPath))
00807 continue;
00808
00809 if (relocations[j].newPath) {
00810 actualRelocations[numActual] = relocations[j].newPath;
00811 numActual++;
00812 }
00813 break;
00814 }
00815 if (j == numRelocations) {
00816 actualRelocations[numActual] = validRelocations[i];
00817 numActual++;
00818 }
00819 }
00820
00821 if (numActual)
00822 xx = hae(h, RPMTAG_INSTPREFIXES, RPM_STRING_ARRAY_TYPE,
00823 (void **) actualRelocations, numActual);
00824
00825 actualRelocations = _free(actualRelocations);
00826 validRelocations = hfd(validRelocations, validType);
00827 }
00828
00829 xx = hge(h, RPMTAG_BASENAMES, NULL, (void **) &baseNames, &fileCount);
00830 xx = hge(h, RPMTAG_DIRINDEXES, NULL, (void **) &dirIndexes, NULL);
00831 xx = hge(h, RPMTAG_DIRNAMES, NULL, (void **) &dirNames, &dirCount);
00832 xx = hge(h, RPMTAG_FILEFLAGS, NULL, (void **) &fFlags, NULL);
00833 xx = hge(h, RPMTAG_FILECOLORS, NULL, (void **) &fColors, NULL);
00834 xx = hge(h, RPMTAG_FILEMODES, NULL, (void **) &fModes, NULL);
00835
00836 dColors = alloca(dirCount * sizeof(*dColors));
00837 memset(dColors, 0, dirCount * sizeof(*dColors));
00838
00839 newDirIndexes = alloca(sizeof(*newDirIndexes) * fileCount);
00840 memcpy(newDirIndexes, dirIndexes, sizeof(*newDirIndexes) * fileCount);
00841 dirIndexes = newDirIndexes;
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851 for (i = fileCount - 1; i >= 0; i--) {
00852 fileTypes ft;
00853 int fnlen;
00854
00855 len = reldel +
00856 strlen(dirNames[dirIndexes[i]]) + strlen(baseNames[i]) + 1;
00857
00858 if (len >= fileAlloced) {
00859 fileAlloced = len * 2;
00860 fn = xrealloc(fn, fileAlloced);
00861 }
00862
00863
00864 assert(fn != NULL);
00865 *fn = '\0';
00866 fnlen = stpcpy( stpcpy(fn, dirNames[dirIndexes[i]]), baseNames[i]) - fn;
00867
00868 if (fColors != NULL)
00869 dColors[dirIndexes[i]] |= fColors[i];
00870
00871
00872
00873
00874
00875
00876
00877 for (j = numRelocations - 1; j >= 0; j--) {
00878 if (relocations[j].oldPath == NULL)
00879 continue;
00880 len = strcmp(relocations[j].oldPath, "/")
00881 ? strlen(relocations[j].oldPath)
00882 : 0;
00883
00884 if (fnlen < len)
00885 continue;
00886
00887
00888
00889
00890 if (!(fn[len] == '/' || fnlen == len))
00891 continue;
00892
00893 if (strncmp(relocations[j].oldPath, fn, len))
00894 continue;
00895 break;
00896 }
00897 if (j < 0) continue;
00898
00899
00900 ft = whatis(fModes[i]);
00901
00902
00903
00904 if (relocations[j].newPath == NULL) {
00905 if (ft == XDIR) {
00906
00907 for (j = dirIndexes[i]; j < dirCount; j++) {
00908 len = strlen(dirNames[j]) - 1;
00909 while (len > 0 && dirNames[j][len-1] == '/') len--;
00910 if (fnlen != len)
00911 continue;
00912 if (strncmp(fn, dirNames[j], fnlen))
00913 continue;
00914 break;
00915 }
00916 }
00917 if (actions) {
00918 actions[i] = FA_SKIPNSTATE;
00919 rpmMessage(RPMMESS_DEBUG, _("excluding %s %s\n"),
00920 ftstring(ft), fn);
00921 }
00922 continue;
00923 }
00924
00925
00926 if (fnlen != len) continue;
00927
00928 if (actions)
00929 rpmMessage(RPMMESS_DEBUG, _("relocating %s to %s\n"),
00930 fn, relocations[j].newPath);
00931 nrelocated++;
00932
00933 strcpy(fn, relocations[j].newPath);
00934 { char * te = strrchr(fn, '/');
00935 if (te) {
00936 if (te > fn) te++;
00937 fnlen = te - fn;
00938 } else
00939 te = fn + strlen(fn);
00940
00941 if (strcmp(baseNames[i], te))
00942 baseNames[i] = alloca_strdup(te);
00943 *te = '\0';
00944
00945 }
00946
00947
00948 for (j = 0; j < dirCount; j++) {
00949 if (fnlen != strlen(dirNames[j]))
00950 continue;
00951 if (strncmp(fn, dirNames[j], fnlen))
00952 continue;
00953 break;
00954 }
00955
00956 if (j < dirCount) {
00957 dirIndexes[i] = j;
00958 continue;
00959 }
00960
00961
00962 if (!haveRelocatedFile) {
00963 const char ** newDirList;
00964
00965 haveRelocatedFile = 1;
00966 newDirList = xmalloc((dirCount + 1) * sizeof(*newDirList));
00967 for (j = 0; j < dirCount; j++)
00968 newDirList[j] = alloca_strdup(dirNames[j]);
00969 dirNames = hfd(dirNames, RPM_STRING_ARRAY_TYPE);
00970 dirNames = newDirList;
00971 } else {
00972 dirNames = xrealloc(dirNames,
00973 sizeof(*dirNames) * (dirCount + 1));
00974 }
00975
00976 dirNames[dirCount] = alloca_strdup(fn);
00977 dirIndexes[i] = dirCount;
00978 dirCount++;
00979 }
00980
00981
00982 for (i = dirCount - 1; i >= 0; i--) {
00983 for (j = numRelocations - 1; j >= 0; j--) {
00984
00985
00986 if (j == p->autorelocatex
00987 && (dColors[i] == 0 || !(dColors[i] & 0x1)))
00988 continue;
00989
00990 if (relocations[j].oldPath == NULL)
00991 continue;
00992 len = strcmp(relocations[j].oldPath, "/")
00993 ? strlen(relocations[j].oldPath)
00994 : 0;
00995
00996 if (len && strncmp(relocations[j].oldPath, dirNames[i], len))
00997 continue;
00998
00999
01000
01001
01002
01003 if (dirNames[i][len] != '/')
01004 continue;
01005
01006 if (relocations[j].newPath) {
01007 const char * s = relocations[j].newPath;
01008 char * t = alloca(strlen(s) + strlen(dirNames[i]) - len + 1);
01009 size_t slen;
01010
01011 (void) stpcpy( stpcpy(t, s) , dirNames[i] + len);
01012
01013
01014 (void) rpmCleanPath(t);
01015 slen = strlen(t);
01016 t[slen] = '/';
01017 t[slen+1] = '\0';
01018
01019 if (actions)
01020 rpmMessage(RPMMESS_DEBUG,
01021 _("relocating directory %s to %s\n"), dirNames[i], t);
01022 dirNames[i] = t;
01023 nrelocated++;
01024 }
01025 }
01026 }
01027
01028
01029 if (nrelocated) {
01030 int c;
01031 void * d;
01032 rpmTagType t;
01033
01034 d = NULL;
01035 xx = hge(h, RPMTAG_BASENAMES, &t, &d, &c);
01036 xx = hae(h, RPMTAG_ORIGBASENAMES, t, d, c);
01037 d = hfd(d, t);
01038
01039 d = NULL;
01040 xx = hge(h, RPMTAG_DIRNAMES, &t, &d, &c);
01041 xx = hae(h, RPMTAG_ORIGDIRNAMES, t, d, c);
01042 d = hfd(d, t);
01043
01044 d = NULL;
01045 xx = hge(h, RPMTAG_DIRINDEXES, &t, &d, &c);
01046 xx = hae(h, RPMTAG_ORIGDIRINDEXES, t, d, c);
01047 d = hfd(d, t);
01048
01049 xx = hme(h, RPMTAG_BASENAMES, RPM_STRING_ARRAY_TYPE,
01050 baseNames, fileCount);
01051 fi->bnl = hfd(fi->bnl, RPM_STRING_ARRAY_TYPE);
01052 xx = hge(h, RPMTAG_BASENAMES, NULL, (void **) &fi->bnl, &fi->fc);
01053
01054 xx = hme(h, RPMTAG_DIRNAMES, RPM_STRING_ARRAY_TYPE,
01055 dirNames, dirCount);
01056 fi->dnl = hfd(fi->dnl, RPM_STRING_ARRAY_TYPE);
01057 xx = hge(h, RPMTAG_DIRNAMES, NULL, (void **) &fi->dnl, &fi->dc);
01058
01059 xx = hme(h, RPMTAG_DIRINDEXES, RPM_INT32_TYPE,
01060 dirIndexes, fileCount);
01061 xx = hge(h, RPMTAG_DIRINDEXES, NULL, (void **) &fi->dil, NULL);
01062 }
01063
01064 baseNames = hfd(baseNames, RPM_STRING_ARRAY_TYPE);
01065 dirNames = hfd(dirNames, RPM_STRING_ARRAY_TYPE);
01066
01067 fn = _free(fn);
01068
01069
01070 return h;
01071 }
01072
01073
01074 rpmfi rpmfiFree(rpmfi fi)
01075 {
01076 HFD_t hfd = headerFreeData;
01077
01078 if (fi == NULL) return NULL;
01079
01080 if (fi->nrefs > 1)
01081 return rpmfiUnlink(fi, fi->Type);
01082
01083
01084 if (_rpmfi_debug < 0)
01085 fprintf(stderr, "*** fi %p\t%s[%d]\n", fi, fi->Type, fi->fc);
01086
01087
01088
01089 if (fi->fc > 0) {
01090 fi->bnl = hfd(fi->bnl, -1);
01091 fi->dnl = hfd(fi->dnl, -1);
01092
01093 fi->flinks = hfd(fi->flinks, -1);
01094 fi->flangs = hfd(fi->flangs, -1);
01095 fi->fmd5s = hfd(fi->fmd5s, -1);
01096 fi->md5s = _free(fi->md5s);
01097
01098 fi->cdict = hfd(fi->cdict, -1);
01099
01100 fi->fuser = hfd(fi->fuser, -1);
01101 fi->fgroup = hfd(fi->fgroup, -1);
01102
01103 fi->fstates = _free(fi->fstates);
01104
01105
01106 if (!fi->keep_header && fi->h == NULL) {
01107 fi->fmtimes = _free(fi->fmtimes);
01108 fi->fmodes = _free(fi->fmodes);
01109 fi->fflags = _free(fi->fflags);
01110 fi->vflags = _free(fi->vflags);
01111 fi->fsizes = _free(fi->fsizes);
01112 fi->frdevs = _free(fi->frdevs);
01113 fi->finodes = _free(fi->finodes);
01114 fi->dil = _free(fi->dil);
01115
01116 fi->fcolors = _free(fi->fcolors);
01117 fi->fcdictx = _free(fi->fcdictx);
01118 fi->ddict = _free(fi->ddict);
01119 fi->fddictx = _free(fi->fddictx);
01120 fi->fddictn = _free(fi->fddictn);
01121
01122 }
01123
01124 }
01125
01126
01127 fi->fsm = freeFSM(fi->fsm);
01128
01129 fi->fn = _free(fi->fn);
01130 fi->apath = _free(fi->apath);
01131 fi->fmapflags = _free(fi->fmapflags);
01132
01133 fi->obnl = hfd(fi->obnl, -1);
01134 fi->odnl = hfd(fi->odnl, -1);
01135
01136 fi->actions = _free(fi->actions);
01137 fi->replacedSizes = _free(fi->replacedSizes);
01138 fi->replaced = _free(fi->replaced);
01139
01140 fi->h = headerFree(fi->h);
01141
01142
01143 (void) rpmfiUnlink(fi, fi->Type);
01144 memset(fi, 0, sizeof(*fi));
01145 fi = _free(fi);
01146
01147
01148 return NULL;
01149 }
01150
01156 static inline unsigned char nibble(char c)
01157
01158 {
01159 if (c >= '0' && c <= '9')
01160 return (c - '0');
01161 if (c >= 'A' && c <= 'F')
01162 return (c - 'A') + 10;
01163 if (c >= 'a' && c <= 'f')
01164 return (c - 'a') + 10;
01165 return 0;
01166 }
01167
01168 #define _fdupe(_fi, _data) \
01169 if ((_fi)->_data != NULL) \
01170 (_fi)->_data = memcpy(xmalloc((_fi)->fc * sizeof(*(_fi)->_data)), \
01171 (_fi)->_data, (_fi)->fc * sizeof(*(_fi)->_data))
01172
01173 rpmfi rpmfiNew(rpmts ts, Header h, rpmTag tagN, int scareMem)
01174 {
01175 HGE_t hge =
01176 (scareMem ? (HGE_t) headerGetEntryMinMemory : (HGE_t) headerGetEntry);
01177 HFD_t hfd = headerFreeData;
01178 rpmte p;
01179 rpmfi fi = NULL;
01180 const char * Type;
01181 uint_32 * uip;
01182 int dnlmax, bnlmax;
01183 unsigned char * t;
01184 int len;
01185 int xx;
01186 int i;
01187
01188 if (tagN == RPMTAG_BASENAMES) {
01189 Type = "Files";
01190 } else {
01191 Type = "?Type?";
01192 goto exit;
01193 }
01194
01195 fi = xcalloc(1, sizeof(*fi));
01196 if (fi == NULL)
01197 goto exit;
01198
01199 fi->magic = RPMFIMAGIC;
01200 fi->Type = Type;
01201 fi->i = -1;
01202 fi->tagN = tagN;
01203
01204 fi->hge = hge;
01205 fi->hae = (HAE_t) headerAddEntry;
01206 fi->hme = (HME_t) headerModifyEntry;
01207 fi->hre = (HRE_t) headerRemoveEntry;
01208 fi->hfd = headerFreeData;
01209
01210 fi->h = (scareMem ? headerLink(h) : NULL);
01211
01212 if (fi->fsm == NULL)
01213 fi->fsm = newFSM();
01214
01215
01216 xx = hge(h, RPMTAG_ARCHIVESIZE, NULL, (void **) &uip, NULL);
01217 fi->archivePos = 0;
01218 fi->archiveSize = (xx ? *uip : 0);
01219
01220 if (!hge(h, RPMTAG_BASENAMES, NULL, (void **) &fi->bnl, &fi->fc)) {
01221 fi->fc = 0;
01222 fi->dc = 0;
01223 goto exit;
01224 }
01225 xx = hge(h, RPMTAG_DIRNAMES, NULL, (void **) &fi->dnl, &fi->dc);
01226 xx = hge(h, RPMTAG_DIRINDEXES, NULL, (void **) &fi->dil, NULL);
01227 xx = hge(h, RPMTAG_FILEMODES, NULL, (void **) &fi->fmodes, NULL);
01228 xx = hge(h, RPMTAG_FILEFLAGS, NULL, (void **) &fi->fflags, NULL);
01229 xx = hge(h, RPMTAG_FILEVERIFYFLAGS, NULL, (void **) &fi->vflags, NULL);
01230 xx = hge(h, RPMTAG_FILESIZES, NULL, (void **) &fi->fsizes, NULL);
01231
01232 xx = hge(h, RPMTAG_FILECOLORS, NULL, (void **) &fi->fcolors, NULL);
01233 fi->color = 0;
01234 if (fi->fcolors != NULL)
01235 for (i = 0; i < fi->fc; i++)
01236 fi->color |= fi->fcolors[i];
01237 xx = hge(h, RPMTAG_CLASSDICT, NULL, (void **) &fi->cdict, &fi->ncdict);
01238 xx = hge(h, RPMTAG_FILECLASS, NULL, (void **) &fi->fcdictx, NULL);
01239
01240 xx = hge(h, RPMTAG_DEPENDSDICT, NULL, (void **) &fi->ddict, &fi->nddict);
01241 xx = hge(h, RPMTAG_FILEDEPENDSX, NULL, (void **) &fi->fddictx, NULL);
01242 xx = hge(h, RPMTAG_FILEDEPENDSN, NULL, (void **) &fi->fddictn, NULL);
01243
01244 xx = hge(h, RPMTAG_FILESTATES, NULL, (void **) &fi->fstates, NULL);
01245 if (xx == 0 || fi->fstates == NULL)
01246 fi->fstates = xcalloc(fi->fc, sizeof(*fi->fstates));
01247 else
01248 _fdupe(fi, fstates);
01249
01250 fi->action = FA_UNKNOWN;
01251 fi->flags = 0;
01252
01253 if (fi->actions == NULL)
01254 fi->actions = xcalloc(fi->fc, sizeof(*fi->actions));
01255
01256 fi->keep_header = (scareMem ? 1 : 0);
01257
01258
01259 fi->mapflags =
01260 CPIO_MAP_PATH | CPIO_MAP_MODE | CPIO_MAP_UID | CPIO_MAP_GID;
01261
01262 xx = hge(h, RPMTAG_FILELINKTOS, NULL, (void **) &fi->flinks, NULL);
01263 xx = hge(h, RPMTAG_FILELANGS, NULL, (void **) &fi->flangs, NULL);
01264
01265 fi->fmd5s = NULL;
01266 xx = hge(h, RPMTAG_FILEMD5S, NULL, (void **) &fi->fmd5s, NULL);
01267
01268 fi->md5s = NULL;
01269 if (fi->fmd5s) {
01270 t = xmalloc(fi->fc * 16);
01271 fi->md5s = t;
01272 for (i = 0; i < fi->fc; i++) {
01273 const char * fmd5;
01274 int j;
01275
01276 fmd5 = fi->fmd5s[i];
01277 if (!(fmd5 && *fmd5 != '\0')) {
01278 memset(t, 0, 16);
01279 t += 16;
01280 continue;
01281 }
01282 for (j = 0; j < 16; j++, t++, fmd5 += 2)
01283 *t = (nibble(fmd5[0]) << 4) | nibble(fmd5[1]);
01284 }
01285 fi->fmd5s = hfd(fi->fmd5s, -1);
01286 }
01287
01288
01289 xx = hge(h, RPMTAG_FILEMTIMES, NULL, (void **) &fi->fmtimes, NULL);
01290 xx = hge(h, RPMTAG_FILERDEVS, NULL, (void **) &fi->frdevs, NULL);
01291 xx = hge(h, RPMTAG_FILEINODES, NULL, (void **) &fi->finodes, NULL);
01292
01293 fi->replacedSizes = xcalloc(fi->fc, sizeof(*fi->replacedSizes));
01294
01295 xx = hge(h, RPMTAG_FILEUSERNAME, NULL, (void **) &fi->fuser, NULL);
01296 xx = hge(h, RPMTAG_FILEGROUPNAME, NULL, (void **) &fi->fgroup, NULL);
01297
01298 if (ts != NULL)
01299 if (fi != NULL)
01300 if ((p = rpmtsRelocateElement(ts)) != NULL && rpmteType(p) == TR_ADDED
01301 && !headerIsEntry(h, RPMTAG_SOURCEPACKAGE)
01302 && !headerIsEntry(h, RPMTAG_ORIGBASENAMES))
01303 {
01304 const char * fmt = rpmGetPath("%{?_autorelocate_path}", NULL);
01305 const char * errstr;
01306 char * newPath;
01307 Header foo;
01308
01309
01310 newPath = headerSprintf(h, fmt, rpmTagTable, rpmHeaderFormats, &errstr);
01311 fmt = _free(fmt);
01312
01313 #if __ia64__
01314
01315 if (newPath != NULL && *newPath != '\0'
01316 && strlen(newPath) >= (sizeof("/emul/i386")-1)
01317 && newPath[0] == '/' && newPath[1] == 'e' && newPath[2] == 'm'
01318 && newPath[3] == 'u' && newPath[4] == 'l' && newPath[5] == '/'
01319 && newPath[6] == 'i' && newPath[8] == '8' && newPath[9] == '6')
01320 {
01321 newPath[7] = 'a';
01322 newPath[8] = '3';
01323 newPath[9] = '2';
01324 }
01325 #endif
01326
01327
01328 i = p->nrelocs;
01329 if (newPath != NULL && *newPath != '\0' && p->relocs != NULL)
01330 for (i = 0; i < p->nrelocs; i++) {
01331
01332 if (strcmp(p->relocs[i].oldPath, "/"))
01333 continue;
01334 if (strcmp(p->relocs[i].newPath, newPath))
01335 continue;
01336
01337 break;
01338 }
01339
01340
01341 if (newPath != NULL && *newPath != '\0' && i == p->nrelocs
01342 && p->archScore == 0)
01343 {
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 }