13 #define _RPMDIR_INTERNAL
18 #define _RPMAV_INTERNAL
24 #define _FPRINT_INTERNAL
27 #define _IOSM_INTERNAL
28 #define _RPMFI_INTERNAL
34 #define _RPMTE_INTERNAL
81 for (t = s + strlen(s) - 1; *t == c && t >= s; t--)
89 return (fi != NULL ? fi->fc : 0);
94 return (fi != NULL ? fi->dc : 0);
105 return (fi != NULL ? fi->i : -1);
112 if (fi != NULL && fx >= 0 && fx < (
int)fi->fc) {
115 fi->j = fi->dil[fi->i];
122 return (fi != NULL ? fi->j : -1);
129 if (fi != NULL && dx >= 0 && dx < (
int)fi->dc) {
138 return (fi != NULL ? fi->isSource : 0);
143 const char * BN = NULL;
145 if (fi != NULL && fi->i >= 0 && fi->i < (
int)fi->fc) {
154 const char * DN = NULL;
156 if (fi != NULL && fi->j >= 0 && fi->j < (
int)fi->dc) {
165 const char * FN =
"";
167 if (fi != NULL && fi->i >= 0 && fi->i < (
int)fi->fc) {
171 fi->fn = (
char *)
xmalloc(fi->fnlen + 1);
173 (void)
urlPath(fi->dnl[fi->dil[fi->i]], &dn);
176 t =
stpcpy(t, fi->bnl[fi->i]);
185 if (fi->_fnbf == NULL) {
186 char * fn = (
char *)
alloca(fi->fnlen + 1);
187 static double e = 1.0e-4;
188 size_t n = (fi->fc > 10 ? fi->fc : 10);
196 for (i = 0; i < (int)fi->fc; i++) {
200 (void)
urlPath(fi->dnl[fi->dil[i]], &dn);
202 xx =
rpmbfAdd(bf, fn, (
size_t)(dn - fn));
214 return (fi ? fi->fnlen : 0);
221 if (fi != NULL && fi->i >= 0 && fi->i < (
int)fi->fc) {
222 if (fi->fflags != NULL)
223 FFlags = fi->fflags[fi->i];
232 if (fi != NULL && fi->i >= 0 && fi->i < (
int)fi->fc) {
233 if (fi->fflags != NULL && fi->h == NULL) {
234 oFFlags = fi->fflags[fi->i];
245 if (fi != NULL && fi->i >= 0 && fi->i < (
int)fi->fc) {
246 if (fi->vflags != NULL)
247 VFlags = fi->vflags[fi->i];
256 if (fi != NULL && fi->i >= 0 && fi->i < (
int)fi->fc) {
257 if (fi->vflags != NULL && fi->h == NULL) {
258 oVFlags = fi->vflags[fi->i];
269 if (fi != NULL && fi->i >= 0 && fi->i < (
int)fi->fc) {
270 if (fi->fmodes != NULL)
271 fmode = fi->fmodes[fi->i];
280 if (fi != NULL && fi->i >= 0 && fi->i < (
int)fi->fc) {
281 if (fi->fstates != NULL)
291 if (fi != NULL && fi->i >= 0 && fi->i < (
int)fi->fc) {
292 if (fi->fstates != NULL) {
293 ofstate = fi->fstates[fi->i];
294 fi->fstates[fi->i] = fstate;
302 unsigned char * digest = NULL;
304 if (fi != NULL && fi->i >= 0 && fi->i < (
int)fi->fc) {
305 if (fi->digests != NULL) {
306 digest = fi->digests + (fi->digestlen * fi->i);
308 *algop = (fi->fdigestalgos
309 ? fi->fdigestalgos[fi->i] : fi->digestalgo);
311 *lenp = fi->digestlen;
319 const char * flink = NULL;
321 if (fi != NULL && fi->i >= 0 && fi->i < (
int)fi->fc) {
322 if (fi->flinks != NULL)
323 flink = fi->flinks[fi->i];
332 if (fi != NULL && fi->i >= 0 && fi->i < (
int)fi->fc) {
333 if (fi->fsizes != NULL)
334 fsize = fi->fsizes[fi->i];
343 if (fi != NULL && fi->i >= 0 && fi->i < (
int)fi->fc) {
344 if (fi->frdevs != NULL)
345 frdev = fi->frdevs[fi->i];
354 if (fi != NULL && fi->i >= 0 && fi->i < (
int)fi->fc) {
355 if (fi->finodes != NULL)
356 finode = fi->finodes[fi->i];
367 color = fi->color & 0xf;
375 if (fi != NULL && fi->i >= 0 && fi->i < (
int)fi->fc) {
376 if (fi->fcolors != NULL)
378 fcolor = (fi->fcolors[fi->i] & 0x0f);
385 const char * fclass = NULL;
387 if (fi != NULL && fi->fcdictx != NULL && fi->i >= 0 && fi->i < (
int)fi->fc) {
388 int cdictx = fi->fcdictx[fi->i];
389 if (fi->cdict != NULL && cdictx >= 0 && cdictx < (
int)fi->ncdict)
390 fclass = fi->cdict[cdictx];
397 const char * fcontext = NULL;
399 if (fi != NULL && fi->i >= 0 && fi->i < (
int)fi->fc) {
400 if (fi->fcontexts != NULL)
401 fcontext = fi->fcontexts[fi->i];
412 if (fi != NULL && fi->i >= 0 && fi->i < (
int)fi->fc) {
413 if (fi->fddictn != NULL)
414 fddictn = fi->fddictn[fi->i];
415 if (fddictn > 0 && fi->fddictx != NULL)
416 fddictx = fi->fddictx[fi->i];
417 if (fi->ddict != NULL && fddictx >= 0 && (fddictx+fddictn) <= (
int)fi->nddict)
418 fddict = fi->ddict + fddictx;
431 if (fi != NULL && fi->i >= 0 && fi->i < (
int)fi->fc) {
433 if (fi->finodes && fi->frdevs) {
438 for (j = 0; j < (int)fi->fc; j++) {
439 if (fi->frdevs[j] == frdev && fi->finodes[j] == finode)
451 if (fi != NULL && fi->i >= 0 && fi->i < (
int)fi->fc) {
452 if (fi->fmtimes != NULL)
453 fmtime = fi->fmtimes[fi->i];
460 const char * fuser = NULL;
463 if (fi != NULL && fi->i >= 0 && fi->i < (
int)fi->fc) {
464 if (fi->fuser != NULL)
465 fuser = fi->fuser[fi->i];
472 const char * fgroup = NULL;
475 if (fi != NULL && fi->i >= 0 && fi->i < (
int)fi->fc) {
476 if (fi->fgroup != NULL)
477 fgroup = fi->fgroup[fi->i];
485 return (fi != NULL ? fi->_fnbf : NULL);
491 return (fi != NULL ? fi->exclude : NULL);
496 return (fi != NULL ? fi->nexclude : 0);
501 return (fi != NULL ? fi->include : NULL);
506 return (fi != NULL ? fi->ninclude : 0);
512 if (fi != NULL && fi->fps != NULL && ix >= 0 && ix < (
int)fi->fc) {
520 if (fi->fc > 0 && fi->fps == NULL) {
523 fpLookupList(fpc, fi->dnl, fi->bnl, fi->dil, fi->fc, fi->fps);
530 if (fi != NULL && ++fi->i >= 0) {
531 if (fi->i < (
int)fi->fc) {
534 fi->j = fi->dil[fi->i];
539 if (_rpmfi_debug < 0 && i != -1)
540 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] :
""));
551 if (fx >= 0 && fx < (
int)fi->fc) {
566 if (fi != NULL && ++fi->j >= 0) {
567 if (fi->j < (
int)fi->dc)
573 if (_rpmfi_debug < 0 && j != -1)
574 fprintf(stderr,
"*** fi %p\t%s[%d]\n", fi, (fi->Type ? fi->Type :
"?Type?"), j);
585 if (dx >= 0 && dx < (
int)fi->fc)
606 case XDIR:
return "directory";
607 case CDEV:
return "char dev";
608 case BDEV:
return "block dev";
609 case LINK:
return "link";
610 case SOCK:
return "sock";
611 case PIPE:
return "fifo/pipe";
612 case REG:
return "file";
613 default:
return "unknown file type";
626 if (S_ISDIR(mode))
return XDIR;
627 if (S_ISCHR(mode))
return CDEV;
628 if (S_ISBLK(mode))
return BDEV;
633 if (S_ISFIFO(mode))
return PIPE;
643 if (awhat != bwhat)
return 1;
648 if (alink == blink)
return 0;
649 if (alink == NULL)
return 1;
650 if (blink == NULL)
return -1;
651 return strcmp(alink, blink);
652 }
else if (awhat ==
REG) {
655 const unsigned char * adigest =
rpmfiDigest(afi, &aalgo, &alen);
658 const unsigned char * bdigest =
rpmfiDigest(bfi, &balgo, &blen);
660 if (!(aalgo == balgo && alen == blen))
662 if (adigest == bdigest)
return 0;
663 if (adigest == NULL)
return 1;
664 if (bdigest == NULL)
return -1;
665 return memcmp(adigest, bdigest, alen);
673 const char * fn =
rpmfiFN(nfi);
680 if (
Lstat(fn, &sb)) {
705 if (diskWhat != newWhat && dbWhat !=
REG && dbWhat !=
LINK)
707 else if (newWhat != dbWhat && diskWhat != dbWhat)
709 else if (dbWhat != newWhat)
711 else if (dbWhat !=
LINK && dbWhat !=
REG)
718 memset(buffer, 0,
sizeof(buffer));
722 const unsigned char * odigest;
725 const unsigned char * ndigest;
727 if (diskWhat ==
REG) {
729 if (
dodigest(oalgo, fn, (
unsigned char *)buffer, 0, NULL))
731 if (odigest && !memcmp(odigest, buffer, olen))
736 if (odigest && ndigest && oalgo == nalgo && olen == nlen
737 && !memcmp(odigest, ndigest, nlen))
741 const char * oFLink, * nFLink;
743 if (diskWhat ==
LINK) {
744 if (
Readlink(fn, buffer,
sizeof(buffer) - 1) == -1)
746 buffer[
sizeof(
buffer)-1] =
'\0';
747 if (oFLink && !strcmp(oFLink, buffer))
752 if (oFLink && nFLink && !strcmp(oFLink, nFLink))
772 default:
return "???";
777 #define alloca_strdup(_s) strcpy((char *)alloca(strlen(_s)+1), (_s))
798 static int _printed = 0;
802 const char ** validRelocations;
805 const char ** baseNames;
806 const char ** dirNames;
817 size_t fileAlloced = 0;
819 int haveRelocatedFile = 0;
828 validRelocations = he->
p.
argv;
836 while (p->relocs[numRelocations].newPath ||
837 p->relocs[numRelocations].oldPath)
846 if (p->relocs == NULL || numRelocations == 0) {
851 he->
p.
argv = validRelocations;
855 validRelocations =
_free(validRelocations);
870 for (i = 0; i < numRelocations; i++) {
877 if (p->relocs[i].oldPath == NULL)
continue;
882 relocations[
i].
oldPath = (t[0] ==
'/' && t[1] ==
'\0')
887 if (p->relocs[i].newPath) {
891 relocations[
i].
newPath = (t[0] ==
'/' && t[1] ==
'\0')
897 for (j = 0; j < numValid; j++) {
898 if (!strcmp(validRelocations[j], relocations[i].oldPath))
903 if (j == numValid && !allowBadRelocate && actions) {
907 relocations[i].oldPath, NULL, NULL, 0);
911 (int)strlen(relocations[i].newPath) - (int)strlen(relocations[i].oldPath);
922 for (i = 0; i < numRelocations; i++) {
925 for (j = 1; j < numRelocations; j++) {
927 if (relocations[j - 1].
oldPath == NULL ||
928 relocations[j ].
oldPath == NULL ||
932 tmpReloc = relocations[j - 1];
933 relocations[j - 1] = relocations[
j];
934 relocations[
j] = tmpReloc;
938 if (!madeSwap)
break;
944 for (i = 0; i < numRelocations; i++) {
945 if (relocations[i].
oldPath == NULL)
continue;
946 if (relocations[i].
newPath == NULL)
951 i, relocations[i].oldPath, relocations[i].
newPath);
957 const char ** actualRelocations;
960 actualRelocations = (
const char **)
xmalloc(numValid *
sizeof(*actualRelocations));
962 for (i = 0; i < numValid; i++) {
963 for (j = 0; j < numRelocations; j++) {
964 if (relocations[j].
oldPath == NULL ||
965 strcmp(validRelocations[i], relocations[j].
oldPath))
969 actualRelocations[numActual] = relocations[
j].
newPath;
974 if (j == numRelocations) {
975 actualRelocations[numActual] = validRelocations[
i];
983 he->
p.
argv = actualRelocations;
988 actualRelocations =
_free(actualRelocations);
989 validRelocations =
_free(validRelocations);
994 baseNames = he->
p.
argv;
1001 dirNames = he->
p.
argv;
1014 memset(dColors, 0, dirCount *
sizeof(*dColors));
1024 for (i = fileCount - 1; i >= 0; i--) {
1029 strlen(dirNames[dirIndexes[i]]) + strlen(baseNames[i]) + 1;
1030 if (len >= fileAlloced) {
1031 fileAlloced = len * 2;
1032 fn = (
char *)
xrealloc(fn, fileAlloced);
1037 fnlen =
stpcpy(
stpcpy(fn, dirNames[dirIndexes[i]]), baseNames[i]) - fn;
1039 if (fColors != NULL) {
1041 for (j = 0; j < (int)dirCount; j++) {
1042 if (strcmp(dirNames[dirIndexes[i]], dirNames[j]))
continue;
1043 dColors[
j] |= fColors[
i];
1054 for (j = numRelocations - 1; j >= 0; j--) {
1055 if (relocations[j].
oldPath == NULL)
1057 len = strcmp(relocations[j].
oldPath,
"/")
1058 ? strlen(relocations[j].oldPath)
1067 if (!(fn[len] ==
'/' || fnlen == len))
1070 if (strncmp(relocations[j].oldPath, fn, len))
1074 if (j < 0)
continue;
1081 if (relocations[j].
newPath == NULL) {
1084 for (j = dirIndexes[i]; j < (int)dirCount; j++) {
1085 len = strlen(dirNames[j]) - 1;
1086 while (len > 0 && dirNames[j][len-1] ==
'/') len--;
1089 if (strncmp(fn, dirNames[j], fnlen))
1103 if (fnlen != len)
continue;
1110 strcpy(fn, relocations[j].newPath);
1111 {
char * te = strrchr(fn,
'/');
1116 te = fn + strlen(fn);
1118 if (strcmp(baseNames[i], te))
1125 for (j = 0; j < (int)dirCount; j++) {
1126 if (fnlen != strlen(dirNames[j]))
1128 if (strncmp(fn, dirNames[j], fnlen))
1133 if (j < (
int)dirCount) {
1139 if (!haveRelocatedFile) {
1140 const char ** newDirList;
1142 haveRelocatedFile = 1;
1143 newDirList = (
const char **)
xmalloc((dirCount + 1) *
sizeof(*newDirList));
1144 for (j = 0; j < (int)dirCount; j++)
1146 dirNames =
_free(dirNames);
1147 dirNames = newDirList;
1149 dirNames = (
const char **)
xrealloc(dirNames,
1150 sizeof(*dirNames) * (dirCount + 1));
1154 dirIndexes[
i] = dirCount;
1159 for (i = dirCount - 1; i >= 0; i--) {
1160 for (j = numRelocations - 1; j >= 0; j--) {
1163 if (j == p->autorelocatex
1164 && (dColors[i] == 0 || !(dColors[i] & mydColor)))
1167 if (relocations[j].
oldPath == NULL)
1169 len = strcmp(relocations[j].
oldPath,
"/")
1170 ? strlen(relocations[j].oldPath)
1173 if (len && strncmp(relocations[j].oldPath, dirNames[i], len))
1180 if (dirNames[i][len] !=
'/')
1184 const char * s = relocations[
j].
newPath;
1185 size_t slen = strlen(s) + strlen(dirNames[i]) -
len;
1186 char * t = (
char *)
alloca(slen + 1);
1198 D_(
"relocating directory %s to %s\n"), dirNames[i], t);
1227 he->
p.
argv = baseNames;
1230 fi->bnl =
_free(fi->bnl);
1233 fi->bnl = he->
p.
argv;
1239 he->
p.
argv = dirNames;
1242 fi->dnl =
_free(fi->dnl);
1244 fi->dnl = he->
p.
argv;
1249 he->
p.
ui32p = dirIndexes;
1252 fi->dil =
_free(fi->dil);
1259 baseNames =
_free(baseNames);
1260 dirIndexes =
_free(dirIndexes);
1261 dirNames =
_free(dirNames);
1262 fFlags =
_free(fFlags);
1263 fColors =
_free(fColors);
1264 fModes =
_free(fModes);
1293 fi->pretrans =
_free(fi->pretrans);
1294 fi->pretransprog =
_free(fi->pretransprog);
1295 fi->posttrans =
_free(fi->posttrans);
1296 fi->posttransprog =
_free(fi->posttransprog);
1297 fi->verifyscript =
_free(fi->verifyscript);
1298 fi->verifyscriptprog =
_free(fi->verifyscriptprog);
1301 fi->bnl =
_free(fi->bnl);
1302 fi->dnl =
_free(fi->dnl);
1304 fi->flinks =
_free(fi->flinks);
1305 fi->flangs =
_free(fi->flangs);
1306 fi->fdigests =
_free(fi->fdigests);
1307 fi->digests =
_free(fi->digests);
1309 fi->cdict =
_free(fi->cdict);
1311 fi->fuser =
_free(fi->fuser);
1312 fi->fgroup =
_free(fi->fgroup);
1314 fi->fstates =
_free(fi->fstates);
1316 fi->fmtimes =
_free(fi->fmtimes);
1317 fi->fmodes =
_free(fi->fmodes);
1318 fi->fflags =
_free(fi->fflags);
1319 fi->vflags =
_free(fi->vflags);
1320 fi->fsizes =
_free(fi->fsizes);
1321 fi->frdevs =
_free(fi->frdevs);
1322 fi->finodes =
_free(fi->finodes);
1323 fi->dil =
_free(fi->dil);
1325 fi->fcolors =
_free(fi->fcolors);
1326 fi->fcdictx =
_free(fi->fcdictx);
1327 fi->ddict =
_free(fi->ddict);
1328 fi->fddictx =
_free(fi->fddictx);
1329 fi->fddictn =
_free(fi->fddictn);
1340 fi->fn =
_free(fi->fn);
1341 fi->apath =
_free(fi->apath);
1342 fi->fmapflags =
_free(fi->fmapflags);
1344 fi->obnl =
_free(fi->obnl);
1345 fi->odnl =
_free(fi->odnl);
1347 fi->fcontexts =
_free(fi->fcontexts);
1349 fi->actions =
_free(fi->actions);
1350 fi->replacedSizes =
_free(fi->replacedSizes);
1365 if (_rpmfiPool == NULL) {
1366 _rpmfiPool =
rpmioNewPool(
"fi",
sizeof(*fi), -1, _rpmfi_debug,
1371 memset(((
char *)fi)+
sizeof(fi->_item), 0,
sizeof(*fi)-
sizeof(fi->_item));
1383 if (c >=
'0' && c <=
'9')
1385 if (c >=
'A' && c <=
'F')
1386 return (c -
'A') + 10;
1387 if (c >=
'a' && c <=
'f')
1388 return (c -
'a') + 10;
1392 #define _fdupestring(_h, _tag, _data) \
1394 xx = headerGet((_h), he, 0); \
1397 #define _fdupedata(_h, _tag, _cast, _data) \
1399 xx = headerGet((_h), he, 0); \
1400 _data = (_cast) he->p.ptr;
1408 int scareMem = (flags & 0x1);
1418 assert(scareMem == 0);
1430 fi->magic = RPMFIMAGIC;
1441 if (fi->fsm == NULL)
1450 fi->archiveSize = (xx && he->
p.
ui32p ? he->
p.
ui32p[0] : 0);
1464 if (xx == 0 && fi->isSource) {
1468 fi->bnl = he->
p.
argv;
1478 if (fi->dc == 0 && fi->isSource) {
1480 fi->dnl = (
const char **)
xcalloc(3,
sizeof(*fi->dnl));
1481 fi->dnl[0] = (
const char *)&fi->dnl[2];
1493 if (fi->fcolors != NULL)
1494 for (i = 0; i < (int)fi->fc; i++)
1495 fi->color |= fi->fcolors[
i];
1506 if (xx == 0 || fi->fstates == NULL)
1512 if (fi->actions == NULL)
1513 fi->actions = (
int *)
xcalloc(fi->fc,
sizeof(*fi->actions));
1523 fi->fdigestalgos = NULL;
1525 if (fi->fdigestalgos) {
1527 for (i = 0; i < (int)fi->fc; i++) {
1528 if (fi->fdigestalgos[i] == 0)
1531 dalgo = (
pgpHashAlgo) (fi->fdigestalgos[i] & 0xff);
1533 assert(dalgo == (
pgpHashAlgo)fi->fdigestalgos[i]);
1535 fi->fdigestalgos =
_free(fi->fdigestalgos);
1559 fi->digestalgo = dalgo;
1564 t = (
unsigned char *)
xmalloc(fi->fc * fi->digestlen);
1566 for (i = 0; i < (int)fi->fc; i++) {
1567 const char * fdigests;
1570 fdigests = fi->fdigests[
i];
1571 if (!(fdigests && *fdigests !=
'\0')) {
1572 memset(t, 0, fi->digestlen);
1576 for (j = 0; j < (int)fi->digestlen; j++, t++, fdigests += 2)
1579 fi->fdigests =
_free(fi->fdigests);
1599 const char * fmt =
rpmGetPath(
"%{?_autorelocate_path}", NULL);
1610 if (newPath != NULL && *newPath !=
'\0' && p->relocs != NULL)
1611 for (i = 0; i < p->nrelocs; i++) {
1613 if (strcmp(p->relocs[i].oldPath,
"/"))
1615 if (strcmp(p->relocs[i].newPath, newPath))
1623 if (newPath != NULL && *newPath !=
'\0' && i == p->nrelocs) {
1627 p->relocs[p->nrelocs].oldPath =
xstrdup(
"/");
1628 p->relocs[p->nrelocs].newPath =
xstrdup(newPath);
1629 p->autorelocatex = p->nrelocs;
1631 p->relocs[p->nrelocs].oldPath = NULL;
1632 p->relocs[p->nrelocs].newPath = NULL;
1634 newPath =
_free(newPath);
1637 if (fi->actions == NULL)
1638 fi->actions = (
int *)
xcalloc(fi->fc,
sizeof(*fi->actions));
1649 if (fi->isSource && fi->dc == 1 && *fi->dnl[0] ==
'\0') {
1650 const char ** av = (
const char **)
xcalloc(4+1,
sizeof(*av));
1663 fi->dnl =
_free(fi->dnl);
1665 nb = fi->dc *
sizeof(*av);
1666 for (i = 0; i < (int)fi->dc; i++)
1667 nb += strlen(av[i]) +
sizeof(
"/");
1669 fi->dnl = (
const char **)
xmalloc(nb);
1670 te = (
char *) (&fi->dnl[fi->dc]);
1672 for (i = 0; i < (int)fi->dc; i++) {
1680 for (i = 0; i < (int)fi->fc; i++) {
1690 const char *
b = fi->bnl[
i];
1691 const char * be = b + strlen(b) -
sizeof(
".spec") - 1;
1693 fi->dil[
i] = (be > b && !strcmp(be,
".spec") ? 1 : 0);
1704 for (i = 0; i < (int)fi->fc; i++) {
1705 size_t fnlen = strlen(fi->dnl[fi->dil[i]]) + strlen(fi->bnl[i]);
1707 if (fnlen > fi->fnlen)
1716 if (_rpmfi_debug < 0)
1717 fprintf(stderr,
"*** fi %p\t%s[%d]\n", fi, Type, (fi ? fi->fc : 0));
1721 return rpmfiLink(fi, (fi ? fi->Type : NULL));
1732 (*relp)[*nrelp].oldPath = (oldPath ?
xstrdup(oldPath) : NULL);
1733 (*relp)[*nrelp].newPath = (newPath ?
xstrdup(newPath) : NULL);
1746 relocs =
_free(relocs);
1772 *nrelocsp = nrelocs;
1780 if (st != NULL && fi != NULL && fi->i >= 0 && fi->i < (
int)fi->fc) {
1781 memset(st, 0,
sizeof(*st));
1783 st->st_rdev = fi->frdevs[fi->i];
1784 st->st_ino = fi->finodes[fi->i];
1785 st->st_mode = fi->fmodes[fi->i];
1786 st->st_nlink =
rpmfiFNlink(fi) + (int)S_ISDIR(st->st_mode);
1787 if (
unameToUid(fi->fuser[fi->i], &st->st_uid) == -1)
1789 if (
gnameToGid(fi->fgroup[fi->i], &st->st_gid) == -1)
1791 st->st_size = fi->fsizes[fi->i];
1792 st->st_blksize = 4 * 1024;
1793 st->st_blocks = (st->st_size + (st->st_blksize - 1)) / st->st_blksize;
1796 st->st_mtime = fi->fmtimes[fi->i];
1805 size_t pathlen = strlen(path);
1809 while (pathlen > 0 && path[pathlen-1] ==
'/')
1813 if (!(fi != NULL && fi->i >= 0 && fi->i < (
int)fi->fc))
1817 const char * fn =
rpmfiFN(fi);
1818 size_t fnlen = strlen(fn);
1820 if (pathlen != fnlen || strncmp(path, fn, fnlen))
1828 fprintf(stderr,
"*** rpmfiStat(%p, %s, %p) rc %d\n", fi, path, st, rc);
1836 const char * dn =
name;
1837 size_t dnlen = strlen(dn);
1838 const char ** fnames = NULL;
1850 const char * fn =
rpmfiFN(fi);
1851 size_t fnlen = strlen(fn);
1855 if (strncmp(dn, fn, dnlen) || fn[dnlen] !=
'/')
1860 xx =
argvAdd(&fnames, fn + dnlen + 1);
1861 fmodes[j++] = fi->fmodes[
i];
1865 dir = (DIR *)
avOpendir(name, fnames, fmodes);
1868 fmodes =
_free(fmodes);
1872 fprintf(stderr,
"*** rpmfiOpendir(%p, %s) dir %p\n", fi, name, dir);
1883 const char * FClass;
1889 if ((ac =
rpmfiFC(fi)) <= 0) {
1896 nb = (ac + 1) *
sizeof(*av);
1901 if (FClass && *FClass !=
'\0')
1902 nb += strlen(FClass);
1907 av = (
const char **)
xmalloc(nb);
1908 t = ((
char *) av) + ((ac + 1) *
sizeof(*av));
1915 if (FClass && *FClass !=
'\0')
1931 void rpmfiBuildFContexts(
Header h,
1936 const char * fcontext;
1942 if ((ac =
rpmfiFC(fi)) <= 0) {
1949 nb = (ac + 1) *
sizeof(*av);
1954 if (fcontext && *fcontext !=
'\0')
1955 nb += strlen(fcontext);
1960 av = (
const char **)
xmalloc(nb);
1961 t = ((
char *) av) + ((ac + 1) *
sizeof(*av));
1968 if (fcontext && *fcontext !=
'\0')
1983 void rpmfiBuildFSContexts(
Header h,
1992 char * fctxt = NULL;
1993 size_t fctxtlen = 0;
1996 if ((ac =
rpmfiFC(fi)) <= 0) {
2003 nb = ac *
sizeof(*fcnb);
2004 fcnb = memset(
alloca(nb), 0, nb);
2010 security_context_t scon = NULL;
2013 fcnb[ac] = lgetfilecon(fn, &scon);
2015 fctxt = (
char *)
xrealloc(fctxt, fctxtlen + fcnb[ac]);
2016 memcpy(fctxt+fctxtlen, scon, fcnb[ac]);
2017 fctxtlen += fcnb[ac];
2024 nb = (ac + 1) *
sizeof(*av) + fctxtlen;
2025 av = (
const char **)
xmalloc(nb);
2026 t = ((
char *) av) + ((ac + 1) *
sizeof(*av));
2027 if (fctxt != NULL && fctxtlen > 0)
2028 (void) memcpy(t, fctxt, fctxtlen);
2051 void rpmfiBuildREContexts(
Header h,
2056 const char ** av = NULL;
2060 char * fctxt = NULL;
2061 size_t fctxtlen = 0;
2064 if ((ac =
rpmfiFC(fi)) <= 0) {
2070 {
const char *fn =
rpmGetPath(
"%{?__file_context_path}", NULL);
2072 if (fn != NULL && *fn !=
'\0')
2073 (void)matchpathcon_init(fn);
2079 nb = ac *
sizeof(*fcnb);
2080 fcnb = memset(
alloca(nb), 0, nb);
2087 security_context_t scon;
2093 if (matchpathcon(fn, fmode, &scon) == 0 && scon != NULL) {
2094 fcnb[ac] = strlen(scon) + 1;
2096 fctxt = (
char *)
xrealloc(fctxt, fctxtlen + fcnb[ac]);
2097 memcpy(fctxt+fctxtlen, scon, fcnb[ac]);
2098 fctxtlen += fcnb[ac];
2107 nb = (ac + 1) *
sizeof(*av) + fctxtlen;
2108 av = (
const char **)
xmalloc(nb);
2109 t = ((
char *) av) + ((ac + 1) *
sizeof(*av));
2110 (void) memcpy(t, fctxt, fctxtlen);
2126 matchpathcon_fini();
2154 if ((ac =
rpmfiFC(fi)) <= 0) {
2168 nb = (ac + 1) *
sizeof(*av);
2177 mydt = ((ix >> 24) & 0xff);
2178 if (mydt != deptype)
2186 nb += strlen(DNEVR+2) + 1;
2192 av = (
const char **)
xmalloc(nb);
2193 t = ((
char *) av) + ((ac + 1) *
sizeof(*av));
2204 mydt = ((ix >> 24) & 0xff);
2205 if (mydt != deptype)
2212 if (DNEVR != NULL) {
rpmuint32_t rpmfiFFlags(rpmfi fi)
Return current file flags from file info set.
int headerMacrosUnload(Header h)
Define per-header macros.
int rpmfiSetHeader(rpmfi fi, Header h)
Link a header to a file info set.
rpmfileState rpmfiSetFState(rpmfi fi, rpmfileState fstate)
Set current file state in file info set.
mongo_error_t const char * errstr
int rpmfiDX(rpmfi fi)
Return current directory index from file info set.
const char const char size_t len
rpmuint32_t rpmfiVFlags(rpmfi fi)
Return current file verify flags from file info set.
void rpmfiFpLookup(rpmfi fi, fingerPrintCache fpc)
const char bson_timestamp_t * ts
void * mireFreeAll(miRE mire, int nmire)
Destroy compiled patterns.
rpmuint32_t rpmfiSetFFlags(rpmfi fi, rpmuint32_t FFlags)
Set current file flags in file info set.
const char * rpmtsRootDir(rpmts ts)
Get transaction rootDir, i.e.
rpmuint32_t rpmfiFDepends(rpmfi fi, const rpmuint32_t **fddictp)
Return current file depends dictionary from file info set.
void rpmpsAppend(rpmps ps, rpmProblemType type, const char *pkgNEVR, fnpyKey key, const char *dn, const char *bn, const char *altNEVR, rpmuint64_t ulong1)
Append a problem to current set of problems.
enum iosmFileAction_e iosmFileAction
File disposition(s) during package install/erase processing.
static const char * rpmfiFtstring(rpmFileTypes ft)
Identify a file type.
rpmbf rpmbfNew(size_t m, size_t k, unsigned flags)
Create a Bloom filter.
rpmuint32_t rpmfiFNlink(rpmfi fi)
Return (calculated) current file nlink count from file info set.
Structures used for an "rpmte" transaction element.
char * xstrdup(const char *str)
char * rpmCleanPath(char *path)
Canonicalize file path.
struct iosm_s * FSM_t
File state machine data.
char * rpmGetPath(const char *path,...)
Return (malloc'ed) expanded, canonicalized, file path.
enum pgpHashAlgo_e pgpHashAlgo
9.4.
int rpmfiSetFX(rpmfi fi, int fx)
Set current file index in file info set.
size_t rpmfiFNMaxLen(rpmfi fi)
Return maximum file name length from file info set.
void * rpmfiFNBF(rpmfi fi)
Return FN Bloom filter from file info set.
static rpmfi rpmfiGetPool(rpmioPool pool)
rpmuint16_t rpmfiFRdev(rpmfi fi)
Return current file rdev from file info set.
rpmfi rpmfiFree(rpmfi fi)
Destroy a file info set.
const char * rpmfiFN(rpmfi fi)
Return current file name from file info set.
unsigned short rpmuint16_t
int rpmfiDecideFate(const rpmfi ofi, rpmfi nfi, int skipMissing)
Return file disposition.
int dodigest(int dalgo, const char *fn, unsigned char *digest, unsigned dflags, size_t *fsizep)
Return digest and size of a file.
const char * rpmfiFUser(rpmfi fi)
Return current file owner from file info set.
static void rpmlog(int code, const char *fmt,...)
struct rpmps_s * rpmps
Transaction problems found while processing a transaction set/.
rpmElementType rpmteType(rpmte te)
Retrieve type of transaction element.
struct rpmRelocation_s * rpmRelocation
const char * rpmfiFGroup(rpmfi fi)
Return current file group from file info set.
const char * rpmdsDNEVR(const rpmds ds)
Return current formatted dependency string.
int rpmfiNInclude(const rpmfi fi)
Return no.
rpmfi rpmfiNew(const void *_ts, Header h, rpmTag tagN, int flags)
Create and load a file info set.
struct rpmds_s * rpmds
Dependency tag sets from a header, so that a header can be discarded early.
rpmuint32_t rpmfiFColor(rpmfi fi)
Return current file color bits from file info set.
const char * rpmfiBN(rpmfi fi)
Return current base name from file info set.
rpmds rpmdsFree(rpmds ds)
Destroy a dependency set.
char * headerSprintf(Header h, const char *fmt, headerTagTableEntry tags, headerSprintfExtension exts, errmsg_t *errmsg)
Return formatted output string from header tags.
int rpmfiFC(rpmfi fi)
Return file count from file info set.
rpmuint32_t rpmfiFSize(rpmfi fi)
Return current file size from file info set.
struct rpmte_s * rpmte
An element of a transaction set, i.e.
struct fingerPrint_s * rpmfiFpsIndex(rpmfi fi, int ix)
#define RPMFILE_STATE_MISSING
rpmuint32_t rpmfiSetVFlags(rpmfi fi, rpmuint32_t VFlags)
Set current file verify flags in file info set.
void rpmbfParams(size_t n, double e, size_t *mp, size_t *kp)
Return optimal {m, k} for given n and e.
const char * rpmfiTypeString(rpmfi fi)
Return formatted string representation of package disposition.
Yet Another syslog(3) API clone.
int rpmfiNextD(rpmfi fi)
Return next directory iterator index.
void * rpmfiExclude(const rpmfi fi)
Return file info exclude patterns.
const char * rpmteNEVR(rpmte te)
Retrieve name-version-release string from transaction element.
void * xcalloc(size_t nmemb, size_t size)
const char * rpmfiDN(rpmfi fi)
Return current directory name from file info set.
rpmbf rpmbfFree(rpmbf bf)
Destroy a Bloom filter.
rpmioItem rpmioGetPool(rpmioPool pool, size_t size)
Get unused item from pool, or alloc a new item.
int gnameToGid(const char *thisGname, gid_t *gid)
unsigned char rpmuint8_t
Private int typedefs to avoid C99 portability issues.
struct rpmfi_s * rpmfi
File info tag sets from a header, so that a header can be discarded early.
rpmuint16_t rpmfiFMode(rpmfi fi)
Return current file mode from file info set.
int Lstat(const char *path, struct stat *st)
lstat(2) clone.
ARGV_t argvFree(ARGV_t argv)
Destroy an argv array.
int rpmfiAddRelocation(rpmRelocation *relp, int *nrelp, const char *oldPath, const char *newPath)
Add relocation element to array.
static Header relocateFileList(const rpmts ts, rpmfi fi, Header origH, iosmFileAction *actions)
Relocate files in header.
int headerMacrosLoad(Header h)
Define per-header macros.
int rpmdsNext(rpmds ds)
Return next dependency set iterator index.
Structure(s) used for dependency tag sets.
void fpLookupList(fingerPrintCache cache, const char **dirNames, const char **baseNames, const rpmuint32_t *dirIndexes, rpmuint32_t fileCount, fingerPrint *fpList)
Return finger prints of an array of file paths.
int rpmfiIsSource(rpmfi fi)
Return source rpm marker from file info set.
const char * rpmGenPath(const char *urlroot, const char *urlmdir, const char *urlfile)
Merge 3 args into path, any or all of which may be a url.
int argvAdd(ARGV_t *argvp, ARGstr_t val)
Add a string to an argv array.
Header headerFree(Header h)
Dereference a header instance.
rpmuint32_t rpmfiFMtime(rpmfi fi)
Return current file modify time from file info set.
Identify a file name path by a unique "finger print".
rpmRelocation rpmfiFreeRelocations(rpmRelocation relocs)
Free relocation array.
enum rpmTagType_e rpmTagType
static char * stripTrailingChar(char *s, char c)
Remove occurrences of trailing character from string.
const char const bson int mongo_write_concern int flags
Associates a trailing sub-directory and final base name with an existing directory finger print...
int rpmfiNext(rpmfi fi)
Return next file iterator index.
rpmps rpmpsFree(rpmps ps)
Destroy a problem set.
Header headerLink(Header h)
Reference a header instance.
rpmte rpmtsRelocateElement(rpmts ts)
Get current relocate transaction element.
int Readlink(const char *path, char *buf, size_t bufsiz)
readlink(2) clone.
int rpmfiDC(rpmfi fi)
Return directory count from file info set.
void * rpmfiOpendir(rpmfi fi, const char *name)
Return directory stream onto file info set.
fnpyKey rpmteKey(rpmte te)
Retrieve key from transaction element.
DIR * avOpendir(const char *path, const char **av, rpmuint16_t *modes)
rpmfi rpmfiInit(rpmfi fi, int fx)
Initialize file iterator index.
#define _fdupestring(_h, _tag, _data)
int rpmfiNExclude(const rpmfi fi)
Return no.
enum rpmfileState_e rpmfileState
File States (when installed).
const char * rpmfiFClass(rpmfi fi)
Return current file class from file info set.
urltype urlPath(const char *url, const char **pathp)
Return path component of URL.
rpmfi rpmfiLink(rpmfi fi, const char *msg)
Reference a file info set instance.
const char * rpmfiFLink(rpmfi fi)
Return current file linkto (i.e.
rpmioPool rpmioNewPool(const char *name, size_t size, int limit, int flags, char *(*dbg)(void *item), void(*init)(void *item), void(*fini)(void *item))
Create a memory pool.
void rpmfiBuildFDeps(Header h, rpmTag tagN, const char ***fdepsp, rpmuint32_t *fcp)
Retrieve per-file dependencies from header.
rpmps rpmtsProblems(rpmts ts)
Return current transaction set problems.
struct fprintCache_s * fingerPrintCache
char * stpcpy(char *dest, const char *src)
struct rpmts_s * rpmts
The RPM Transaction Set.
IOSM_t newFSM(void)
Create file state machine instance.
static void * _free(const void *p)
Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
Structures and prototypes used for an "rpmts" transaction set.
rpmfileState rpmfiFState(rpmfi fi)
Return current file state from file info set.
void * rpmfiBloomFN(const rpmfi fi)
Return file path Bloom filter.
File state machine to handle a payload within an rpm package.
rpmuint32_t rpmfiColor(rpmfi fi)
Return union of all file color bits from file info set.
rpmfi rpmfiInitD(rpmfi fi, int dx)
Initialize directory iterator index.
int rpmbfAdd(rpmbf bf, const void *_s, size_t ns)
Add item to a Bloom filter.
rpmRelocation rpmfiDupeRelocations(rpmRelocation relocs, int *nrelocsp)
Duplicate a relocation array.
#define _fdupedata(_h, _tag, _cast, _data)
const unsigned char * rpmfiDigest(rpmfi fi, int *algop, size_t *lenp)
Return current file (binary) digest from file info set.
IOSM_t freeFSM(IOSM_t fsm)
Destroy file state machine instance.
#define alloca_strdup(_s)
int rpmfiCompare(const rpmfi afi, const rpmfi bfi)
Return file info comparison.
void * rpmfiInclude(const rpmfi fi)
Return file info include patterns.
static rpmFileTypes rpmfiWhatis(rpmuint16_t mode)
Return file type from mode_t.
void rpmfiBuildFClasses(Header h, const char ***fclassp, rpmuint32_t *fcp)
Retrieve file classes from header.
rpmprobFilterFlags rpmtsFilterFlags(rpmts ts)
Get problem ignore bit mask, i.e.
static unsigned char nibble(char c)
Convert hex to binary nibble.
rpmuint32_t rpmfiFInode(rpmfi fi)
Return current file inode from file info set.
int rpmfiStat(rpmfi fi, const char *path, struct stat *st)
Return lstat(2) data of path from file info set.
int unameToUid(const char *thisUname, uid_t *uid)
const char * rpmfiFContext(rpmfi fi)
Return current file security context from file info set.
rpmds rpmdsNew(Header h, rpmTag tagN, int flags)
Create and load a dependency set.
int rpmfiFStat(rpmfi fi, struct stat *st)
Return current stat(2) data from file info set.
int rpmdsSetIx(rpmds ds, int ix)
Set dependency set index.
int rpmfiFX(rpmfi fi)
Return current file index from file info set.
int rpmExpandNumeric(const char *arg)
Return macro expansion as a numeric value.
File name and stat information.
static void rpmfiFini(void *_fi)
int rpmfiSetDX(rpmfi fi, int dx)
Set current directory index in file info set.
enum rpmFileTypes_e rpmFileTypes
File types.