3 * Routines to handle file info tag sets.
8 #include <rpmio_internal.h>
11 #include "cpio.h" /* XXX CPIO_FOO */
12 #include "fsm.h" /* XXX newFSM() */
14 #define _RPMFI_INTERNAL
17 #define _RPMTE_INTERNAL /* relocations */
21 #include "misc.h" /* XXX stripTrailingChar */
30 rpmfi XrpmfiUnlink(rpmfi fi, const char * msg, const char * fn, unsigned ln)
32 if (fi == NULL) return NULL;
34 if (_rpmfi_debug && msg != NULL)
35 fprintf(stderr, "--> fi %p -- %d %s at %s:%u\n", fi, fi->nrefs, msg, fn, ln);
41 rpmfi XrpmfiLink(rpmfi fi, const char * msg, const char * fn, unsigned ln)
43 if (fi == NULL) return NULL;
46 if (_rpmfi_debug && msg != NULL)
47 fprintf(stderr, "--> fi %p ++ %d %s at %s:%u\n", fi, fi->nrefs, msg, fn, ln);
49 /*@-refcounttrans@*/ return fi; /*@=refcounttrans@*/
54 return (fi != NULL ? fi->fc : 0);
59 return (fi != NULL ? fi->dc : 0);
70 return (fi != NULL ? fi->i : -1);
73 int rpmfiSetFX(rpmfi fi, int fx)
77 if (fi != NULL && fx >= 0 && fx < fi->fc) {
81 fi->j = fi->dil[fi->i];
89 return (fi != NULL ? fi->j : -1);
92 int rpmfiSetDX(rpmfi fi, int dx)
96 if (fi != NULL && dx >= 0 && dx < fi->dc) {
103 const char * rpmfiBN(rpmfi fi)
105 const char * BN = NULL;
107 if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
116 const char * rpmfiDN(rpmfi fi)
118 const char * DN = NULL;
120 if (fi != NULL && fi->j >= 0 && fi->j < fi->dc) {
129 const char * rpmfiFN(rpmfi fi)
131 const char * FN = "";
134 if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
137 fi->fn = xmalloc(fi->fnlen);
141 t = stpcpy(t, fi->dnl[fi->dil[fi->i]]);
142 t = stpcpy(t, fi->bnl[fi->i]);
149 int_32 rpmfiFFlags(rpmfi fi)
153 if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
155 if (fi->fflags != NULL)
156 FFlags = fi->fflags[fi->i];
162 int_32 rpmfiVFlags(rpmfi fi)
166 if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
168 if (fi->vflags != NULL)
169 VFlags = fi->vflags[fi->i];
175 int_16 rpmfiFMode(rpmfi fi)
179 if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
181 if (fi->fmodes != NULL)
182 fmode = fi->fmodes[fi->i];
188 rpmfileState rpmfiFState(rpmfi fi)
190 rpmfileState fstate = RPMFILE_STATE_MISSING;
192 if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
194 if (fi->fstates != NULL)
195 fstate = fi->fstates[fi->i];
201 const unsigned char * rpmfiMD5(rpmfi fi)
203 unsigned char * MD5 = NULL;
205 if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
207 if (fi->md5s != NULL)
208 MD5 = fi->md5s + (16 * fi->i);
214 const char * rpmfiFLink(rpmfi fi)
216 const char * flink = NULL;
218 if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
220 if (fi->flinks != NULL)
221 flink = fi->flinks[fi->i];
227 int_32 rpmfiFSize(rpmfi fi)
231 if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
233 if (fi->fsizes != NULL)
234 fsize = fi->fsizes[fi->i];
240 int_16 rpmfiFRdev(rpmfi fi)
244 if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
246 if (fi->frdevs != NULL)
247 frdev = fi->frdevs[fi->i];
253 int_32 rpmfiFInode(rpmfi fi)
257 if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
259 if (fi->finodes != NULL)
260 finode = fi->finodes[fi->i];
266 int_32 rpmfiFNlink(rpmfi fi)
270 if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
271 /* XXX rpm-2.3.12 has not RPMTAG_FILEINODES */
273 if (fi->finodes && fi->frdevs) {
274 int_32 finode = fi->finodes[fi->i];
275 int_16 frdev = fi->frdevs[fi->i];
278 for (j = 0; j < fi->fc; j++) {
279 if (fi->frdevs[j] == frdev && fi->finodes[j] == finode)
288 int_32 rpmfiFMtime(rpmfi fi)
292 if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
294 if (fi->fmtimes != NULL)
295 fmtime = fi->fmtimes[fi->i];
301 const char * rpmfiFUser(rpmfi fi)
303 const char * fuser = NULL;
305 /* XXX add support for ancient RPMTAG_FILEUIDS? */
306 if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
308 if (fi->fuser != NULL)
309 fuser = fi->fuser[fi->i];
315 const char * rpmfiFGroup(rpmfi fi)
317 const char * fgroup = NULL;
319 /* XXX add support for ancient RPMTAG_FILEGIDS? */
320 if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
322 if (fi->fgroup != NULL)
323 fgroup = fi->fgroup[fi->i];
329 int rpmfiNext(rpmfi fi)
333 if (fi != NULL && ++fi->i >= 0) {
334 if (fi->i < fi->fc) {
338 fi->j = fi->dil[fi->i];
343 /*@-modfilesystem @*/
344 if (_rpmfi_debug < 0 && i != -1)
345 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] : ""));
346 /*@=modfilesystem @*/
353 rpmfi rpmfiInit(rpmfi fi, int fx)
356 if (fx >= 0 && fx < fi->fc) {
367 int rpmfiNextD(rpmfi fi)
371 if (fi != NULL && ++fi->j >= 0) {
377 /*@-modfilesystem @*/
378 if (_rpmfi_debug < 0 && j != -1)
379 fprintf(stderr, "*** fi %p\t%s[%d]\n", fi, (fi->Type ? fi->Type : "?Type?"), j);
380 /*@=modfilesystem @*/
387 rpmfi rpmfiInitD(rpmfi fi, int dx)
390 if (dx >= 0 && dx < fi->fc)
402 * Identify a file type.
403 * @param ft file type
404 * @return string to identify a file type
406 static /*@observer@*/
407 const char *const ftstring (fileTypes ft)
411 case XDIR: return "directory";
412 case CDEV: return "char dev";
413 case BDEV: return "block dev";
414 case LINK: return "link";
415 case SOCK: return "sock";
416 case PIPE: return "fifo/pipe";
417 case REG: return "file";
418 default: return "unknown file type";
423 fileTypes whatis(uint_16 mode)
425 if (S_ISDIR(mode)) return XDIR;
426 if (S_ISCHR(mode)) return CDEV;
427 if (S_ISBLK(mode)) return BDEV;
428 if (S_ISLNK(mode)) return LINK;
430 if (S_ISSOCK(mode)) return SOCK;
432 if (S_ISFIFO(mode)) return PIPE;
437 const char *const rpmfiTypeString(rpmfi fi)
439 switch(rpmteType(fi->te)) {
440 case TR_ADDED: return " install";
441 case TR_REMOVED: return " erase";
442 default: return "???";
447 #define alloca_strdup(_s) strcpy(alloca(strlen(_s)+1), (_s))
450 * Relocate files in header.
451 * @todo multilib file dispositions need to be checked.
452 * @param ts transaction set
453 * @param fi transaction element file info
454 * @param origH package header
455 * @param actions file dispositions
456 * @return header with relocated files
460 Header relocateFileList(const rpmts ts, rpmfi fi,
461 Header origH, fileAction * actions)
462 /*@modifies ts, fi, origH, actions @*/
468 HFD_t hfd = (fi->hfd ? fi->hfd : headerFreeData);
469 static int _printed = 0;
470 int allowBadRelocate = (rpmtsFilterFlags(ts) & RPMPROB_FILTER_FORCERELOCATE);
471 rpmRelocation * relocations = NULL;
473 const char ** validRelocations;
474 rpmTagType validType;
476 const char ** baseNames;
477 const char ** dirNames;
479 int_32 * newDirIndexes;
482 uint_32 * fFlags = NULL;
483 uint_16 * fModes = NULL;
489 int haveRelocatedFile = 0;
494 if (!hge(origH, RPMTAG_PREFIXES, &validType,
495 (void **) &validRelocations, &numValid))
500 while (p->relocs[numRelocations].newPath ||
501 p->relocs[numRelocations].oldPath)
505 * If no relocations are specified (usually the case), then return the
506 * original header. If there are prefixes, however, then INSTPREFIXES
507 * should be added, but, since relocateFileList() can be called more
508 * than once for the same header, don't bother if already present.
510 if (p->relocs == NULL || numRelocations == 0) {
512 if (!headerIsEntry(origH, RPMTAG_INSTPREFIXES))
513 xx = hae(origH, RPMTAG_INSTPREFIXES,
514 validType, validRelocations, numValid);
515 validRelocations = hfd(validRelocations, validType);
517 /* XXX FIXME multilib file actions need to be checked. */
518 return headerLink(origH);
521 h = headerLink(origH);
523 relocations = alloca(sizeof(*relocations) * numRelocations);
525 /* Build sorted relocation list from raw relocations. */
526 for (i = 0; i < numRelocations; i++) {
530 * Default relocations (oldPath == NULL) are handled in the UI,
533 if (p->relocs[i].oldPath == NULL) continue; /* XXX can't happen */
535 /* FIXME: Trailing /'s will confuse us greatly. Internal ones will
536 too, but those are more trouble to fix up. :-( */
537 t = alloca_strdup(p->relocs[i].oldPath);
539 relocations[i].oldPath = (t[0] == '/' && t[1] == '\0')
541 : stripTrailingChar(t, '/');
544 /* An old path w/o a new path is valid, and indicates exclusion */
545 if (p->relocs[i].newPath) {
548 t = alloca_strdup(p->relocs[i].newPath);
550 relocations[i].newPath = (t[0] == '/' && t[1] == '\0')
552 : stripTrailingChar(t, '/');
555 /*@-nullpass@*/ /* FIX: relocations[i].oldPath == NULL */
556 /* Verify that the relocation's old path is in the header. */
557 for (j = 0; j < numValid; j++) {
558 if (!strcmp(validRelocations[j], relocations[i].oldPath))
559 /*@innerbreak@*/ break;
562 /* XXX actions check prevents problem from being appended twice. */
563 if (j == numValid && !allowBadRelocate && actions) {
564 rpmps ps = rpmtsProblems(ts);
565 rpmpsAppend(ps, RPMPROB_BADRELOCATE,
566 rpmteNEVR(p), rpmteKey(p),
567 relocations[i].oldPath, NULL, NULL, 0);
571 strlen(relocations[i].newPath) - strlen(relocations[i].oldPath);
577 relocations[i].newPath = NULL;
581 /* stupid bubble sort, but it's probably faster here */
582 for (i = 0; i < numRelocations; i++) {
585 for (j = 1; j < numRelocations; j++) {
586 rpmRelocation tmpReloc;
587 if (relocations[j - 1].oldPath == NULL || /* XXX can't happen */
588 relocations[j ].oldPath == NULL || /* XXX can't happen */
589 strcmp(relocations[j - 1].oldPath, relocations[j].oldPath) <= 0)
590 /*@innercontinue@*/ continue;
591 /*@-usereleased@*/ /* LCL: ??? */
592 tmpReloc = relocations[j - 1];
593 relocations[j - 1] = relocations[j];
594 relocations[j] = tmpReloc;
598 if (!madeSwap) break;
603 rpmMessage(RPMMESS_DEBUG, _("========== relocations\n"));
604 for (i = 0; i < numRelocations; i++) {
605 if (relocations[i].oldPath == NULL) continue; /* XXX can't happen */
606 if (relocations[i].newPath == NULL)
607 rpmMessage(RPMMESS_DEBUG, _("%5d exclude %s\n"),
608 i, relocations[i].oldPath);
610 rpmMessage(RPMMESS_DEBUG, _("%5d relocate %s -> %s\n"),
611 i, relocations[i].oldPath, relocations[i].newPath);
615 /* Add relocation values to the header */
617 const char ** actualRelocations;
620 actualRelocations = xmalloc(numValid * sizeof(*actualRelocations));
622 for (i = 0; i < numValid; i++) {
623 for (j = 0; j < numRelocations; j++) {
624 if (relocations[j].oldPath == NULL || /* XXX can't happen */
625 strcmp(validRelocations[i], relocations[j].oldPath))
626 /*@innercontinue@*/ continue;
627 /* On install, a relocate to NULL means skip the path. */
628 if (relocations[j].newPath) {
629 actualRelocations[numActual] = relocations[j].newPath;
632 /*@innerbreak@*/ break;
634 if (j == numRelocations) {
635 actualRelocations[numActual] = validRelocations[i];
641 xx = hae(h, RPMTAG_INSTPREFIXES, RPM_STRING_ARRAY_TYPE,
642 (void **) actualRelocations, numActual);
644 actualRelocations = _free(actualRelocations);
645 validRelocations = hfd(validRelocations, validType);
648 xx = hge(h, RPMTAG_BASENAMES, NULL, (void **) &baseNames, &fileCount);
649 xx = hge(h, RPMTAG_DIRINDEXES, NULL, (void **) &dirIndexes, NULL);
650 xx = hge(h, RPMTAG_DIRNAMES, NULL, (void **) &dirNames, &dirCount);
651 xx = hge(h, RPMTAG_FILEFLAGS, NULL, (void **) &fFlags, NULL);
652 xx = hge(h, RPMTAG_FILEMODES, NULL, (void **) &fModes, NULL);
654 skipDirList = alloca(dirCount * sizeof(*skipDirList));
655 memset(skipDirList, 0, dirCount * sizeof(*skipDirList));
657 newDirIndexes = alloca(sizeof(*newDirIndexes) * fileCount);
658 memcpy(newDirIndexes, dirIndexes, sizeof(*newDirIndexes) * fileCount);
659 dirIndexes = newDirIndexes;
662 * For all relocations, we go through sorted file/relocation lists
663 * backwards so that /usr/local relocations take precedence over /usr
667 /* Relocate individual paths. */
669 for (i = fileCount - 1; i >= 0; i--) {
674 * If only adding libraries of different arch into an already
675 * installed package, skip all other files.
677 if (rpmteMultiLib(p) && !isFileMULTILIB((fFlags[i]))) {
679 actions[i] = FA_SKIPMULTILIB;
680 rpmMessage(RPMMESS_DEBUG, _("excluding multilib path %s%s\n"),
681 dirNames[dirIndexes[i]], baseNames[i]);
687 strlen(dirNames[dirIndexes[i]]) + strlen(baseNames[i]) + 1;
689 if (len >= fileAlloced) {
690 fileAlloced = len * 2;
691 fn = xrealloc(fn, fileAlloced);
695 fnlen = stpcpy( stpcpy(fn, dirNames[dirIndexes[i]]), baseNames[i]) - fn;
698 * See if this file path needs relocating.
701 * XXX FIXME: Would a bsearch of the (already sorted)
702 * relocation list be a good idea?
704 for (j = numRelocations - 1; j >= 0; j--) {
705 if (relocations[j].oldPath == NULL) /* XXX can't happen */
706 /*@innercontinue@*/ continue;
707 len = strcmp(relocations[j].oldPath, "/")
708 ? strlen(relocations[j].oldPath)
712 /*@innercontinue@*/ continue;
714 * Only subdirectories or complete file paths may be relocated. We
715 * don't check for '\0' as our directory names all end in '/'.
717 if (!(fn[len] == '/' || fnlen == len))
718 /*@innercontinue@*/ continue;
720 if (strncmp(relocations[j].oldPath, fn, len))
721 /*@innercontinue@*/ continue;
722 /*@innerbreak@*/ break;
726 ft = whatis(fModes[i]);
728 /* On install, a relocate to NULL means skip the path. */
729 if (relocations[j].newPath == NULL) {
731 /* Start with the parent, looking for directory to exclude. */
732 for (j = dirIndexes[i]; j < dirCount; j++) {
733 len = strlen(dirNames[j]) - 1;
734 while (len > 0 && dirNames[j][len-1] == '/') len--;
736 /*@innercontinue@*/ continue;
737 if (strncmp(fn, dirNames[j], fnlen))
738 /*@innercontinue@*/ continue;
739 /*@innerbreak@*/ break;
745 actions[i] = FA_SKIPNSTATE;
746 rpmMessage(RPMMESS_DEBUG, _("excluding %s %s\n"),
752 /* Relocation on full paths only, please. */
753 if (fnlen != len) continue;
756 rpmMessage(RPMMESS_DEBUG, _("relocating %s to %s\n"),
757 fn, relocations[j].newPath);
760 strcpy(fn, relocations[j].newPath);
761 { char * te = strrchr(fn, '/');
763 if (te > fn) te++; /* root is special */
766 te = fn + strlen(fn);
767 /*@-nullpass -nullderef@*/ /* LCL: te != NULL here. */
768 if (strcmp(baseNames[i], te)) /* basename changed too? */
769 baseNames[i] = alloca_strdup(te);
770 *te = '\0'; /* terminate new directory name */
771 /*@=nullpass =nullderef@*/
774 /* Does this directory already exist in the directory list? */
775 for (j = 0; j < dirCount; j++) {
776 if (fnlen != strlen(dirNames[j]))
777 /*@innercontinue@*/ continue;
778 if (strncmp(fn, dirNames[j], fnlen))
779 /*@innercontinue@*/ continue;
780 /*@innerbreak@*/ break;
788 /* Creating new paths is a pita */
789 if (!haveRelocatedFile) {
790 const char ** newDirList;
792 haveRelocatedFile = 1;
793 newDirList = xmalloc((dirCount + 1) * sizeof(*newDirList));
794 for (j = 0; j < dirCount; j++)
795 newDirList[j] = alloca_strdup(dirNames[j]);
796 dirNames = hfd(dirNames, RPM_STRING_ARRAY_TYPE);
797 dirNames = newDirList;
799 dirNames = xrealloc(dirNames,
800 sizeof(*dirNames) * (dirCount + 1));
803 dirNames[dirCount] = alloca_strdup(fn);
804 dirIndexes[i] = dirCount;
808 /* Finish off by relocating directories. */
809 for (i = dirCount - 1; i >= 0; i--) {
810 for (j = numRelocations - 1; j >= 0; j--) {
812 if (relocations[j].oldPath == NULL) /* XXX can't happen */
813 /*@innercontinue@*/ continue;
814 len = strcmp(relocations[j].oldPath, "/")
815 ? strlen(relocations[j].oldPath)
818 if (len && strncmp(relocations[j].oldPath, dirNames[i], len))
819 /*@innercontinue@*/ continue;
822 * Only subdirectories or complete file paths may be relocated. We
823 * don't check for '\0' as our directory names all end in '/'.
825 if (dirNames[i][len] != '/')
826 /*@innercontinue@*/ continue;
828 if (relocations[j].newPath) { /* Relocate the path */
829 const char * s = relocations[j].newPath;
830 char * t = alloca(strlen(s) + strlen(dirNames[i]) - len + 1);
832 (void) stpcpy( stpcpy(t, s) , dirNames[i] + len);
834 rpmMessage(RPMMESS_DEBUG,
835 _("relocating directory %s to %s\n"), dirNames[i], t);
842 /* Save original filenames in header and replace (relocated) filenames. */
849 xx = hge(h, RPMTAG_BASENAMES, &t, &d, &c);
850 xx = hae(h, RPMTAG_ORIGBASENAMES, t, d, c);
854 xx = hge(h, RPMTAG_DIRNAMES, &t, &d, &c);
855 xx = hae(h, RPMTAG_ORIGDIRNAMES, t, d, c);
859 xx = hge(h, RPMTAG_DIRINDEXES, &t, &d, &c);
860 xx = hae(h, RPMTAG_ORIGDIRINDEXES, t, d, c);
863 xx = hme(h, RPMTAG_BASENAMES, RPM_STRING_ARRAY_TYPE,
864 baseNames, fileCount);
865 fi->bnl = hfd(fi->bnl, RPM_STRING_ARRAY_TYPE);
866 xx = hge(h, RPMTAG_BASENAMES, NULL, (void **) &fi->bnl, &fi->fc);
868 xx = hme(h, RPMTAG_DIRNAMES, RPM_STRING_ARRAY_TYPE,
870 fi->dnl = hfd(fi->dnl, RPM_STRING_ARRAY_TYPE);
871 xx = hge(h, RPMTAG_DIRNAMES, NULL, (void **) &fi->dnl, &fi->dc);
873 xx = hme(h, RPMTAG_DIRINDEXES, RPM_INT32_TYPE,
874 dirIndexes, fileCount);
875 xx = hge(h, RPMTAG_DIRINDEXES, NULL, (void **) &fi->dil, NULL);
878 baseNames = hfd(baseNames, RPM_STRING_ARRAY_TYPE);
879 dirNames = hfd(dirNames, RPM_STRING_ARRAY_TYPE);
886 rpmfi rpmfiFree(rpmfi fi, int freefimem)
888 HFD_t hfd = headerFreeData;
890 if (fi == NULL) return NULL;
893 return rpmfiUnlink(fi, fi->Type);
896 if (_rpmfi_debug < 0)
897 fprintf(stderr, "*** fi %p\t%s[%d]\n", fi, fi->Type, fi->fc);
902 fi->bnl = hfd(fi->bnl, -1);
903 fi->dnl = hfd(fi->dnl, -1);
905 fi->flinks = hfd(fi->flinks, -1);
906 fi->flangs = hfd(fi->flangs, -1);
907 fi->fmd5s = hfd(fi->fmd5s, -1);
908 fi->md5s = _free(fi->md5s);
910 fi->fuser = hfd(fi->fuser, -1);
911 fi->fuids = _free(fi->fuids);
912 fi->fgroup = hfd(fi->fgroup, -1);
913 fi->fgids = _free(fi->fgids);
915 fi->fstates = _free(fi->fstates);
918 if (!fi->keep_header && fi->h == NULL) {
919 fi->fmtimes = _free(fi->fmtimes);
920 fi->fmodes = _free(fi->fmodes);
921 fi->fflags = _free(fi->fflags);
922 fi->vflags = _free(fi->vflags);
923 fi->fsizes = _free(fi->fsizes);
924 fi->frdevs = _free(fi->frdevs);
925 fi->finodes = _free(fi->finodes);
926 fi->dil = _free(fi->dil);
932 fi->fsm = freeFSM(fi->fsm);
934 fi->fn = _free(fi->fn);
935 fi->apath = _free(fi->apath);
936 fi->fmapflags = _free(fi->fmapflags);
938 fi->obnl = hfd(fi->obnl, -1);
939 fi->odnl = hfd(fi->odnl, -1);
941 fi->actions = _free(fi->actions);
942 fi->replacedSizes = _free(fi->replacedSizes);
943 fi->replaced = _free(fi->replaced);
945 fi->h = headerFree(fi->h);
947 /*@-nullstate -refcounttrans -usereleased@*/
948 (void) rpmfiUnlink(fi, fi->Type);
951 memset(fi, 0, sizeof(*fi)); /* XXX trash and burn */
955 /*@=nullstate =refcounttrans =usereleased@*/
961 * Convert hex to binary nibble.
962 * @param c hex character
963 * @return binary nibble
965 static inline unsigned char nibble(char c)
968 if (c >= '0' && c <= '9')
970 if (c >= 'A' && c <= 'F')
971 return (c - 'A') + 10;
972 if (c >= 'a' && c <= 'f')
973 return (c - 'a') + 10;
977 #define _fdupe(_fi, _data) \
978 if ((_fi)->_data != NULL) \
979 (_fi)->_data = memcpy(xmalloc((_fi)->fc * sizeof(*(_fi)->_data)), \
980 (_fi)->_data, (_fi)->fc * sizeof(*(_fi)->_data))
982 rpmfi rpmfiNew(rpmts ts, rpmfi fi,
983 Header h, rpmTag tagN, int scareMem)
986 (scareMem ? (HGE_t) headerGetEntryMinMemory : (HGE_t) headerGetEntry);
987 HFD_t hfd = headerFreeData;
997 if (tagN == RPMTAG_BASENAMES) {
1006 fi = xcalloc(1, sizeof(*fi));
1007 malloced = 0; /* XXX always return with memory alloced. */
1011 fi->magic = RPMFIMAGIC;
1017 fi->hae = (HAE_t) headerAddEntry;
1018 fi->hme = (HME_t) headerModifyEntry;
1019 fi->hre = (HRE_t) headerRemoveEntry;
1020 fi->hfd = headerFreeData;
1022 fi->h = (scareMem ? headerLink(h) : NULL);
1024 if (fi->fsm == NULL)
1027 /* 0 means unknown */
1028 xx = hge(h, RPMTAG_ARCHIVESIZE, NULL, (void **) &uip, NULL);
1030 fi->archiveSize = (xx ? *uip : 0);
1032 if (!hge(h, RPMTAG_BASENAMES, NULL, (void **) &fi->bnl, &fi->fc)) {
1035 if (scareMem && fi->h)
1036 fi->h = headerFree(fi->h);
1037 fi->fsm = freeFSM(fi->fsm);
1038 /*@-refcounttrans@*/
1040 /*@=refcounttrans@*/
1048 xx = hge(h, RPMTAG_DIRNAMES, NULL, (void **) &fi->dnl, &fi->dc);
1049 xx = hge(h, RPMTAG_DIRINDEXES, NULL, (void **) &fi->dil, NULL);
1050 xx = hge(h, RPMTAG_FILEMODES, NULL, (void **) &fi->fmodes, NULL);
1051 xx = hge(h, RPMTAG_FILEFLAGS, NULL, (void **) &fi->fflags, NULL);
1052 xx = hge(h, RPMTAG_FILEVERIFYFLAGS, NULL, (void **) &fi->vflags, NULL);
1053 xx = hge(h, RPMTAG_FILESIZES, NULL, (void **) &fi->fsizes, NULL);
1054 xx = hge(h, RPMTAG_FILESTATES, NULL, (void **) &fi->fstates, NULL);
1055 if (xx == 0 || fi->fstates == NULL)
1056 fi->fstates = xcalloc(fi->fc, sizeof(*fi->fstates));
1058 _fdupe(fi, fstates);
1060 fi->action = FA_UNKNOWN;
1063 if (fi->actions == NULL)
1064 fi->actions = xcalloc(fi->fc, sizeof(*fi->actions));
1066 fi->keep_header = (scareMem ? 1 : 0);
1068 /* XXX TR_REMOVED needs CPIO_MAP_{ABSOLUTE,ADDDOT} CPIO_ALL_HARDLINKS */
1070 CPIO_MAP_PATH | CPIO_MAP_MODE | CPIO_MAP_UID | CPIO_MAP_GID;
1072 xx = hge(h, RPMTAG_FILELINKTOS, NULL, (void **) &fi->flinks, NULL);
1073 xx = hge(h, RPMTAG_FILELANGS, NULL, (void **) &fi->flangs, NULL);
1075 xx = hge(h, RPMTAG_FILEMD5S, NULL, (void **) &fi->fmd5s, NULL);
1077 t = xmalloc(fi->fc * 16);
1079 for (i = 0; i < fi->fc; i++) {
1083 fmd5 = fi->fmd5s[i];
1084 if (!(fmd5 && *fmd5 != '\0')) {
1089 for (j = 0; j < 16; j++, t++, fmd5 += 2)
1090 *t = (nibble(fmd5[0]) << 4) | nibble(fmd5[1]);
1092 fi->fmd5s = hfd(fi->fmd5s, -1);
1094 /* XXX TR_REMOVED doesn;t need fmtimes, frdevs or finodes */
1095 xx = hge(h, RPMTAG_FILEMTIMES, NULL, (void **) &fi->fmtimes, NULL);
1096 xx = hge(h, RPMTAG_FILERDEVS, NULL, (void **) &fi->frdevs, NULL);
1097 xx = hge(h, RPMTAG_FILEINODES, NULL, (void **) &fi->finodes, NULL);
1099 fi->replacedSizes = xcalloc(fi->fc, sizeof(*fi->replacedSizes));
1101 xx = hge(h, RPMTAG_FILEUSERNAME, NULL, (void **) &fi->fuser, NULL);
1103 xx = hge(h, RPMTAG_FILEGROUPNAME, NULL, (void **) &fi->fgroup, NULL);
1108 if (fi->te != NULL && rpmteType(fi->te) == TR_ADDED) {
1111 if (fi->actions == NULL)
1112 fi->actions = xcalloc(fi->fc, sizeof(*fi->actions));
1113 /*@-compdef@*/ /* FIX: fi-md5s undefined */
1114 foo = relocateFileList(ts, fi, h, fi->actions);
1116 fi->h = headerFree(fi->h);
1117 fi->h = headerLink(foo);
1118 foo = headerFree(foo);
1122 _fdupe(fi, fmtimes);
1124 _fdupe(fi, finodes);
1130 fi->h = headerFree(fi->h);
1134 for (i = 0; i < fi->dc; i++) {
1135 if ((len = strlen(fi->dnl[i])) > dnlmax)
1139 for (i = 0; i < fi->fc; i++) {
1140 if ((len = strlen(fi->bnl[i])) > bnlmax)
1143 fi->fnlen = dnlmax + bnlmax + 1;
1150 /*@-modfilesystem@*/
1151 if (_rpmfi_debug < 0)
1152 fprintf(stderr, "*** fi %p\t%s[%d]\n", fi, Type, (fi ? fi->fc : 0));
1153 /*@=modfilesystem@*/
1155 /*@-compdef -nullstate@*/ /* FIX: rpmfi null annotations */
1156 return rpmfiLink(fi, (fi ? fi->Type : NULL));
1157 /*@=compdef =nullstate@*/