9 #define MYALLPERMS 07777
11 #if defined(WITH_PCRE) && defined(WITH_PCRE_POSIX)
12 #include <pcreposix.h>
17 #define _RPMIOB_INTERNAL
25 #define _RPMTAG_INTERNAL
26 #define _RPMFI_INTERNAL
29 #define _RPMTE_INTERNAL
44 #define SKIPWHITE(_x) {while(*(_x) && (xisspace(*_x) || *(_x) == ',')) (_x)++;}
45 #define SKIPNONWHITE(_x){while(*(_x) &&!(xisspace(*_x) || *(_x) == ',')) (_x)++;}
47 #define MAXDOCDIR 1024
69 #define fl_dev fl_st.st_dev
70 #define fl_ino fl_st.st_ino
71 #define fl_mode fl_st.st_mode
72 #define fl_nlink fl_st.st_nlink
73 #define fl_uid fl_st.st_uid
74 #define fl_gid fl_st.st_gid
75 #define fl_rdev fl_st.st_rdev
76 #define fl_size fl_st.st_size
77 #define fl_mtime fl_st.st_mtime
204 static void dumpAttrRec(
const char * msg,
AttrRec ar)
209 fprintf(stderr,
"%s:\t", msg);
210 fprintf(stderr,
"(%s, %s, %s, %s)\n",
227 static char *olds = NULL;
236 s += strspn(s, delim);
245 s = strchr(token,
'"');
247 s = strpbrk(token, delim);
253 olds = strchr(token,
'\0');
271 HE_t he = memset(
alloca(
sizeof(*he)), 0,
sizeof(*he));
283 for (i = 0; i < he->
c; i++) {
284 xx = currentTime - mtime[i];
285 if (xx < 0) xx = -xx;
290 mtime =
_free(mtime);
336 if ((p = strstr(buf, (name =
"%verify"))) != NULL) {
339 }
else if ((p = strstr(buf, (name =
"%defverify"))) != NULL) {
345 for (pe = p; (size_t)(pe-p) < strlen(name); pe++)
358 for (p = pe; *pe && *pe !=
')'; pe++)
377 for (p = q; *p !=
'\0'; p = pe) {
387 for (vfa = verifyAttrs; vfa->
attribute != NULL; vfa++) {
390 verifyFlags |= vfa->
flag;
397 if (!strcmp(p,
"not")) {
406 *resultVerify = negated ? ~(verifyFlags) : verifyFlags;
412 #define isAttrDefault(_ars) ((_ars)[0] == '-' && (_ars)[1] == '\0')
425 const char * errstr = NULL;
429 if ((p = strstr(buf, (name =
"%dev"))) == NULL)
432 for (pe = p; (size_t)(pe-p) < strlen(name); pe++)
443 for (p = pe; *pe && *pe !=
')'; pe++)
458 pe = p;
SKIPNONWHITE(pe);
if (*pe !=
'\0') *pe++ =
'\0';
469 pe = p;
SKIPNONWHITE(pe);
if (*pe !=
'\0') *pe++ =
'\0';
470 for (pe = p; *pe &&
xisdigit(*pe); pe++)
487 pe = p;
SKIPNONWHITE(pe);
if (*pe !=
'\0') *pe++ =
'\0';
488 for (pe = p; *pe &&
xisdigit(*pe); pe++)
532 if ((p = strstr(buf, (name =
"%attr"))) != NULL) {
535 }
else if ((p = strstr(buf, (name =
"%defattr"))) != NULL) {
541 for (pe = p; (size_t)(pe-p) < strlen(name); pe++)
554 for (p = pe; *pe && *pe !=
')'; pe++)
557 if (ret_ar == &(fl->
def_ar)) {
563 _(
"Non-white space follows %s(): %s\n"), name, q);
580 pe = p;
SKIPNONWHITE(pe);
if (*pe !=
'\0') *pe++ =
'\0';
585 pe = p;
SKIPNONWHITE(pe);
if (*pe !=
'\0') *pe++ =
'\0';
590 pe = p;
SKIPNONWHITE(pe);
if (*pe !=
'\0') *pe++ =
'\0';
594 if (*p !=
'\0' && ret_ar == &(fl->
def_ar)) {
595 pe = p;
SKIPNONWHITE(pe);
if (*pe !=
'\0') *pe++ =
'\0';
600 if (!(ar->ar_fmodestr && ar->ar_user && ar->ar_group) || *p !=
'\0') {
609 x = sscanf(ar->ar_fmodestr,
"%o", &ui);
610 if ((x == 0) || (ar->ar_fmode & ~
MYALLPERMS)) {
617 ar->ar_fmodestr = NULL;
621 x = sscanf(ar->ar_dmodestr,
"%o", &ui);
622 if ((x == 0) || (ar->ar_dmode & ~
MYALLPERMS)) {
629 ar->ar_dmodestr = NULL;
657 if ((p = strstr(buf, (name =
"%config"))) == NULL)
663 for (pe = p; (size_t)(pe-p) < strlen(name); pe++)
671 for (p = pe; *pe && *pe !=
')'; pe++)
687 for (p = q; *p !=
'\0'; p = pe) {
695 if (!strcmp(p,
"missingok")) {
697 }
else if (!strcmp(p,
"noreplace")) {
711 static int langCmp(
const void * ap,
const void * bp)
714 return strcmp(*(
const char **)ap, *(
const char **)bp);
730 while ((p = strstr(buf, (name =
"%lang"))) != NULL) {
732 for (pe = p; (size_t)(pe-p) < strlen(name); pe++)
744 for (pe = p; *pe && *pe !=
')'; pe++)
761 for (p = q; *p !=
'\0'; p = pe) {
773 if (np < 1 || (np == 1 && *p !=
'C') || np >= 32) {
775 _(
"Unusual locale length: \"%.*s\" in %%lang(%s)\n"),
783 for (i = 0; i < fl->
nLangs; i++) {
796 strncpy(newp, p, np);
799 if (*pe ==
',') pe++;
816 static int initialized = 0;
817 static int hasRegex = 0;
818 static regex_t compiledPatt;
819 static char buf[BUFSIZ];
821 regmatch_t matches[2];
825 const char *patt =
rpmExpand(
"%{?_langpatt}", NULL);
827 if (!(patt && *patt !=
'\0'))
829 else if (regcomp(&compiledPatt, patt, REG_EXTENDED))
838 memset(matches, 0,
sizeof(matches));
839 if (! hasRegex || regexec(&compiledPatt, fileName, 2, matches, REG_NOTEOL))
843 s = fileName + matches[1].rm_eo - 1;
844 x = (int)matches[1].rm_eo - (
int)matches[1].rm_so;
872 {
"%spec", 0, RPMFILE_SPEC },
892 char * buf,
FileList fl,
const char ** fileName)
903 char specialDocBuf[BUFSIZ];
906 specialDocBuf[0] =
'\0';
912 if (!strcmp(s,
"%docdir")) {
929 #if defined(__LCLINT__)
935 for (vfa = virtualFileAttributes; vfa->
attribute != NULL; vfa++) {
939 if (!strcmp(s,
"%dir"))
966 strcat(specialDocBuf,
" ");
967 strcat(specialDocBuf, s);
973 const char * sfn = NULL;
978 _(
"File must begin with \"/\": %s\n"), s);
995 _(
"Can't mix special %%doc with other forms: %s\n"),
996 (*fileName ? *fileName :
""));
1003 static char *_docdir_fmt = NULL;
1004 static int oneshot = 0;
1005 const char *ddir, *fmt, *errstr;
1007 _docdir_fmt =
rpmExpand(
"%{?_docdir_fmt}", NULL);
1008 if (!(_docdir_fmt && *_docdir_fmt))
1009 _docdir_fmt =
_free(_docdir_fmt);
1012 if (_docdir_fmt == NULL)
1013 _docdir_fmt =
xstrdup(
"%{NAME}-%{VERSION}");
1037 mkdir_p =
rpmExpand(
"%{?__mkdir_p}%{!?__mkdir_p:mkdir -p}", NULL);
1039 mkdir_p =
xstrdup(
"mkdir -p");
1041 mkdir_p =
_free(mkdir_p);
1044 compress_doc =
rpmExpand(
"%{__compress_doc}", NULL);
1045 if (compress_doc && *compress_doc !=
'%')
1047 compress_doc =
_free(compress_doc);
1070 const char *a = NULL;
1072 const char *b = NULL;
1075 return strcmp(a, b);
1089 k = strlen(fileName);
1092 if (l < k && strncmp(fileName, fl->
docDirs[x], l) == 0 && fileName[l] ==
'/')
1112 if (!(S_ISREG(ilp->fl_mode) && ilp->fl_nlink > 1))
1119 if (!S_ISREG(jlp->fl_mode))
1121 if (ilp->fl_nlink != jlp->fl_nlink)
1123 if (ilp->fl_ino != jlp->fl_ino)
1125 if (ilp->fl_dev != jlp->fl_dev)
1135 static int dncmp(
const void * a,
const void * b)
1138 const char ** aurlp = (
const char **)a;
1139 const char ** burlp = (
const char **)b;
1144 return strcmp(adn, bdn);
1155 HE_t he = memset(
alloca(
sizeof(*he)), 0,
sizeof(*he));
1156 const char ** fileNames;
1158 const char ** dirNames;
1159 const char ** baseNames;
1180 fileNames = he->
p.
argv;
1182 if (!xx || fileNames == NULL || count <= 0)
1185 dirNames =
alloca(
sizeof(*dirNames) * count);
1186 baseNames =
alloca(
sizeof(*dirNames) * count);
1187 dirIndexes =
alloca(
sizeof(*dirIndexes) * count);
1189 (void)
urlPath(fileNames[0], &fn);
1193 dirNames[dirIndex] =
"";
1194 for (i = 0; i < count; i++) {
1195 dirIndexes[i] = dirIndex;
1196 baseNames[i] = fileNames[i];
1201 for (i = 0; i < count; i++) {
1202 const char ** needle;
1207 if (fileNames[i] == NULL)
1209 baseName = strrchr(fileNames[i],
'/') + 1;
1210 len = baseName - fileNames[i];
1212 savechar = *baseName;
1216 (needle = bsearch(&fileNames[i], dirNames, dirIndex + 1,
sizeof(dirNames[0]),
dncmp)) == NULL) {
1217 char *s =
alloca(len + 1);
1218 memcpy(s, fileNames[i], len + 1);
1220 dirIndexes[i] = ++dirIndex;
1221 dirNames[dirIndex] = s;
1223 dirIndexes[i] = needle - dirNames;
1226 *baseName = savechar;
1227 baseNames[i] = baseName;
1234 he->
p.
ui32p = dirIndexes;
1240 he->
p.
argv = baseNames;
1246 he->
p.
argv = dirNames;
1247 he->
c = dirIndex + 1;
1251 fileNames =
_free(fileNames);
1260 HE_t he = memset(
alloca(
sizeof(*he)), 0,
sizeof(*he));
1263 static int oneshot = 0;
1275 dalgo = (isSrc ? source_file_dalgo : binary_file_dalgo);
1324 HE_t he = memset(
alloca(
sizeof(*he)), 0,
sizeof(*he));
1328 int _addDotSlash = !isSrc;
1347 skipLen += strlen(fl->
prefix);
1350 sxfn =
rpmGetPath(
"%{?_build_file_context_path}", NULL);
1352 if (sxfn != NULL && *sxfn !=
'\0')
1356 for (i = 0, flp = fl->
fileList; i < fl->fileListRecsUsed; i++, flp++) {
1374 if (S_ISDIR(flp->fl_mode)) {
1377 flp[1].fl_mode = flp->fl_mode;
1381 flp[1].fl_mode = flp->fl_mode;
1388 flp[1].fl_uid = flp->fl_uid;
1396 flp[1].fl_gid = flp->fl_gid;
1415 apathlen += (strlen(apath) - skipLen + (_addDotSlash ? 3 : 1));
1418 dpathlen += (strlen(flp->
diskURL) + 2);
1515 if (S_ISREG(flp->fl_mode))
1544 const char * buildRoot;
1547 if (buf[0] ==
'/' && strcmp(buildRoot,
"/") &&
1548 !strncmp(buf, buildRoot, strlen(buildRoot))) {
1550 _(
"Symlink points to BuildRoot: %s -> %s\n"),
1581 if (S_ISDIR(flp->fl_mode))
1596 static char *nocon =
"";
1604 he->
p.
argv = (
const char **)&scon;
1611 if (scon != nocon) {
1618 if (sxfn != NULL && *sxfn !=
'\0') {
1636 if (fi == NULL)
return;
1643 fi->dnl =
_free(fi->dnl);
1644 fi->bnl =
_free(fi->bnl);
1645 if (!scareMem) fi->dil =
_free(fi->dil);
1648 fi->dnl =
xmalloc(fi->fc *
sizeof(*fi->dnl) + dpathlen + 1);
1649 d = (
char *)(fi->dnl + fi->fc);
1652 fi->bnl =
xmalloc(fi->fc * (
sizeof(*fi->bnl) +
sizeof(*fi->dil)));
1654 fi->dil = (!scareMem)
1655 ?
xcalloc(
sizeof(*fi->dil), fi->fc)
1660 fi->apath =
xmalloc(fi->fc *
sizeof(*fi->apath) + apathlen + 1);
1661 a = (
char *)(fi->apath + fi->fc);
1664 fi->actions =
_free(fi->actions);
1665 fi->actions =
xcalloc(
sizeof(*fi->actions), fi->fc);
1666 fi->fmapflags =
xcalloc(
sizeof(*fi->fmapflags), fi->fc);
1671 fi->fuser =
_free(fi->fuser);
1672 fi->fgroup =
_free(fi->fgroup);
1675 if (fi->dil != NULL)
1676 for (i = 0, flp = fl->
fileList; (
unsigned)i < fi->fc; i++, flp++) {
1691 size_t fnlen = strlen(flp->
diskURL);
1692 if (fnlen > fi->fnlen) {
1694 assert(fi->fn == NULL);
1703 fi->dnl[fi->dil[i]] = d;
1708 for (b = d; b > fi->dnl[fi->dil[i]] && *b !=
'/'; b--)
1722 a =
stpcpy(a, (apath + skipLen));
1735 if (S_ISREG(flp->fl_mode)) {
1738 if (flp->fl_nlink > 1) {
1741 for (; (unsigned)j < fi->fc; j++, jlp++) {
1752 if (!S_ISREG(jlp->fl_mode))
1754 if (flp->fl_nlink != jlp->fl_nlink)
1756 if (flp->fl_ino != jlp->fl_ino)
1758 if (flp->fl_dev != jlp->fl_dev)
1792 fileList[count].
diskURL =
_free(fileList[count].diskURL);
1793 fileList[count].
fileURL =
_free(fileList[count].fileURL);
1794 fileList[count].
langs =
_free(fileList[count].langs);
1796 fileList =
_free(fileList);
1818 struct stat * statp)
1827 const char *fn =
xstrdup(diskURL);
1828 const char *fileURL = fn;
1829 struct stat statbuf;
1833 const char *fileUname;
1834 const char *fileGname;
1849 {
const char *fileName;
1853 fileURL += (fileName - fileURL);
1856 const char * s = fileURL + nb;
1857 char * t = (
char *) fileURL;
1858 (void) memmove(t, s, nb);
1870 if (*fileURL ==
'\0')
1875 const char *prefixTest;
1876 const char *prefixPtr = fl->
prefix;
1878 (void)
urlPath(fileURL, &prefixTest);
1879 while (*prefixPtr && *prefixTest && (*prefixTest == *prefixPtr)) {
1883 if (*prefixPtr || (*prefixTest && *prefixTest !=
'/')) {
1892 if (statp == NULL) {
1894 memset(statp, 0,
sizeof(*statp));
1896 time_t now = time(NULL);
1899 statp->st_nlink = 1;
1902 statp->st_dev = statp->st_rdev;
1903 statp->st_mode = (fl->
devtype ==
'b' ? S_IFBLK : S_IFCHR);
1905 statp->st_atime = now;
1906 statp->st_mtime = now;
1907 statp->st_ctime = now;
1908 }
else if (
Lstat(diskURL, statp)) {
1921 if ((! fl->
isDir) && S_ISDIR(statp->st_mode)) {
1928 fileMode = statp->st_mode;
1929 fileUid = statp->st_uid;
1930 fileGid = statp->st_gid;
1951 if (fileUname == NULL)
1953 if (fileGname == NULL)
1966 flp->
fl_st = *statp;
1967 flp->fl_mode = fileMode;
1968 flp->fl_uid = fileUid;
1969 flp->fl_gid = fileGid;
1973 flp->
uname = fileUname;
1974 flp->
gname = fileGname;
1980 for (i = 0; i < fl->
nLangs; i++)
1984 for (i = 0; i < fl->
nLangs; i++) {
1986 if (i) *ncl++ =
'|';
2027 ftsSet[0] = (
char *) diskURL;
2029 ftsp =
Fts_open(ftsSet, myFtsOpts, NULL);
2030 while ((fts =
Fts_read(ftsp)) != NULL) {
2083 HE_t he = memset(
alloca(
sizeof(*he)), 0,
sizeof(*he));
2084 const char * buildURL =
"%{_builddir}/%{?buildsubdir}/";
2085 const char * fn = NULL;
2086 const char * apkt = NULL;
2108 if ((xx =
pgpReadPkts(fn, &pkt, (
size_t *)&pktlen)) <= 0) {
2120 if (!(xx == 0 && iob != NULL)) {
2124 apkt = (
const char *) iob->b;
2161 const char * fileURL)
2170 const char *diskURL = NULL;
2177 {
const char * fileName;
2178 (void)
urlPath(fileURL, &fileName);
2179 if (*fileName !=
'/') {
2198 const char ** argv = NULL;
2210 xx =
rpmGlob(diskURL, &argc, &argv);
2211 if (xx == 0 && argc >= 1) {
2212 for (i = 0; i < argc; i++) {
2213 rc =
addFile(fl, argv[i], NULL);
2214 argv[i] =
_free(argv[i]);
2230 rc =
addFile(fl, diskURL, NULL);
2233 diskURL =
_free(diskURL);
2242 int installSpecialDoc,
int test)
2249 HE_t he = memset(
alloca(
sizeof(*he)), 0,
sizeof(*he));
2253 const char *fileName;
2256 AttrRec specialDocAttrRec = &arbuf;
2257 char *specialDoc = NULL;
2264 char *saveptr = NULL;
2267 char *token = strtok_r(filesFiles,
",", &saveptr);
2275 if (*token ==
'/') {
2284 fd =
Fopen(ffn,
"r.fpio");
2286 if (fd == NULL ||
Ferror(fd)) {
2288 _(
"Could not open %%files file %s: %s\n"),
2296 while (fgets(buf, (
int)
sizeof(buf), f)) {
2306 }
while((token = strtok_r(NULL,
",", &saveptr)) != NULL);
2307 filesFiles =
_free(filesFiles);
2311 memset(&fl, 0,
sizeof(fl));
2348 #if defined(RPM_VENDOR_OPENPKG)
2372 for (fp = files; *fp != NULL; fp++) {
2380 strncpy(buf, s,
sizeof(buf)-1);
2381 buf[
sizeof(buf)-1] =
'\0';
2401 for (i = 0; i < fl.
nLangs; i++)
2427 if (fileName == NULL)
2432 specialDoc =
_free(specialDoc);
2433 specialDoc =
xstrdup(fileName);
2452 if (installSpecialDoc) {
2453 int _missing_doc_files_terminate_build =
2458 if (rc !=
RPMRC_OK && _missing_doc_files_terminate_build)
2476 for (i = 0; i < fl.
nLangs; i++)
2491 specialDoc =
_free(specialDoc);
2502 "PartialHardlinkSets",
"4.0.4-1");
2518 for (i = 0; i < fl.
nLangs; i++)
2533 HE_t he = memset(
alloca(
sizeof(*he)), 0,
sizeof(*he));
2537 static rpmTag classTag = 0xffffffff;
2541 if (classTag == 0xffffffff)
2574 #if defined(RPM_VENDOR_OPENPKG)
2584 if (classTag == he->
tag && he->
p.
ptr != NULL)
2601 for (i = 0; i < spec->
nfoo; i++) {
2602 const char * str = spec->
foo[i].str;
2607 if (str == NULL || iob == NULL)
2613 if (!(he->
p.
str != NULL && he->
p.
str[0] !=
'\0')) {
2629 he->
p.
argv = (
const char **) &s;
2641 if (sfp != NULL && *sfp != NULL)
2649 for (srcPtr = spec->
sources; srcPtr != NULL; srcPtr = srcPtr->
next) {
2653 #
if defined(RPM_VENDOR_OPENPKG)
2716 rpmiob sourceFiles, *sfp = &sourceFiles;
2723 char _srcdefattr_buf[BUFSIZ];
2727 _srcdefattr =
rpmExpand(
"%{?_srcdefattr}", NULL);
2733 memset(&fl, 0,
sizeof(fl));
2734 if (_srcdefattr && *_srcdefattr) {
2735 xx =
snprintf(_srcdefattr_buf,
sizeof(_srcdefattr_buf),
"%%defattr %s", _srcdefattr);
2736 _srcdefattr_buf[
sizeof(_srcdefattr_buf)-1] =
'\0';
2752 for (fp = files; *fp != NULL; fp++) {
2753 const char * diskURL, *diskPath;
2765 if (*diskURL ==
'!') {
2770 (void)
urlPath(diskURL, &diskPath);
2773 diskPath = strrchr(diskPath,
'/');
2784 diskURL, strerror(
errno));
2788 #if defined(RPM_VENDOR_OPENPKG)
2791 flp->fl_mode &= S_IFMT;
2836 static const char * av_ckfile[] = {
"%{?__check_files}", NULL };
2838 rpmiob iob_stdout = NULL;
2854 for (pkg = spec->
packages; pkg != NULL; pkg = pkg->
next) {
2874 rc =
rpmfcExec(av_ckfile, fileList, &iob_stdout, 0);
2879 int _unpackaged_files_terminate_build =
2884 if ((*t !=
'\0') && (*t !=
'\n')) {
2885 rc = (_unpackaged_files_terminate_build) ? 1 : 0;
2887 _(
"Installed (but unpackaged) file(s) found:\n%s"), t);
2906 const char *fn1, *fn2;
2919 if (strcmp(fn1, fn2))
2930 const char *N1, *N2;
2931 HE_t he = memset(
alloca(
sizeof(*he)), 0,
sizeof(*he));
2939 _(
"File(s) packaged into both %s and %s:\n%s"),
2965 for (pkg2 = pkg1->
next; pkg2; pkg2 = pkg2->
next) {
2991 if (strcmp(fn, d) == 0) {
3014 char **unpackaged = NULL;
3031 while ((p = strchr(p + 1,
'/'))) {
3042 while ((p = strchr(p + 1,
'/'))) {
3050 for (j = 0; j < n; j++)
3051 if (strcmp(fn, unpackaged[j]) == 0) {
3059 unpackaged =
xrealloc(unpackaged,
sizeof(*unpackaged) * (n + 1));
3060 unpackaged[n++] =
xstrdup(fn);
3068 HE_t he = memset(
alloca(
sizeof(*he)), 0,
sizeof(*he));
3074 for (i = 0; i < n; i++) {
3077 unpackaged[i] =
_free(unpackaged[i]);
3079 unpackaged =
_free(unpackaged);
3082 _(
"Unpackaged subdir(s) in %s:\n%s"),
3113 HE_t he = memset(
alloca(
sizeof(*he)), 0,
sizeof(*he));
3117 for (pkg = spec->
packages; pkg != NULL; pkg = pkg->
next) {