9 #define MYALLPERMS 07777
23 #define _RPMFI_INTERNAL
26 #define _RPMTE_INTERNAL
41 #define SKIPWHITE(_x) {while(*(_x) && (xisspace(*_x) || *(_x) == ',')) (_x)++;}
42 #define SKIPNONWHITE(_x){while(*(_x) &&!(xisspace(*_x) || *(_x) == ',')) (_x)++;}
44 #define MAXDOCDIR 1024
66 #define fl_dev fl_st.st_dev
67 #define fl_ino fl_st.st_ino
68 #define fl_mode fl_st.st_mode
69 #define fl_nlink fl_st.st_nlink
70 #define fl_uid fl_st.st_uid
71 #define fl_gid fl_st.st_gid
72 #define fl_rdev fl_st.st_rdev
73 #define fl_size fl_st.st_size
74 #define fl_mtime fl_st.st_mtime
205 static void dumpAttrRec(
const char * msg,
AttrRec ar)
210 fprintf(stderr,
"%s:\t", msg);
211 fprintf(stderr,
"(%s, %s, %s, %s)\n",
228 static char *olds = NULL;
237 s += strspn(s, delim);
246 s = strchr(token,
'"');
248 s = strpbrk(token, delim);
254 olds = strchr(token,
'\0');
279 time_t currentTime = time(NULL);
285 for (x = 0; x < count; x++) {
286 if ((currentTime - mtime[x]) > tc)
289 files = hfd(files, fnt);
337 if ((p = strstr(buf, (name =
"%verify"))) != NULL) {
340 }
else if ((p = strstr(buf, (name =
"%defverify"))) != NULL) {
346 for (pe = p; (pe-p) < strlen(name); pe++)
359 for (p = pe; *pe && *pe !=
')'; pe++)
378 for (p = q; *p !=
'\0'; p = pe) {
388 for (vfa = verifyAttrs; vfa->
attribute != NULL; vfa++) {
391 verifyFlags |= vfa->
flag;
398 if (!strcmp(p,
"not")) {
407 *resultVerify = negated ? ~(verifyFlags) : verifyFlags;
414 #define isAttrDefault(_ars) ((_ars)[0] == '-' && (_ars)[1] == '\0')
428 const char * errstr = NULL;
432 if ((p = strstr(buf, (name =
"%dev"))) == NULL)
435 for (pe = p; (pe-p) < strlen(name); pe++)
446 for (p = pe; *pe && *pe !=
')'; pe++)
461 pe = p;
SKIPNONWHITE(pe);
if (*pe !=
'\0') *pe++ =
'\0';
472 pe = p;
SKIPNONWHITE(pe);
if (*pe !=
'\0') *pe++ =
'\0';
473 for (pe = p; *pe &&
xisdigit(*pe); pe++)
490 pe = p;
SKIPNONWHITE(pe);
if (*pe !=
'\0') *pe++ =
'\0';
491 for (pe = p; *pe &&
xisdigit(*pe); pe++)
537 if ((p = strstr(buf, (name =
"%attr"))) != NULL) {
540 }
else if ((p = strstr(buf, (name =
"%defattr"))) != NULL) {
546 for (pe = p; (pe-p) < strlen(name); pe++)
559 for (p = pe; *pe && *pe !=
')'; pe++)
562 if (ret_ar == &(fl->
def_ar)) {
568 _(
"Non-white space follows %s(): %s\n"), name, q);
585 pe = p;
SKIPNONWHITE(pe);
if (*pe !=
'\0') *pe++ =
'\0';
590 pe = p;
SKIPNONWHITE(pe);
if (*pe !=
'\0') *pe++ =
'\0';
595 pe = p;
SKIPNONWHITE(pe);
if (*pe !=
'\0') *pe++ =
'\0';
599 if (*p !=
'\0' && ret_ar == &(fl->
def_ar)) {
600 pe = p;
SKIPNONWHITE(pe);
if (*pe !=
'\0') *pe++ =
'\0';
605 if (!(ar->ar_fmodestr && ar->ar_user && ar->ar_group) || *p !=
'\0') {
614 x = sscanf(ar->ar_fmodestr,
"%o", &ui);
615 if ((x == 0) || (ar->ar_fmode & ~
MYALLPERMS)) {
622 ar->ar_fmodestr = NULL;
626 x = sscanf(ar->ar_dmodestr,
"%o", &ui);
627 if ((x == 0) || (ar->ar_dmode & ~
MYALLPERMS)) {
634 ar->ar_dmodestr = NULL;
664 if ((p = strstr(buf, (name =
"%config"))) == NULL)
670 for (pe = p; (pe-p) < strlen(name); pe++)
678 for (p = pe; *pe && *pe !=
')'; pe++)
694 for (p = q; *p !=
'\0'; p = pe) {
702 if (!strcmp(p,
"missingok")) {
704 }
else if (!strcmp(p,
"noreplace")) {
719 static int langCmp(
const void * ap,
const void * bp)
723 return strcmp(*(
const char **)ap, *(
const char **)bp);
741 while ((p = strstr(buf, (name =
"%lang"))) != NULL) {
743 for (pe = p; (pe-p) < strlen(name); pe++)
755 for (pe = p; *pe && *pe !=
')'; pe++)
772 for (p = q; *p !=
'\0'; p = pe) {
784 if (np < 1 || (np == 1 && *p !=
'C') || np >= 32) {
786 _(
"Unusual locale length: \"%.*s\" in %%lang(%s)\n"),
794 for (i = 0; i < fl->
nLangs; i++) {
807 strncpy(newp, p, np);
810 if (*pe ==
',') pe++;
829 static int initialized = 0;
830 static int hasRegex = 0;
831 static regex_t compiledPatt;
832 static char buf[BUFSIZ];
834 regmatch_t matches[2];
838 const char *patt =
rpmExpand(
"%{?_langpatt}", NULL);
840 if (!(patt && *patt !=
'\0'))
842 else if (regcomp(&compiledPatt, patt, REG_EXTENDED))
851 memset(matches, 0,
sizeof(matches));
852 if (! hasRegex || regexec(&compiledPatt, fileName, 2, matches, REG_NOTEOL))
856 s = fileName + matches[1].rm_eo - 1;
857 x = matches[1].rm_eo - matches[1].rm_so;
884 {
"%spec", 0, RPMFILE_SPEC },
905 FileList fl,
const char ** fileName)
914 int res, specialDoc = 0;
915 char specialDocBuf[BUFSIZ];
917 specialDocBuf[0] =
'\0';
924 if (!strcmp(s,
"%docdir")) {
941 #if defined(__LCLINT__)
947 for (vfa = virtualFileAttributes; vfa->
attribute != NULL; vfa++) {
951 if (!strcmp(s,
"%dir"))
979 strcat(specialDocBuf,
" ");
980 strcat(specialDocBuf, s);
986 const char * sfn = NULL;
991 _(
"File must begin with \"/\": %s\n"), s);
1009 _(
"Can't mix special %%doc with other forms: %s\n"),
1010 (*fileName ? *fileName :
""));
1015 {
static char *_docdir_fmt= 0;
1016 static int oneshot = 0;
1017 const char *ddir, *fmt, *errstr;
1019 _docdir_fmt =
rpmExpand(
"%{?_docdir_fmt}", NULL);
1020 if (!_docdir_fmt || !*_docdir_fmt)
1021 _docdir_fmt =
"%{NAME}-%{VERSION}";
1047 compress_doc =
rpmExpand(
"%{__compress_doc}", NULL);
1048 if (compress_doc && *compress_doc !=
'%')
1050 compress_doc =
_free(compress_doc);
1066 compress_doc =
rpmExpand(
"%{__compress_doc}", NULL);
1067 if (compress_doc && *compress_doc !=
'%')
1084 const char *a = NULL;
1086 const char *b = NULL;
1089 return strcmp(a, b);
1104 if (strstr(fileName, fl->
docDirs[x]) == fileName)
1124 if (!(S_ISREG(ilp->fl_mode) && ilp->fl_nlink > 1))
1131 if (!S_ISREG(jlp->fl_mode))
1133 if (ilp->fl_nlink != jlp->fl_nlink)
1135 if (ilp->fl_ino != jlp->fl_ino)
1137 if (ilp->fl_dev != jlp->fl_dev)
1148 static int dncmp(
const void * a,
const void * b)
1151 const char ** aurlp = a;
1152 const char ** burlp = b;
1157 return strcmp(adn, bdn);
1175 const char ** dirNames;
1176 const char ** baseNames;
1196 if (fileNames == NULL || count <= 0)
1199 dirNames =
alloca(
sizeof(*dirNames) * count);
1200 baseNames =
alloca(
sizeof(*dirNames) * count);
1201 dirIndexes =
alloca(
sizeof(*dirIndexes) * count);
1203 (void)
urlPath(fileNames[0], &fn);
1207 dirNames[dirIndex] =
"";
1208 for (i = 0; i < count; i++) {
1209 dirIndexes[i] = dirIndex;
1210 baseNames[i] = fileNames[i];
1216 for (i = 0; i < count; i++) {
1217 const char ** needle;
1222 if (fileNames[i] == NULL)
1224 baseName = strrchr(fileNames[i],
'/') + 1;
1225 len = baseName - fileNames[i];
1227 savechar = *baseName;
1231 (needle = bsearch(&fileNames[i], dirNames, dirIndex + 1,
sizeof(dirNames[0]),
dncmp)) == NULL) {
1232 char *s =
alloca(len + 1);
1233 memcpy(s, fileNames[i], len + 1);
1235 dirIndexes[i] = ++dirIndex;
1236 dirNames[dirIndex] = s;
1238 dirIndexes[i] = needle - dirNames;
1241 *baseName = savechar;
1242 baseNames[i] = baseName;
1252 dirNames, dirIndex + 1);
1255 fileNames = hfd(fileNames, fnt);
1278 int _addDotSlash = !isSrc;
1297 skipLen += strlen(fl->
prefix);
1300 sxfn =
rpmGetPath(
"%{?_build_file_context_path}", NULL);
1301 if (sxfn != NULL && *sxfn !=
'\0')
1304 for (i = 0, flp = fl->
fileList; i < fl->fileListRecsUsed; i++, flp++) {
1322 if (S_ISDIR(flp->fl_mode)) {
1325 flp[1].fl_mode = flp->fl_mode;
1329 flp[1].fl_mode = flp->fl_mode;
1336 flp[1].fl_uid = flp->fl_uid;
1344 flp[1].fl_gid = flp->fl_gid;
1363 apathlen += (strlen(apath) - skipLen + (_addDotSlash ? 3 : 1));
1366 dpathlen += (strlen(flp->
diskURL) + 2);
1377 if (
sizeof(flp->fl_size) !=
sizeof(
uint_32)) {
1383 &(flp->fl_size), 1);
1389 if (
sizeof(flp->fl_mtime) !=
sizeof(
uint_32)) {
1395 &(flp->fl_mtime), 1);
1397 if (
sizeof(flp->fl_mode) !=
sizeof(
uint_16)) {
1403 &(flp->fl_mode), 1);
1405 if (
sizeof(flp->fl_rdev) !=
sizeof(
uint_16)) {
1411 &(flp->fl_rdev), 1);
1413 if (
sizeof(flp->fl_dev) !=
sizeof(
uint_32)) {
1421 if (
sizeof(flp->fl_ino) !=
sizeof(
uint_32)) {
1434 {
static uint_32 source_file_dalgo = 0;
1435 static uint_32 binary_file_dalgo = 0;
1436 static int oneshot = 0;
1447 dalgo = (isSrc ? source_file_dalgo : binary_file_dalgo);
1471 if (S_ISREG(flp->fl_mode))
1486 const char * buildRoot;
1489 if (buf[0] ==
'/' && strcmp(buildRoot,
"/") &&
1490 !strncmp(buf, buildRoot, strlen(buildRoot))) {
1492 _(
"Symlink points to BuildRoot: %s -> %s\n"),
1512 if (S_ISDIR(flp->fl_mode))
1520 mode_t fmode = (
uint_16)flp->fl_mode;
1521 static const char *nocon =
"";
1539 if (fi == NULL)
return;
1542 fi->te =
xcalloc(1,
sizeof(*fi->te));
1546 fi->dnl =
_free(fi->dnl);
1547 fi->bnl =
_free(fi->bnl);
1548 if (!scareMem) fi->dil =
_free(fi->dil);
1551 fi->dnl =
xmalloc(fi->fc *
sizeof(*fi->dnl) + dpathlen + 1);
1552 d = (
char *)(fi->dnl + fi->fc);
1555 fi->bnl =
xmalloc(fi->fc * (
sizeof(*fi->bnl) +
sizeof(*fi->dil)));
1557 fi->dil = (!scareMem)
1558 ?
xcalloc(
sizeof(*fi->dil), fi->fc)
1559 : (
int *)(fi->bnl + fi->fc);
1563 fi->apath =
xmalloc(fi->fc *
sizeof(*fi->apath) + apathlen + 1);
1564 a = (
char *)(fi->apath + fi->fc);
1567 fi->actions =
xcalloc(
sizeof(*fi->actions), fi->fc);
1568 fi->fmapflags =
xcalloc(
sizeof(*fi->fmapflags), fi->fc);
1577 if (fi->dil != NULL)
1578 for (i = 0, flp = fl->
fileList; i < fi->fc; i++, flp++) {
1591 if ((fnlen = strlen(flp->
diskURL) + 1) > fi->fnlen)
1597 fi->dnl[fi->dil[i]] = d;
1602 for (b = d; b > fi->dnl[fi->dil[i]] && *b !=
'/'; b--)
1616 a =
stpcpy(a, (apath + skipLen));
1629 if (S_ISREG(flp->fl_mode)) {
1632 if (flp->fl_nlink > 1) {
1635 for (; (unsigned)j < fi->fc; j++, jlp++) {
1636 if (!S_ISREG(jlp->fl_mode))
1638 if (flp->fl_nlink != jlp->fl_nlink)
1640 if (flp->fl_ino != jlp->fl_ino)
1642 if (flp->fl_dev != jlp->fl_dev)
1676 fileList[count].
diskURL =
_free(fileList[count].diskURL);
1677 fileList[count].
fileURL =
_free(fileList[count].fileURL);
1678 fileList[count].
langs =
_free(fileList[count].langs);
1680 fileList =
_free(fileList);
1704 struct stat * statp)
1713 const char *fn =
xstrdup(diskURL);
1714 const char *fileURL = fn;
1715 struct stat statbuf;
1719 const char *fileUname;
1720 const char *fileGname;
1735 {
const char *fileName;
1739 fileURL += (fileName - fileURL);
1742 const char * s = fileURL + nb;
1743 char * t = (
char *) fileURL;
1744 (void) memmove(t, s, nb);
1758 if (*fileURL ==
'\0')
1764 const char *prefixTest;
1765 const char *prefixPtr = fl->
prefix;
1767 (void)
urlPath(fileURL, &prefixTest);
1768 while (*prefixPtr && *prefixTest && (*prefixTest == *prefixPtr)) {
1772 if (*prefixPtr || (*prefixTest && *prefixTest !=
'/')) {
1780 if (statp == NULL) {
1782 memset(statp, 0,
sizeof(*statp));
1784 time_t now = time(NULL);
1787 statp->st_nlink = 1;
1790 statp->st_dev = statp->st_rdev;
1791 statp->st_mode = (fl->
devtype ==
'b' ? S_IFBLK : S_IFCHR);
1793 statp->st_atime = now;
1794 statp->st_mtime = now;
1795 statp->st_ctime = now;
1796 }
else if (
Lstat(diskURL, statp)) {
1803 if ((! fl->
isDir) && S_ISDIR(statp->st_mode)) {
1809 fileMode = statp->st_mode;
1810 fileUid = statp->st_uid;
1811 fileGid = statp->st_gid;
1832 if (fileUname == NULL)
1834 if (fileGname == NULL)
1838 if (check_fileList && (S_ISREG(fileMode) ||
S_ISLNK(fileMode))) {
1839 const char * diskfn = NULL;
1840 (void)
urlPath(diskURL, &diskfn);
1855 flp->
fl_st = *statp;
1856 flp->fl_mode = fileMode;
1857 flp->fl_uid = fileUid;
1858 flp->fl_gid = fileGid;
1862 flp->
uname = fileUname;
1863 flp->
gname = fileGname;
1869 for (i = 0; i < fl->
nLangs; i++)
1873 for (i = 0; i < fl->
nLangs; i++) {
1875 if (i) *ncl++ =
'|';
1916 ftsSet[0] = (
char *) diskURL;
1918 ftsp =
Fts_open(ftsSet, myFtsOpts, NULL);
1919 while ((fts =
Fts_read(ftsp)) != NULL) {
1972 const char * buildURL =
"%{_builddir}/%{?buildsubdir}/";
1973 const char * fn = NULL;
1974 const char * apkt = NULL;
1975 const unsigned char * pkt = NULL;
2007 if ((rc =
rpmioSlurp(fn, &pkt, &pktlen)) != 0) {
2011 apkt = (
const char *) pkt;
2043 const char * fileURL)
2052 const char *diskURL = NULL;
2058 {
const char * fileName;
2059 (void)
urlPath(fileURL, &fileName);
2060 if (*fileName !=
'/') {
2079 const char ** argv = NULL;
2092 rc =
rpmGlob(diskURL, &argc, &argv);
2093 if (rc == 0 && argc >= 1) {
2094 for (i = 0; i < argc; i++) {
2095 rc =
addFile(fl, argv[i], NULL);
2097 argv[i] =
_free(argv[i]);
2109 rc =
addFile(fl, diskURL, NULL);
2113 diskURL =
_free(diskURL);
2125 int installSpecialDoc,
int test)
2134 char *s, **files, **fp;
2135 const char *fileName;
2138 AttrRec specialDocAttrRec = &arbuf;
2139 char *specialDoc = NULL;
2158 fd =
Fopen(ffn,
"r.fpio");
2160 if (fd == NULL ||
Ferror(fd)) {
2162 _(
"Could not open %%files file %s: %s\n"),
2170 while (fgets(buf,
sizeof(buf), f)) {
2182 memset(&fl, 0,
sizeof(fl));
2241 for (fp = files; *fp != NULL; fp++) {
2268 for (i = 0; i < fl.
nLangs; i++)
2294 if (fileName == NULL)
2300 specialDoc =
_free(specialDoc);
2301 specialDoc =
xstrdup(fileName);
2321 if (installSpecialDoc) {
2322 int _missing_doc_files_terminate_build =
2327 if (rc && _missing_doc_files_terminate_build)
2345 for (i = 0; i < fl.
nLangs; i++)
2360 specialDoc =
_free(specialDoc);
2371 "PartialHardlinkSets",
"4.0.4-1");
2387 for (i = 0; i < fl.
nLangs; i++)
2458 if (sfp != NULL && *sfp != NULL)
2466 for (srcPtr = spec->
sources; srcPtr != NULL; srcPtr = srcPtr->
next) {
2469 "%{_sourcedir}/", srcPtr->
source, NULL);
2505 StringBuf sourceFiles, *sfp = &sourceFiles;
2513 _srcdefattr =
rpmExpand(
"%{?_srcdefattr}", NULL);
2520 memset(&fl, 0,
sizeof(fl));
2521 if (_srcdefattr && *_srcdefattr) {
2522 sprintf(buf,
"%%defattr %s", _srcdefattr);
2540 for (fp = files; *fp != NULL; fp++) {
2541 const char * diskURL, *diskPath;
2553 if (*diskURL ==
'!') {
2558 (void)
urlPath(diskURL, &diskPath);
2561 diskPath = strrchr(diskPath,
'/');
2572 diskURL, strerror(
errno));
2577 flp->fl_mode &= S_IFMT;
2626 static const char * av_ckfile[] = {
"%{?__check_files}", NULL };
2642 rc =
rpmfcExec(av_ckfile, fileList, &sb_stdout, 0);
2648 int _unpackaged_files_terminate_build =
2653 if ((*t !=
'\0') && (*t !=
'\n')) {
2654 rc = (_unpackaged_files_terminate_build) ? 1 : 0;
2656 _(
"Installed (but unpackaged) file(s) found:\n%s"), t);
2676 for (pkg = spec->
packages; pkg != NULL; pkg = pkg->
next) {
2677 const char *n, *v, *r;