13 #define _RPMFI_INTERNAL
16 #define _IOSM_INTERNAL
18 #define fsmUNSAFE fsmStage
20 #if defined(SUPPORT_AR_PAYLOADS)
27 #if defined(_USE_RPMTE)
48 #define alloca_strdup(_s) strcpy(alloca(strlen(_s)+1), (_s))
67 const FSMI_t iter = fsm->iter;
69 return (iter ? iter->ts : NULL);
81 const FSMI_t iter = fsm->iter;
83 return (iter ? iter->fi : NULL);
87 #define SUFFIX_RPMORIG ".rpmorig"
88 #define SUFFIX_RPMSAVE ".rpmsave"
89 #define SUFFIX_RPMNEW ".rpmnew"
101 const struct stat * st,
107 const char * s = NULL;
112 nb = strlen(fsm->dirName) +
113 (st && !S_ISDIR(st->st_mode) ? (subdir ? strlen(subdir) : 0) : 0) +
114 (st && !S_ISDIR(st->st_mode) ? (suffix ? strlen(suffix) : 0) : 0) +
115 strlen(fsm->baseName) + 1;
117 t =
stpcpy(t, fsm->dirName);
118 if (st && !S_ISDIR(st->st_mode))
119 if (subdir) t =
stpcpy(t, subdir);
120 t =
stpcpy(t, fsm->baseName);
121 if (st && !S_ISDIR(st->st_mode))
122 if (suffix) t =
stpcpy(t, suffix);
159 iter =
xcalloc(1,
sizeof(*iter));
164 iter->i = (iter->reverse ? (fi->fc - 1) : 0);
165 iter->isave = iter->i;
182 const rpmfi fi = iter->fi;
185 if (iter->i >= 0) i = iter->i--;
187 if (iter->i < (
int)fi->fc) i = iter->i++;
199 const char * aurl = *(
const char **)a;
200 const char * burl = *(
const char **)b;
201 const char * afn = NULL;
202 const char * bfn = NULL;
207 #ifdef VERY_OLD_BUGGY_RPM_PACKAGES
209 if (strchr(afn,
'/') == NULL)
210 bfn = strrchr(bfn,
'/') + 1;
214 if (afn[0] ==
'.' && afn[1] ==
'/') afn += 2;
215 if (bfn[0] ==
'.' && bfn[1] ==
'/') bfn += 2;
218 if (afn[0] ==
'/') afn += 1;
219 if (bfn[0] ==
'/') bfn += 1;
221 return strcmp(afn, bfn);
237 const rpmfi fi = iter->fi;
240 if (fi && fc > 0 && fi->apath && fsmPath && *fsmPath) {
241 const char ** p = NULL;
243 if (fi->apath != NULL)
244 p = bsearch(&fsmPath, fi->apath, fc,
sizeof(fsmPath),
247 iter->i = p - fi->apath;
287 return (
int) (dnli ? dnli->
fi->dc : 0);
295 return (dnli ? dnli->
isave : -1);
318 dnli =
xcalloc(1,
sizeof(*dnli));
321 dnli->
i = (int) (reverse ? fi->dc : 0);
338 if (!S_ISDIR(fi->fmodes[i]))
342 dnlen = strlen(fi->dnl[dil]);
343 bnlen = strlen(fi->bnl[i]);
345 for (j = 0; j < (int)fi->dc; j++) {
348 if (!dnli->
active[j] || j == (
int)dil)
350 (void)
urlPath(fi->dnl[j], &dnl);
352 if (jlen != (dnlen+bnlen+1))
354 if (strncmp(dnl, fi->dnl[dil], dnlen))
356 if (strncmp(dnl+dnlen, fi->bnl[i], bnlen))
358 if (dnl[dnlen+bnlen] !=
'/' || dnl[dnlen+bnlen+1] !=
'\0')
369 for (i = 0; i < (int)fi->dc; i++) {
370 if (!dnli->
active[i])
continue;
374 D_(
"========== Directories not explicitly included in package:\n"));
376 (void)
urlPath(fi->dnl[i], &dnl);
396 const char * dn = NULL;
404 i = (!dnli->
reverse ? dnli->
i++ : --dnli->
i);
405 }
while (i >= 0 && i < (
int)fi->dc && !dnli->
active[i]);
407 if (i >= 0 && i < (
int)fi->dc)
416 #if defined(WITH_PTHREADS)
417 static void * fsmThread(
void * arg)
423 return ((
void *) ((
long)
fsmStage(fsm, fsm->nstage)));
432 fsm->nstage = nstage;
433 #if defined(WITH_PTHREADS)
434 if (fsm->multithreaded)
452 struct stat * st = &fsm->sb;
458 for (fsm->li = fsm->links; fsm->li; fsm->li = fsm->li->next) {
459 if (fsm->li->sb.st_ino == st->st_ino && fsm->li->sb.st_dev == st->st_dev)
464 if (fsm->li == NULL) {
465 fsm->li =
xcalloc(1,
sizeof(*fsm->li));
466 fsm->li->next = NULL;
468 fsm->li->nlink = (int) st->st_nlink;
469 fsm->li->linkIndex = fsm->ix;
470 fsm->li->createdPath = -1;
472 fsm->li->filex =
xcalloc(st->st_nlink,
sizeof(fsm->li->filex[0]));
473 memset(fsm->li->filex, -1, (st->st_nlink *
sizeof(fsm->li->filex[0])));
474 fsm->li->nsuffix =
xcalloc(st->st_nlink,
sizeof(*fsm->li->nsuffix));
477 fsm->li->linksLeft = (int) st->st_nlink;
479 fsm->li->linksLeft = 0;
482 fsm->li->next = fsm->links;
484 fsm->links = fsm->li;
488 fsm->li->filex[fsm->li->linksLeft] = fsm->ix;
490 fsm->li->nsuffix[fsm->li->linksLeft] = fsm->nsuffix;
495 return (fsm->li->linksLeft > 0);
500 if (!(st->st_size || fsm->li->linksLeft == (
int) st->st_nlink))
506 for (j = fsm->li->linksLeft - 1; j >= 0; j--) {
507 ix = fsm->li->filex[j];
519 fsm->li->linkIndex = j;
520 fsm->path =
_free(fsm->path);
535 li->nsuffix =
_free(li->nsuffix);
536 li->filex =
_free(li->filex);
550 fsm->path =
_free(fsm->path);
551 while ((fsm->li = fsm->links) != NULL) {
552 fsm->links = fsm->li->next;
553 fsm->li->next = NULL;
556 fsm->dnlx =
_free(fsm->dnlx);
557 fsm->ldn =
_free(fsm->ldn);
563 #if defined(SUPPORT_AR_PAYLOADS)
577 const char * apath = NULL;
578 (void)
urlPath(fi->apath[ix], &apath);
579 path = apath + fi->striplen;
583 if ((nb = strlen(path)) < 15)
593 fsm->lmtab = t =
xmalloc(lmtablen + 1);
594 fsm->lmtablen = lmtablen;
600 const char * apath = NULL;
601 (void)
urlPath(fi->apath[ix], &apath);
602 path = apath + fi->striplen;
606 if ((nb = strlen(path)) < 15)
618 const void * _ts,
const void *
_fi,
FD_t cfd,
619 unsigned int * archiveSize,
const char ** failedFile)
626 #if defined(_USE_RPMTE)
638 fsm->adding = adding;
642 fprintf(stderr,
"--> fsmSetup(%p, 0x%x, \"%s\", %p, %p, %p, %p, %p)\n", fsm, goal, afmt, (
void *)ts, fi, cfd, archiveSize, failedFile);
646 if (fsm->headerRead == NULL) {
647 if (afmt != NULL && (!strcmp(afmt,
"tar") || !strcmp(afmt,
"ustar"))) {
649 fprintf(stderr,
"\ttar vectors set\n");
655 #if defined(SUPPORT_AR_PAYLOADS)
656 if (afmt != NULL && !strcmp(afmt,
"ar")) {
658 fprintf(stderr,
"\tar vectors set\n");
669 fprintf(stderr,
"\tcpio vectors set\n");
680 fsm->cfd =
fdLink(cfd,
"persist (fsm)");
688 fsm->iter->ts =
rpmtsLink(ts,
"mapIterator");
695 #define _tsmask (RPMTRANS_FLAG_PKGCOMMIT | RPMTRANS_FLAG_COMMIT)
708 fsm->archiveSize = archiveSize;
709 if (fsm->archiveSize)
710 *fsm->archiveSize = 0;
711 fsm->failedFile = failedFile;
713 *fsm->failedFile = NULL;
716 memset(fsm->sufbuf, 0,
sizeof(fsm->sufbuf));
719 sprintf(fsm->sufbuf,
";%08x", (
unsigned)
rpmtsGetTid(ts));
726 if (rc && !ec) ec = rc;
731 if (rc && !ec) ec = rc;
733 if (fsm->archiveSize && ec == 0)
747 fprintf(stderr,
"--> fsmTeardown(%p)\n", fsm);
754 fsm->lmtab =
_free(fsm->lmtab);
756 fsm->iter->ts = NULL;
758 if (fsm->cfd != NULL) {
760 fsm->cfd =
fdFree(fsm->cfd,
"persist (fsm)");
764 fsm->failedFile = NULL;
776 fsm->fcontext = NULL;
777 if (!fsm->nofcontexts) {
780 int xx =
matchpathcon(fsm->path, fsm->sb.st_mode, &scon);
783 if (!xx && scon != NULL)
784 fsm->fcontext = scon;
791 if (fi && i >= 0 && i < (
int)fi->fc)
792 fsm->fcontext = (fi->fcontexts ? fi->fcontexts[i] : NULL);
802 int teAdding = fsm->adding;
810 fsm->mapFlags = fi->mapflags;
812 if (fi && i >= 0 && i < (
int)fi->fc) {
814 fsm->astriplen = fi->astriplen;
815 fsm->action = (fi->actions ? fi->actions[i] : fi->action);
816 fsm->fflags = (fi->fflags ? fi->fflags[i] : fi->flags);
817 fsm->mapFlags = (fi->fmapflags ? fi->fmapflags[i] : fi->mapflags);
820 fsm->dirName = fi->dnl[fi->dil[i]];
821 fsm->baseName = fi->bnl[i];
823 switch (fsm->action) {
837 if (fi->fstates && teAdding)
842 if (fi->fstates && teAdding)
847 if (fi->fstates && teAdding)
881 const struct stat * st = &fsm->sb;
882 fsm->path =
_free(fsm->path);
883 fsm->path =
fsmFsPath(fsm, st, fsm->subdir,
884 (fsm->suffix ? fsm->suffix : fsm->nsuffix));
892 struct stat * st = &fsm->sb;
896 if (fi && i >= 0 && i < (
int) fi->fc) {
897 mode_t perms = (S_ISDIR(st->st_mode) ? fi->dperms : fi->fperms);
898 mode_t finalMode = (fi->fmodes ? (mode_t)fi->fmodes[i] : perms);
899 dev_t finalRdev = (dev_t)(fi->frdevs ? fi->frdevs[i] : 0);
900 rpmuint32_t finalMtime = (fi->fmtimes ? fi->fmtimes[i] : 0);
904 #if defined(RPM_VENDOR_OPENPKG) || defined(RPM_VENDOR_MANDRIVA) || defined(RPM_VENDOR_ARK)
912 if (fi->fuser &&
unameToUid(fi->fuser[i], &uid)) {
913 #if defined(RPM_VENDOR_OPENPKG) ||defined(RPM_VENDOR_MANDRIVA) || defined(RPM_VENDOR_ARK)
918 _(
"user %s does not exist - using root\n"), fi->fuser[i]);
920 finalMode &= ~S_ISUID;
921 #if defined(RPM_VENDOR_OPENPKG) || defined(RPM_VENDOR_MANDRIVA) || defined(RPM_VENDOR_ARK)
926 if (fi->fgroup &&
gnameToGid(fi->fgroup[i], &gid)) {
927 #if defined(RPM_VENDOR_OPENPKG) || defined(RPM_VENDOR_MANDRIVA) || defined(RPM_VENDOR_ARK)
932 _(
"group %s does not exist - using root\n"), fi->fgroup[i]);
934 finalMode &= ~S_ISGID;
935 #if defined(RPM_VENDOR_OPENPKG) || defined(RPM_VENDOR_MANDRIVA) || defined(RPM_VENDOR_ARK)
941 st->st_mode = (st->st_mode & S_IFMT) | (finalMode & ~S_IFMT);
943 st->st_mode = (st->st_mode & ~S_IFMT) | (finalMode & S_IFMT);
944 if ((S_ISCHR(st->st_mode) || S_ISBLK(st->st_mode))
945 && st->st_nlink == 0)
947 st->st_rdev = finalRdev;
948 st->st_mtime = finalMtime;
958 if (!fsm->nofdigests) {
959 fsm->fdigestalgo = fi->digestalgo;
960 fsm->fdigest = (fi->fdigests ? fi->fdigests[i] : NULL);
961 fsm->digestlen = fi->digestlen;
962 fsm->digest = (fi->digests ? (fi->digests + (fsm->digestlen * i)) : NULL);
964 fsm->fdigestalgo = 0;
984 const struct stat * st = &fsm->sb;
985 size_t left = (size_t) st->st_size;
993 if (st->st_size > 0 && (fsm->fdigest != NULL || fsm->digest != NULL))
998 fsm->wrlen = (left > fsm->wrsize ? fsm->wrsize : left);
1014 xx = fsync(
Fileno(fsm->wfd));
1016 if (st->st_size > 0 && (fsm->fdigest || fsm->digest)) {
1017 void * digest = NULL;
1018 int asAscii = (fsm->digest == NULL ? 1 : 0);
1021 fdFiniDigest(fsm->wfd, fsm->fdigestalgo, &digest, NULL, asAscii);
1023 if (digest == NULL) {
1024 rc = IOSMERR_DIGEST_MISMATCH;
1028 if (fsm->digest != NULL) {
1029 if (memcmp(digest, fsm->digest, fsm->digestlen))
1030 rc = IOSMERR_DIGEST_MISMATCH;
1032 if (strcmp(digest, fsm->fdigest))
1033 rc = IOSMERR_DIGEST_MISMATCH;
1035 digest =
_free(digest);
1056 const char * path = fsm->path;
1057 const char * opath = fsm->opath;
1058 struct stat * st = &fsm->sb;
1059 struct stat * ost = &fsm->osb;
1064 st->st_size = (writeData ? ost->st_size : 0);
1066 if (S_ISDIR(st->st_mode)) {
1068 }
else if (
S_ISLNK(st->st_mode)) {
1076 st->st_size = fsm->rdnb;
1077 fsm->lpath =
xstrdup(fsm->rdbuf);
1081 size_t nb= strlen(fsm->dirName) + strlen(fsm->baseName) +
sizeof(
".");
1091 const char * apath = NULL;
1092 (void)
urlPath(fi->apath[fsm->ix], &apath);
1093 fsm->path = apath + fi->striplen;
1095 fsm->path = fi->bnl[fsm->ix];
1102 if (writeData && S_ISREG(st->st_mode)) {
1103 #if defined(HAVE_MMAP)
1104 char * rdbuf = NULL;
1105 void * mapped = (
void *)-1;
1108 int use_mmap = (st->st_size <= 0x07ffffff);
1115 #if defined(HAVE_MMAP)
1117 mapped = mmap(NULL, st->st_size, PROT_READ, MAP_SHARED,
Fileno(fsm->rfd), 0);
1118 if (mapped != (
void *)-1) {
1120 fsm->rdbuf = (
char *) mapped;
1121 fsm->rdlen = nmapped = st->st_size;
1122 #if defined(HAVE_MADVISE) && defined(MADV_DONTNEED)
1123 xx = madvise(mapped, nmapped, MADV_DONTNEED);
1132 #if defined(HAVE_MMAP)
1133 if (mapped != (
void *)-1) {
1134 fsm->rdnb = nmapped;
1138 fsm->rdlen = (left > fsm->rdsize ? fsm->rdsize : left),
1150 #if defined(HAVE_MMAP)
1151 if (mapped != (
void *)-1) {
1153 xx = msync(mapped, nmapped, MS_ASYNC);
1154 #if defined(HAVE_MADVISE) && defined(MADV_DONTNEED)
1155 xx = madvise(mapped, nmapped, MADV_DONTNEED);
1157 xx = munmap(mapped, nmapped);
1161 xx = fsync(
Fileno(fsm->rfd));
1171 if (fsm->rfd != NULL)
1191 const char * path = fsm->path;
1192 const char * lpath = fsm->lpath;
1193 const char * nsuffix = fsm->nsuffix;
1194 int iterIndex = fsm->ix;
1198 const char * linkpath = NULL;
1203 fsm->nsuffix = NULL;
1206 for (i = fsm->li->nlink - 1; i >= 0; i--) {
1208 if (fsm->li->filex[i] < 0)
continue;
1210 fsm->ix = fsm->li->filex[i];
1218 const char * apath = NULL;
1220 (void)
urlPath(fsm->path, &apath);
1222 t =
xmalloc(
sizeof(
".") + strlen(apath + fsm->astriplen));
1223 (void)
stpcpy(
stpcpy(t,
"."), apath + fsm->astriplen);
1227 fsm->lpath = linkpath;
1230 rc =
writeFile(fsm, (fsm->lpath == NULL));
1235 if (fsm->failedFile && rc != 0 && *fsm->failedFile == NULL) {
1237 *fsm->failedFile =
xstrdup(fsm->path);
1240 fsm->path =
_free(fsm->path);
1241 fsm->li->filex[i] = -1;
1245 linkpath =
_free(linkpath);
1247 fsm->ix = iterIndex;
1248 fsm->nsuffix = nsuffix;
1265 const char * path = fsm->path;
1266 const char * opath = fsm->opath;
1267 const char * nsuffix = fsm->nsuffix;
1268 int iterIndex = fsm->ix;
1275 fsm->nsuffix = NULL;
1278 fsm->ix = fsm->li->filex[fsm->li->createdPath];
1280 fsm->opath = fsm->path;
1282 for (i = 0; i < fsm->li->nlink; i++) {
1283 if (fsm->li->filex[i] < 0)
continue;
1284 if (fsm->li->createdPath == i)
continue;
1286 fsm->ix = fsm->li->filex[i];
1287 fsm->path =
_free(fsm->path);
1293 if (!(rc == IOSMERR_ENOENT))
break;
1297 if (fsm->failedFile && rc != 0 && *fsm->failedFile == NULL) {
1299 *fsm->failedFile =
xstrdup(fsm->path);
1302 fsm->li->linksLeft--;
1304 fsm->path =
_free(fsm->path);
1305 fsm->opath =
_free(fsm->opath);
1307 fsm->ix = iterIndex;
1308 fsm->nsuffix = nsuffix;
1327 const char * path = fsm->path;
1328 const char * nsuffix = fsm->nsuffix;
1329 int iterIndex = fsm->ix;
1330 struct stat * st = &fsm->sb;
1335 fsm->nsuffix = NULL;
1338 for (fsm->li = fsm->links; fsm->li; fsm->li = fsm->li->next) {
1339 if (fsm->li->sb.st_ino == st->st_ino && fsm->li->sb.st_dev == st->st_dev)
1343 for (i = 0; i < fsm->li->nlink; i++) {
1344 if (fsm->li->filex[i] < 0)
continue;
1345 fsm->ix = fsm->li->filex[i];
1349 fsm->path =
_free(fsm->path);
1350 fsm->li->filex[i] = -1;
1353 fsm->ix = iterIndex;
1354 fsm->nsuffix = nsuffix;
1370 const char * path = fsm->path;
1372 char * dn = fsm->rdbuf;
1379 if (fsm->ldn != NULL && fsm->dnlx != NULL)
1381 size_t dnlen = strlen(fsm->path);
1385 if (fsm->dnlx[dc] < 1 || (
size_t)fsm->dnlx[dc] >= dnlen)
1389 te =
stpcpy(dn, fsm->path) - 1;
1405 }
while ((te - fsm->path) > fsm->dnlx[dc]);
1427 struct stat * st = &fsm->sb;
1428 struct stat * ost = &fsm->osb;
1429 const char * path = fsm->path;
1430 mode_t st_mode = st->st_mode;
1432 char * dn = fsm->rdbuf;
1440 fsm->dnlx = (dc ?
xcalloc(dc,
sizeof(*fsm->dnlx)) : NULL);
1442 if (fsm->dnlx != NULL)
1444 size_t dnlen = strlen(fsm->path);
1448 if (dc < 0)
continue;
1449 fsm->dnlx[
dc] = (
unsigned short) dnlen;
1454 if (dnlen <= fsm->ldnlen && !strcmp(fsm->path, fsm->ldn))
1459 (void)
stpcpy(dn, fsm->path);
1463 (void)
urlPath(dn, (
const char **)&te);
1464 for (i = 1, te++; *te !=
'\0'; te++, i++) {
1472 if (i < fsm->ldnlen &&
1473 (fsm->ldn[i] ==
'/' || fsm->ldn[i] ==
'\0') &&
1474 !strncmp(fsm->path, fsm->ldn, i))
1478 fsm->dnlx[
dc] = (te - dn);
1488 if (rc == 0 && S_ISDIR(ost->st_mode)) {
1490 fsm->dnlx[
dc] = (te - dn);
1491 }
else if (rc == IOSMERR_ENOENT) {
1494 st->st_mode = S_IFDIR | (fi->dperms & 07777);
1501 if (!fsm->nofcontexts
1506 fsm->fcontext = scon;
1509 fsm->fcontext = NULL;
1510 if (fsm->fcontext == NULL)
1512 D_(
"%s directory created with perms %04o, no context.\n"),
1513 fsm->path, (
unsigned)(st->st_mode & 07777));
1516 D_(
"%s directory created with perms %04o, context %s.\n"),
1517 fsm->path, (
unsigned)(st->st_mode & 07777),
1519 fsm->fcontext = NULL;
1532 if (fsm->ldnalloc < (dnlen + 1)) {
1533 fsm->ldnalloc = dnlen + 100;
1534 fsm->ldn =
xrealloc(fsm->ldn, fsm->ldnalloc);
1536 if (fsm->ldn != NULL) {
1537 strcpy(fsm->ldn, fsm->path);
1538 fsm->ldnlen = dnlen;
1546 st->st_mode = st_mode;
1558 static int fsmStat(
IOSM_t fsm)
1564 if (fsm->path != NULL) {
1565 int saveernno =
errno;
1568 if (rc == IOSMERR_ENOENT) {
1572 }
else if (rc == 0) {
1583 #define IS_DEV_LOG(_x) \
1584 ((_x) != NULL && strlen(_x) >= (sizeof("/dev/log")-1) && \
1585 !strncmp((_x), "/dev/log", sizeof("/dev/log")-1) && \
1586 ((_x)[sizeof("/dev/log")-1] == '\0' || \
1587 (_x)[sizeof("/dev/log")-1] == ';'))
1597 struct stat * st = &fsm->sb;
1598 struct stat * ost = &fsm->osb;
1599 int saveerrno =
errno;
1603 #define _fafilter(_a) \
1604 (!((_a) == FA_CREATE || (_a) == FA_ERASE || (_a) == FA_COPYIN || (_a) == FA_COPYOUT) \
1605 ? iosmFileActionString(_a) : "")
1613 (
unsigned)st->st_mode, (
int)st->st_nlink,
1614 (
int)st->st_uid, (
int)st->st_gid, (
unsigned long)st->st_size,
1615 (fsm->path ? fsm->path :
""),
1618 const char * apath = NULL;
1620 (void)
urlPath(fsm->path, &apath);
1625 (
unsigned)st->st_mode, (int)st->st_nlink,
1626 (
int)st->st_uid, (int)st->st_gid, (
unsigned long)st->st_size,
1627 (apath ? apath + fsm->astriplen :
""),
1641 if (rc == IOSMERR_HDR_TRAILER) {
1676 if (rc == IOSMERR_HDR_TRAILER) {
1692 if (rc == IOSMERR_HDR_TRAILER) {
1721 while ((fsm->li = fsm->links) != NULL) {
1722 fsm->links = fsm->li->next;
1723 fsm->li->next = NULL;
1726 for (j = -1, nlink = 0, i = 0; i < fsm->li->nlink; i++) {
1727 if (fsm->li->filex[i] < 0)
1734 fsm->li->filex[0] = fsm->li->filex[j];
1735 fsm->li->filex[j] = -1;
1737 fsm->li->sb.st_nlink = nlink;
1739 fsm->sb = fsm->li->sb;
1753 fsm->path =
_free(fsm->path);
1754 fsm->lpath =
_free(fsm->lpath);
1755 fsm->opath =
_free(fsm->opath);
1756 fsm->dnlx =
_free(fsm->dnlx);
1758 fsm->ldn =
_free(fsm->ldn);
1759 fsm->ldnalloc = fsm->ldnlen = 0;
1761 fsm->rdsize = fsm->wrsize = 0;
1762 fsm->rdbuf = fsm->rdb =
_free(fsm->rdb);
1763 fsm->wrbuf = fsm->wrb =
_free(fsm->wrb);
1765 fsm->rdsize = 16 * BUFSIZ;
1766 fsm->rdbuf = fsm->rdb =
xmalloc(fsm->rdsize);
1767 fsm->wrsize = 16 * BUFSIZ;
1768 fsm->wrbuf = fsm->wrb =
xmalloc(fsm->wrsize);
1771 fsm->mkdirsdone = 0;
1782 if (!rc) fsm->mkdirsdone = 1;
1787 fsm->path =
_free(fsm->path);
1788 fsm->lpath =
_free(fsm->lpath);
1790 fsm->diskchecked = fsm->exists = 0;
1792 fsm->suffix = (fsm->sufbuf[0] !=
'\0' ? fsm->sufbuf : NULL);
1794 fsm->osuffix = NULL;
1795 fsm->nsuffix = NULL;
1814 _(
"archive file %s was not found in header file list\n"),
1817 if (fsm->failedFile && *fsm->failedFile == NULL)
1818 *fsm->failedFile =
xstrdup(fsm->path);
1819 rc = IOSMERR_UNMAPPED_FILE;
1821 rc = IOSMERR_HDR_TRAILER;
1830 st->st_mode = fi->fmodes[fsm->ix];
1842 if (fsm->path != NULL &&
1847 if (rc == IOSMERR_ENOENT) {
1851 }
else if (rc == 0) {
1859 fsm->diskchecked = 1;
1873 if (S_ISREG(st->st_mode) && st->st_nlink > 1)
1877 if (
fsmGetFi(fsm)->mapflags & IOSM_PAYLOAD_LIST) fsm->postpone = 1;
1892 if (fsm->postpone) {
1895 if (S_ISREG(st->st_mode))
1904 if (S_ISREG(st->st_mode) && st->st_nlink > 1) {
1905 struct hardLink_s * li, * prev;
1911 for (li = fsm->links, prev = NULL; li; prev = li, li = li->next)
1916 fsm->links = fsm->li->next;
1918 prev->next = fsm->li->next;
1919 fsm->li->next = NULL;
1930 if (S_ISREG(st->st_mode) && fsm->lpath != NULL) {
1931 const char * opath = fsm->opath;
1932 char * t =
xmalloc(strlen(fsm->lpath+1) + strlen(fsm->suffix) + 1);
1933 (void)
stpcpy(t, fsm->lpath+1);
1937 if (fsm->failedFile && rc != 0 && *fsm->failedFile == NULL) {
1938 *fsm->failedFile =
xstrdup(fsm->path);
1940 fsm->opath =
_free(fsm->opath);
1944 if (S_ISREG(st->st_mode)) {
1945 const char * path = fsm->path;
1947 fsm->path =
fsmFsPath(fsm, st, NULL, NULL);
1950 if (rc == 0 && fsm->osuffix) {
1951 const char * opath = fsm->opath;
1952 fsm->opath = fsm->path;
1953 fsm->path =
fsmFsPath(fsm, st, NULL, fsm->osuffix);
1957 _(
"%s saved as %s\n"),
1958 (fsm->opath ? fsm->opath :
""),
1959 (fsm->path ? fsm->path :
""));
1960 fsm->path =
_free(fsm->path);
1967 if (!(rc == IOSMERR_ENOENT))
return rc;
1969 }
else if (S_ISDIR(st->st_mode)) {
1970 mode_t st_mode = st->st_mode;
1972 if (rc == IOSMERR_ENOENT) {
1973 st->st_mode &= ~07777;
1974 st->st_mode |= 00700;
1976 st->st_mode = st_mode;
1978 }
else if (
S_ISLNK(st->st_mode)) {
1979 assert(fsm->lpath != NULL);
1982 if (rc == IOSMERR_ENOENT)
1984 }
else if (S_ISFIFO(st->st_mode)) {
1985 mode_t st_mode = st->st_mode;
1988 if (rc == IOSMERR_ENOENT) {
1991 st->st_mode = st_mode;
1993 }
else if (S_ISCHR(st->st_mode) ||
1994 S_ISBLK(st->st_mode) ||
1998 if (rc == IOSMERR_ENOENT)
2002 if (fsm->repackaged)
2007 rc = IOSMERR_UNKNOWN_FILETYPE;
2009 if (S_ISREG(st->st_mode) && st->st_nlink > 1) {
2010 fsm->li->createdPath = fsm->li->linkIndex;
2025 if (archivePos > fi->archivePos) {
2026 fi->archivePos = (
unsigned long long) archivePos;
2028 fi->archivePos, fi->archiveSize);
2037 if (fsm->sufbuf[0] !=
'\0')
2047 if (fsm->failedFile && *fsm->failedFile == NULL)
2048 *fsm->failedFile =
xstrdup(fsm->path);
2051 if (!fsm->postpone && fsm->commit) {
2053 rc = ((S_ISREG(st->st_mode) && st->st_nlink > 1)
2060 fsm->path =
_free(fsm->path);
2061 fsm->lpath =
_free(fsm->lpath);
2062 fsm->opath =
_free(fsm->opath);
2063 memset(st, 0,
sizeof(*st));
2064 memset(ost, 0,
sizeof(*ost));
2068 if (fsm->osuffix && fsm->diskchecked &&
2069 (fsm->exists || (fsm->goal ==
IOSM_PKGINSTALL && S_ISREG(st->st_mode))))
2071 const char * opath = fsm->opath;
2072 const char * path = fsm->path;
2073 fsm->opath =
fsmFsPath(fsm, st, NULL, NULL);
2074 fsm->path =
fsmFsPath(fsm, st, NULL, fsm->osuffix);
2078 (fsm->opath ? fsm->opath :
""),
2079 (fsm->path ? fsm->path :
""));
2081 fsm->path =
_free(fsm->path);
2083 fsm->opath =
_free(fsm->opath);
2091 if (S_ISDIR(st->st_mode)) {
2095 case IOSMERR_ENOENT:
2096 case IOSMERR_ENOTEMPTY:
2104 _(
"%s rmdir of %s failed: Directory not empty\n"),
2109 (fsm->strict_erasures ?
RPMLOG_ERR : RPMLOG_DEBUG),
2110 _(
"%s rmdir of %s failed: %s\n"),
2118 case IOSMERR_ENOENT:
2125 _(
" %s: unlink of %s failed: %s\n"),
2132 if (!fsm->strict_erasures) rc = 0;
2140 if (!S_ISDIR(st->st_mode) &&
2141 (fsm->subdir || fsm->suffix || fsm->nsuffix))
2143 fsm->opath = fsm->path;
2144 fsm->path =
fsmFsPath(fsm, st, NULL, fsm->nsuffix);
2147 (void)
Unlink(fsm->opath);
2148 else if (fsm->nsuffix) {
2149 const char * opath =
fsmFsPath(fsm, st, NULL, NULL);
2151 (opath ? opath :
""),
2152 (fsm->path ? fsm->path :
""));
2153 opath =
_free(opath);
2155 fsm->opath =
_free(fsm->opath);
2160 if (!rc && !getuid()) {
2164 fsm->fcontext = NULL;
2167 if (!rc && !getuid())
2170 if (!rc && !getuid())
2175 time_t mtime = st->st_mtime;
2178 st->st_mtime = fi->fmtimes[fsm->ix];
2180 st->st_mtime = mtime;
2188 else if (fsm->failedFile && *fsm->failedFile == NULL) {
2189 *fsm->failedFile = fsm->path;
2194 fsm->path =
_free(fsm->path);
2197 while ((fsm->li = fsm->links) != NULL) {
2198 fsm->links = fsm->li->next;
2199 fsm->li->next = NULL;
2201 fsm->commit && fsm->li->linksLeft)
2203 for (i = 0 ; i < fsm->li->linksLeft; i++) {
2204 if (fsm->li->filex[i] < 0)
2206 rc = IOSMERR_MISSING_HARDLINK;
2207 if (fsm->failedFile && *fsm->failedFile == NULL) {
2208 fsm->ix = fsm->li->filex[i];
2210 *fsm->failedFile = fsm->path;
2220 rc = IOSMERR_MISSING_HARDLINK;
2224 fsm->ldn =
_free(fsm->ldn);
2225 fsm->ldnalloc = fsm->ldnlen = 0;
2226 fsm->rdbuf = fsm->rdb =
_free(fsm->rdb);
2227 fsm->wrbuf = fsm->wrb =
_free(fsm->wrb);
2230 if (fsm->diskchecked && !fsm->exists) {
2231 rc = IOSMERR_ENOENT;
2234 if (S_ISREG(st->st_mode)) {
2235 char * path =
alloca(strlen(fsm->path) +
sizeof(
"-RPMDELETE"));
2241 fsm->opath = fsm->path;
2247 rc = IOSMERR_UNLINK_FAILED;
2248 fsm->path = fsm->opath;
2250 return (rc ? rc : IOSMERR_ENOENT);
2252 }
else if (S_ISDIR(st->st_mode)) {
2253 if (S_ISDIR(ost->st_mode))
return 0;
2256 if (rc == IOSMERR_ENOENT) rc = 0;
2259 if (S_ISDIR(ost->st_mode))
return 0;
2261 }
else if (
S_ISLNK(st->st_mode)) {
2267 if (!strcmp(fsm->lpath, fsm->rdbuf))
return 0;
2269 }
else if (S_ISFIFO(st->st_mode)) {
2270 if (S_ISFIFO(ost->st_mode))
return 0;
2271 }
else if (S_ISCHR(st->st_mode) || S_ISBLK(st->st_mode)) {
2272 if ((S_ISCHR(ost->st_mode) || S_ISBLK(ost->st_mode)) &&
2273 (ost->st_rdev == st->st_rdev))
return 0;
2274 }
else if (
S_ISSOCK(st->st_mode)) {
2275 if (
S_ISSOCK(ost->st_mode))
return 0;
2280 if (rc == 0) rc = IOSMERR_ENOENT;
2281 return (rc ? rc : IOSMERR_ENOENT);
2331 if (!(stage & IOSM_INTERNAL)) {
2332 fsm->rc = (rc == IOSMERR_HDR_TRAILER ? 0 : rc);