3 * File state machine to handle a payload from a package.
8 #include <rpmio_internal.h>
15 #define _RPMFI_INTERNAL
23 /*@access FD_t @*/ /* XXX void ptr args */
29 #define alloca_strdup(_s) strcpy(alloca(strlen(_s)+1), (_s))
33 int _fsm_debug = _FSM_DEBUG;
35 /* XXX Failure to remove is not (yet) cause for failure. */
36 /*@-exportlocal -exportheadervar@*/
38 int strict_erasures = 0;
39 /*@=exportlocal =exportheadervar@*/
41 rpmts fsmGetTs(const FSM_t fsm) {
42 const FSMI_t iter = fsm->iter;
43 /*@-compdef -refcounttrans -retexpose -usereleased @*/
44 return (iter ? iter->ts : NULL);
45 /*@=compdef =refcounttrans =retexpose =usereleased @*/
48 rpmfi fsmGetFi(const FSM_t fsm)
50 const FSMI_t iter = fsm->iter;
51 /*@-compdef -refcounttrans -retexpose -usereleased @*/
52 return (iter ? iter->fi : NULL);
53 /*@=compdef =refcounttrans =retexpose =usereleased @*/
56 #define SUFFIX_RPMORIG ".rpmorig"
57 #define SUFFIX_RPMSAVE ".rpmsave"
58 #define SUFFIX_RPMNEW ".rpmnew"
61 * Build path to file from file info, ornamented with subdir and suffix.
62 * @param fsm file state machine data
63 * @param st file stat info
64 * @param subdir subdir to use (NULL disables)
65 * @param suffix suffix to use (NULL disables)
66 * @retval path to file
68 static /*@only@*//*@null@*/
69 const char * fsmFsPath(/*@special@*/ /*@null@*/ const FSM_t fsm,
70 /*@null@*/ const struct stat * st,
71 /*@null@*/ const char * subdir,
72 /*@null@*/ const char * suffix)
73 /*@uses fsm->dirName, fsm->baseName */
76 const char * s = NULL;
81 nb = strlen(fsm->dirName) +
82 (st && !S_ISDIR(st->st_mode) ? (subdir ? strlen(subdir) : 0) : 0) +
83 (st && !S_ISDIR(st->st_mode) ? (suffix ? strlen(suffix) : 0) : 0) +
84 strlen(fsm->baseName) + 1;
87 t = stpcpy(t, fsm->dirName);
88 if (st && !S_ISDIR(st->st_mode))
89 if (subdir) t = stpcpy(t, subdir);
90 t = stpcpy(t, fsm->baseName);
91 if (st && !S_ISDIR(st->st_mode))
92 if (suffix) t = stpcpy(t, suffix);
99 * Destroy file info iterator.
100 * @param p file info iterator
101 * @retval NULL always
103 static /*@null@*/ void * mapFreeIterator(/*@only@*//*@null@*/ void * p)
104 /*@globals fileSystem @*/
105 /*@modifies fileSystem @*/
109 iter->ts = rpmtsFree(iter->ts);
110 iter->fi = rpmfiUnlink(iter->fi, "mapIterator");
116 * Create file info iterator.
117 * @param ts transaction set
118 * @param fi transaction element file info
119 * @return file info iterator
122 mapInitIterator(rpmts ts, rpmfi fi)
123 /*@modifies ts, fi @*/
127 iter = xcalloc(1, sizeof(*iter));
128 iter->ts = rpmtsLink(ts, "mapIterator");
129 iter->fi = rpmfiLink(fi, "mapIterator");
130 iter->reverse = (rpmteType(fi->te) == TR_REMOVED && fi->action != FA_COPYOUT);
131 iter->i = (iter->reverse ? (fi->fc - 1) : 0);
132 iter->isave = iter->i;
137 * Return next index into file info.
138 * @param a file info iterator
139 * @return next index, -1 on termination
141 static int mapNextIterator(/*@null@*/ void * a)
148 const rpmfi fi = iter->fi;
150 if (iter->i >= 0) i = iter->i--;
152 if (iter->i < fi->fc) i = iter->i++;
162 static int cpioStrCmp(const void * a, const void * b)
165 const char * afn = *(const char **)a;
166 const char * bfn = *(const char **)b;
168 /* XXX Some 4+ year old rpm packages have basename only in payloads. */
169 #ifdef VERY_OLD_BUGGY_RPM_PACKAGES
170 if (strchr(afn, '/') == NULL)
171 bfn = strrchr(bfn, '/') + 1;
174 /* Match rpm-4.0 payloads with ./ prefixes. */
175 if (afn[0] == '.' && afn[1] == '/') afn += 2;
176 if (bfn[0] == '.' && bfn[1] == '/') bfn += 2;
178 /* If either path is absolute, make it relative. */
179 if (afn[0] == '/') afn += 1;
180 if (bfn[0] == '/') bfn += 1;
182 return strcmp(afn, bfn);
187 * Locate archive path in file info.
188 * @param iter file info iterator
189 * @param fsmPath archive path
190 * @return index into file info, -1 if archive path was not found
193 static int mapFind(/*@null@*/ FSMI_t iter, const char * fsmPath)
199 const rpmfi fi = iter->fi;
200 if (fi && fi->fc > 0 && fi->apath && fsmPath && *fsmPath) {
201 const char ** p = NULL;
204 if (fi->apath != NULL)
205 p = bsearch(&fsmPath, fi->apath, fi->fc, sizeof(fsmPath),
209 iter->i = p - fi->apath;
210 ix = mapNextIterator(iter);
219 * Directory name iterator.
221 typedef struct dnli_s {
223 /*@only@*/ /*@null@*/
231 * Destroy directory name iterator.
232 * @param a directory name iterator
233 * @retval NULL always
235 static /*@null@*/ void * dnlFreeIterator(/*@only@*//*@null@*/ const void * a)
239 DNLI_t dnli = (void *)a;
240 if (dnli->active) free(dnli->active);
247 static inline int dnlCount(const DNLI_t dnli)
250 return (dnli ? dnli->fi->dc : 0);
255 static inline int dnlIndex(const DNLI_t dnli)
258 return (dnli ? dnli->isave : -1);
262 * Create directory name iterator.
263 * @param fsm file state machine data
264 * @param reverse traverse directory names in reverse order?
265 * @return directory name iterator
269 static /*@only@*/ void * dnlInitIterator(/*@special@*/ const FSM_t fsm,
271 /*@uses fsm->iter @*/
274 rpmfi fi = fsmGetFi(fsm);
280 dnli = xcalloc(1, sizeof(*dnli));
282 dnli->reverse = reverse;
284 dnli->i = (reverse ? fi->dc : 0);
288 dnli->active = xcalloc(fi->dc, sizeof(*dnli->active));
290 /* Identify parent directories not skipped. */
292 for (i = 0; i < fi->fc; i++)
293 if (!XFA_SKIPPING(fi->actions[i])) dnli->active[fi->dil[i]] = 1;
296 /* Exclude parent directories that are explicitly included. */
297 for (i = 0; i < fi->fc; i++) {
298 int dil, dnlen, bnlen;
300 if (!S_ISDIR(fi->fmodes[i]))
304 dnlen = strlen(fi->dnl[dil]);
305 bnlen = strlen(fi->bnl[i]);
307 for (j = 0; j < fi->dc; j++) {
311 if (!dnli->active[j] || j == dil)
312 /*@innercontinue@*/ continue;
315 if (jlen != (dnlen+bnlen+1))
316 /*@innercontinue@*/ continue;
317 if (strncmp(dnl, fi->dnl[dil], dnlen))
318 /*@innercontinue@*/ continue;
319 if (strncmp(dnl+dnlen, fi->bnl[i], bnlen))
320 /*@innercontinue@*/ continue;
321 if (dnl[dnlen+bnlen] != '/' || dnl[dnlen+bnlen+1] != '\0')
322 /*@innercontinue@*/ continue;
323 /* This directory is included in the package. */
327 /*@innerbreak@*/ break;
331 /* Print only once per package. */
334 for (i = 0; i < fi->dc; i++) {
335 if (!dnli->active[i]) continue;
338 rpmMessage(RPMMESS_DEBUG,
339 _("========== Directories not explictly included in package:\n"));
341 rpmMessage(RPMMESS_DEBUG, _("%10d %s\n"), i, fi->dnl[i]);
344 rpmMessage(RPMMESS_DEBUG, "==========\n");
353 * Return next directory name (from file info).
354 * @param dnli directory name iterator
355 * @return next directory name
358 static /*@observer@*/ const char * dnlNextIterator(/*@null@*/ DNLI_t dnli)
361 const char * dn = NULL;
369 i = (!dnli->reverse ? dnli->i++ : --dnli->i);
370 } while (i >= 0 && i < fi->dc && !dnli->active[i]);
372 if (i >= 0 && i < fi->dc)
382 static void * fsmThread(void * arg)
386 return ((void *) fsmStage(fsm, fsm->nstage));
389 int fsmNext(FSM_t fsm, fileStage nstage)
392 fsm->nstage = nstage;
393 return rpmsqThread(fsmThread, fsm);
397 * Save hard link in chain.
398 * @param fsm file state machine data
399 * @return Is chain only partially filled?
402 static int saveHardLink(/*@special@*/ /*@partial@*/ FSM_t fsm)
403 /*@uses fsm->links, fsm->ix, fsm->sb, fsm->goal, fsm->nsuffix @*/
404 /*@defines fsm->li @*/
405 /*@releases fsm->path @*/
406 /*@globals errno, fileSystem, internalState @*/
407 /*@modifies fsm, errno, fileSystem, internalState @*/
409 struct stat * st = &fsm->sb;
414 /* Find hard link set. */
416 for (fsm->li = fsm->links; fsm->li; fsm->li = fsm->li->next) {
417 if (fsm->li->sb.st_ino == st->st_ino && fsm->li->sb.st_dev == st->st_dev)
422 /* New hard link encountered, add new link to set. */
425 if (fsm->li == NULL) {
426 fsm->li = xcalloc(1, sizeof(*fsm->li));
427 fsm->li->next = NULL;
428 fsm->li->sb = *st; /* structure assignment */
429 fsm->li->nlink = st->st_nlink;
430 fsm->li->linkIndex = fsm->ix;
431 fsm->li->createdPath = -1;
433 fsm->li->filex = xcalloc(st->st_nlink, sizeof(fsm->li->filex[0]));
434 memset(fsm->li->filex, -1, (st->st_nlink * sizeof(fsm->li->filex[0])));
435 fsm->li->nsuffix = xcalloc(st->st_nlink, sizeof(*fsm->li->nsuffix));
437 if (fsm->goal == FSM_PKGBUILD)
438 fsm->li->linksLeft = st->st_nlink;
439 if (fsm->goal == FSM_PKGINSTALL)
440 fsm->li->linksLeft = 0;
443 fsm->li->next = fsm->links;
445 fsm->links = fsm->li;
450 if (fsm->goal == FSM_PKGBUILD) --fsm->li->linksLeft;
452 fsm->li->filex[fsm->li->linksLeft] = fsm->ix;
453 /*@-observertrans -dependenttrans@*/
454 fsm->li->nsuffix[fsm->li->linksLeft] = fsm->nsuffix;
455 /*@=observertrans =dependenttrans@*/
457 if (fsm->goal == FSM_PKGINSTALL) fsm->li->linksLeft++;
459 if (fsm->goal == FSM_PKGBUILD)
460 return (fsm->li->linksLeft > 0);
462 if (fsm->goal != FSM_PKGINSTALL)
465 if (!(st->st_size || fsm->li->linksLeft == st->st_nlink))
468 /* Here come the bits, time to choose a non-skipped file name. */
469 { rpmfi fi = fsmGetFi(fsm);
471 for (j = fsm->li->linksLeft - 1; j >= 0; j--) {
472 ix = fsm->li->filex[j];
473 if (ix < 0 || XFA_SKIPPING(fi->actions[ix]))
479 /* Are all links skipped or not encountered yet? */
481 return 1; /* XXX W2DO? */
483 /* Save the non-skipped file name and map index. */
484 fsm->li->linkIndex = j;
485 fsm->path = _free(fsm->path);
487 rc = fsmNext(fsm, FSM_MAP);
493 * Destroy set of hard links.
494 * @param li set of hard links
495 * @return NULL always
497 static /*@null@*/ void * freeHardLink(/*@only@*/ /*@null@*/ struct hardLink_s * li)
501 li->nsuffix = _free(li->nsuffix); /* XXX elements are shared */
502 li->filex = _free(li->filex);
509 FSM_t fsm = xcalloc(1, sizeof(*fsm));
513 FSM_t freeFSM(FSM_t fsm)
516 fsm->path = _free(fsm->path);
518 while ((fsm->li = fsm->links) != NULL) {
519 fsm->links = fsm->li->next;
520 fsm->li->next = NULL;
521 fsm->li = freeHardLink(fsm->li);
524 fsm->dnlx = _free(fsm->dnlx);
525 fsm->ldn = _free(fsm->ldn);
526 fsm->iter = mapFreeIterator(fsm->iter);
531 int fsmSetup(FSM_t fsm, fileStage goal,
532 const rpmts ts, const rpmfi fi, FD_t cfd,
533 unsigned int * archiveSize, const char ** failedFile)
540 fsm->cfd = fdLink(cfd, "persist (fsm)");
541 pos = fdGetCpioPos(fsm->cfd);
542 fdSetCpioPos(fsm->cfd, 0);
544 fsm->iter = mapInitIterator(ts, fi);
546 if (fsm->goal == FSM_PKGINSTALL || fsm->goal == FSM_PKGBUILD) {
549 ptr = rpmtsNotify(ts, fi->te,
550 RPMCALLBACK_INST_START, fi->archivePos, fi->archiveSize);
555 fsm->archiveSize = archiveSize;
556 if (fsm->archiveSize)
557 *fsm->archiveSize = 0;
558 fsm->failedFile = failedFile;
560 *fsm->failedFile = NULL;
564 memset(fsm->sufbuf, 0, sizeof(fsm->sufbuf));
565 if (fsm->goal == FSM_PKGINSTALL) {
566 if (ts && rpmtsGetTid(ts) > 0)
567 sprintf(fsm->sufbuf, ";%08x", (unsigned)rpmtsGetTid(ts));
571 rc = fsmStage(fsm, FSM_CREATE);
572 if (rc && !ec) ec = rc;
574 rc = fsmStage(fsm, fsm->goal);
575 if (rc && !ec) ec = rc;
578 if (fsm->archiveSize && ec == 0)
579 *fsm->archiveSize = (fdGetCpioPos(fsm->cfd) - pos);
585 int fsmTeardown(FSM_t fsm)
590 rc = fsmStage(fsm, FSM_DESTROY);
592 fsm->iter = mapFreeIterator(fsm->iter);
593 if (fsm->cfd != NULL) {
594 fsm->cfd = fdFree(fsm->cfd, "persist (fsm)");
597 fsm->failedFile = NULL;
601 int fsmMapPath(FSM_t fsm)
603 rpmfi fi = fsmGetFi(fsm); /* XXX const except for fstates */
610 fsm->action = FA_UNKNOWN;
614 if (fi && i >= 0 && i < fi->fc) {
617 fsm->astriplen = fi->astriplen;
618 fsm->action = (fi->actions ? fi->actions[i] : fi->action);
619 fsm->fflags = (fi->fflags ? fi->fflags[i] : fi->flags);
620 fsm->mapFlags = (fi->fmapflags ? fi->fmapflags[i] : fi->mapflags);
622 /* src rpms have simple base name in payload. */
623 fsm->dirName = fi->dnl[fi->dil[i]];
624 fsm->baseName = fi->bnl[i];
628 switch (fsm->action) {
638 assert(rpmteType(fi->te) == TR_ADDED);
642 if (fi->fstates && rpmteType(fi->te) == TR_ADDED)
643 fi->fstates[i] = RPMFILE_STATE_NOTINSTALLED;
646 case FA_SKIPNETSHARED:
647 if (fi->fstates && rpmteType(fi->te) == TR_ADDED)
648 fi->fstates[i] = RPMFILE_STATE_NETSHARED;
652 if (fi->fstates && rpmteType(fi->te) == TR_ADDED)
653 fi->fstates[i] = RPMFILE_STATE_WRONGCOLOR;
657 if (!(fsm->fflags & RPMFILE_GHOST)) /* XXX Don't if %ghost file. */
658 switch (rpmteType(fi->te)) {
660 fsm->osuffix = SUFFIX_RPMORIG;
661 /*@innerbreak@*/ break;
663 fsm->osuffix = SUFFIX_RPMSAVE;
664 /*@innerbreak@*/ break;
669 assert(rpmteType(fi->te) == TR_ADDED);
670 if (!(fsm->fflags & RPMFILE_GHOST)) /* XXX Don't if %ghost file. */
671 fsm->nsuffix = SUFFIX_RPMNEW;
675 assert(rpmteType(fi->te) == TR_ADDED);
676 if (!(fsm->fflags & RPMFILE_GHOST)) /* XXX Don't if %ghost file. */
677 fsm->osuffix = SUFFIX_RPMSAVE;
680 #if 0 /* XXX is this a genhdlist fix? */
681 assert(rpmteType(fi->te) == TR_REMOVED);
684 * XXX TODO: %ghost probably shouldn't be removed, but that changes
685 * legacy rpm behavior.
693 if ((fsm->mapFlags & CPIO_MAP_PATH) || fsm->nsuffix) {
694 const struct stat * st = &fsm->sb;
695 fsm->path = _free(fsm->path);
696 fsm->path = fsmFsPath(fsm, st, fsm->subdir,
697 (fsm->suffix ? fsm->suffix : fsm->nsuffix));
703 int fsmMapAttrs(FSM_t fsm)
705 struct stat * st = &fsm->sb;
706 rpmfi fi = fsmGetFi(fsm);
709 if (fi && i >= 0 && i < fi->fc) {
711 (S_ISDIR(st->st_mode) ? fi->dperms : fi->fperms);
713 (fi->fmodes ? fi->fmodes[i] : perms);
715 (fi->fuids ? fi->fuids[i] : fi->uid); /* XXX chmod u-s */
717 (fi->fgids ? fi->fgids[i] : fi->gid); /* XXX chmod g-s */
719 (fi->frdevs ? fi->frdevs[i] : 0);
721 (fi->fmtimes ? fi->fmtimes[i] : 0);
723 if (fsm->mapFlags & CPIO_MAP_MODE)
724 st->st_mode = (st->st_mode & S_IFMT) | (finalMode & ~S_IFMT);
725 if (fsm->mapFlags & CPIO_MAP_TYPE) {
726 st->st_mode = (st->st_mode & ~S_IFMT) | (finalMode & S_IFMT);
727 if ((S_ISCHR(st->st_mode) || S_ISBLK(st->st_mode))
728 && st->st_nlink == 0)
730 st->st_rdev = finalRdev;
731 st->st_mtime = finalMtime;
733 if (fsm->mapFlags & CPIO_MAP_UID)
734 st->st_uid = finalUid;
735 if (fsm->mapFlags & CPIO_MAP_GID)
736 st->st_gid = finalGid;
738 { rpmts ts = fsmGetTs(fsm);
740 if (ts != NULL && !(rpmtsFlags(ts) & RPMTRANS_FLAG_NOMD5)) {
741 fsm->fmd5sum = (fi->fmd5s ? fi->fmd5s[i] : NULL);
742 fsm->md5sum = (fi->md5s ? (fi->md5s + (16 * i)) : NULL);
754 * Create file from payload stream.
755 * @param fsm file state machine data
756 * @return 0 on success
758 static int expandRegular(/*@special@*/ FSM_t fsm)
760 /*@globals errno, fileSystem, internalState @*/
761 /*@modifies fsm, errno, fileSystem, internalState @*/
763 const struct stat * st = &fsm->sb;
764 int left = st->st_size;
767 rc = fsmNext(fsm, FSM_WOPEN);
771 if (st->st_size > 0 && (fsm->fmd5sum || fsm->md5sum))
772 fdInitDigest(fsm->wfd, PGPHASHALGO_MD5, 0);
776 fsm->wrlen = (left > fsm->wrsize ? fsm->wrsize : left);
777 rc = fsmNext(fsm, FSM_DREAD);
781 rc = fsmNext(fsm, FSM_WRITE);
787 /* don't call this with fileSize == fileComplete */
789 (void) fsmNext(fsm, FSM_NOTIFY);
792 if (st->st_size > 0 && (fsm->fmd5sum || fsm->md5sum)) {
793 void * md5sum = NULL;
794 int asAscii = (fsm->md5sum == NULL ? 1 : 0);
796 (void) Fflush(fsm->wfd);
797 fdFiniDigest(fsm->wfd, PGPHASHALGO_MD5, &md5sum, NULL, asAscii);
799 if (md5sum == NULL) {
800 rc = CPIOERR_MD5SUM_MISMATCH;
804 if (fsm->md5sum != NULL) {
805 if (memcmp(md5sum, fsm->md5sum, 16))
806 rc = CPIOERR_MD5SUM_MISMATCH;
808 if (strcmp(md5sum, fsm->fmd5sum))
809 rc = CPIOERR_MD5SUM_MISMATCH;
811 md5sum = _free(md5sum);
815 (void) fsmNext(fsm, FSM_WCLOSE);
820 * Write next item to payload stream.
821 * @param fsm file state machine data
822 * @param writeData should data be written?
823 * @return 0 on success
825 static int writeFile(/*@special@*/ FSM_t fsm, int writeData)
826 /*@uses fsm->path, fsm->opath, fsm->sb, fsm->osb, fsm->cfd @*/
827 /*@globals errno, fileSystem, internalState @*/
828 /*@modifies fsm, errno, fileSystem, internalState @*/
830 const char * path = fsm->path;
831 const char * opath = fsm->opath;
832 struct stat * st = &fsm->sb;
833 struct stat * ost = &fsm->osb;
834 char * symbuf = NULL;
839 st->st_size = (writeData ? ost->st_size : 0);
842 if (S_ISDIR(st->st_mode)) {
844 } else if (S_ISLNK(st->st_mode)) {
846 * While linux puts the size of a symlink in the st_size field,
847 * I don't think that's a specified standard.
849 /* XXX NUL terminated result in fsm->rdbuf, len in fsm->rdnb. */
850 rc = fsmStage(fsm, FSM_READLINK);
852 st->st_size = fsm->rdnb;
853 symbuf = alloca_strdup(fsm->rdbuf); /* XXX save readlink return. */
857 if (fsm->mapFlags & CPIO_MAP_ABSOLUTE) {
858 /*@-compdef@*/ /* FIX: dirName/baseName annotations ? */
860 int nb = strlen(fsm->dirName) + strlen(fsm->baseName) + sizeof(".");
861 char * t = alloca(nb);
864 if (fsm->mapFlags & CPIO_MAP_ADDDOT)
866 t = stpcpy( stpcpy(t, fsm->dirName), fsm->baseName);
869 } else if (fsm->mapFlags & CPIO_MAP_PATH) {
870 rpmfi fi = fsmGetFi(fsm);
872 (fi->apath ? fi->apath[fsm->ix] + fi->striplen : fi->bnl[fsm->ix]);
875 rc = fsmNext(fsm, FSM_HWRITE);
879 if (writeData && S_ISREG(st->st_mode)) {
882 void * mapped = (void *)-1;
886 rc = fsmNext(fsm, FSM_ROPEN);
889 /* XXX unbuffered mmap generates *lots* of fdio debugging */
892 mapped = mmap(NULL, st->st_size, PROT_READ, MAP_SHARED, Fileno(fsm->rfd), 0);
893 if (mapped != (void *)-1) {
895 fsm->rdbuf = (char *) mapped;
896 fsm->rdlen = nmapped = st->st_size;
897 #if defined(MADV_DONTNEED)
898 xx = madvise(mapped, nmapped, MADV_DONTNEED);
907 if (mapped != (void *)-1) {
912 fsm->rdlen = (left > fsm->rdsize ? fsm->rdsize : left),
913 rc = fsmNext(fsm, FSM_READ);
917 /* XXX DWRITE uses rdnb for I/O length. */
918 rc = fsmNext(fsm, FSM_DWRITE);
925 if (mapped != (void *)-1) {
926 xx = msync(mapped, nmapped, MS_ASYNC);
927 #if defined(MADV_DONTNEED)
928 xx = madvise(mapped, nmapped, MADV_DONTNEED);
930 /*@-noeffect@*/ xx = munmap(mapped, nmapped) /*@=noeffect@*/;
935 } else if (writeData && S_ISLNK(st->st_mode)) {
936 /* XXX DWRITE uses rdnb for I/O length. */
938 strcpy(fsm->rdbuf, symbuf); /* XXX restore readlink buffer. */
940 fsm->rdnb = strlen(symbuf);
941 rc = fsmNext(fsm, FSM_DWRITE);
945 rc = fsmNext(fsm, FSM_PAD);
951 if (fsm->rfd != NULL)
952 (void) fsmNext(fsm, FSM_RCLOSE);
953 /*@-dependenttrans@*/
956 /*@=dependenttrans@*/
961 * Write set of linked files to payload stream.
962 * @param fsm file state machine data
963 * @return 0 on success
965 static int writeLinkedFile(/*@special@*/ FSM_t fsm)
966 /*@uses fsm->path, fsm->nsuffix, fsm->ix, fsm->li, fsm->failedFile @*/
967 /*@globals errno, fileSystem, internalState @*/
968 /*@modifies fsm, errno, fileSystem, internalState @*/
970 const char * path = fsm->path;
971 const char * nsuffix = fsm->nsuffix;
972 int iterIndex = fsm->ix;
982 for (i = fsm->li->nlink - 1; i >= 0; i--) {
984 if (fsm->li->filex[i] < 0) continue;
986 fsm->ix = fsm->li->filex[i];
987 rc = fsmNext(fsm, FSM_MAP);
989 /* Write data after last link. */
990 rc = writeFile(fsm, (i == 0));
991 if (fsm->failedFile && rc != 0 && *fsm->failedFile == NULL) {
993 *fsm->failedFile = xstrdup(fsm->path);
996 fsm->path = _free(fsm->path);
997 fsm->li->filex[i] = -1;
1001 fsm->ix = iterIndex;
1002 fsm->nsuffix = nsuffix;
1007 /** \ingroup payload
1008 * Create pending hard links to existing file.
1009 * @param fsm file state machine data
1010 * @return 0 on success
1013 static int fsmMakeLinks(/*@special@*/ FSM_t fsm)
1014 /*@uses fsm->path, fsm->opath, fsm->nsuffix, fsm->ix, fsm->li @*/
1015 /*@globals errno, fileSystem, internalState @*/
1016 /*@modifies fsm, errno, fileSystem, internalState @*/
1018 const char * path = fsm->path;
1019 const char * opath = fsm->opath;
1020 const char * nsuffix = fsm->nsuffix;
1021 int iterIndex = fsm->ix;
1028 fsm->nsuffix = NULL;
1031 fsm->ix = fsm->li->filex[fsm->li->createdPath];
1032 rc = fsmNext(fsm, FSM_MAP);
1033 fsm->opath = fsm->path;
1036 for (i = 0; i < fsm->li->nlink; i++) {
1037 if (fsm->li->filex[i] < 0) continue;
1038 if (fsm->li->createdPath == i) continue;
1040 fsm->ix = fsm->li->filex[i];
1041 fsm->path = _free(fsm->path);
1042 rc = fsmNext(fsm, FSM_MAP);
1043 if (XFA_SKIPPING(fsm->action)) continue;
1045 rc = fsmUNSAFE(fsm, FSM_VERIFY);
1047 if (rc != CPIOERR_LSTAT_FAILED) break;
1049 /* XXX link(fsm->opath, fsm->path) */
1050 rc = fsmNext(fsm, FSM_LINK);
1051 if (fsm->failedFile && rc != 0 && *fsm->failedFile == NULL) {
1054 *fsm->failedFile = xstrdup(fsm->path);
1058 fsm->li->linksLeft--;
1061 fsm->path = _free(fsm->path);
1062 fsm->opath = _free(fsm->opath);
1064 fsm->ix = iterIndex;
1065 fsm->nsuffix = nsuffix;
1072 /** \ingroup payload
1073 * Commit hard linked file set atomically.
1074 * @param fsm file state machine data
1075 * @return 0 on success
1077 static int fsmCommitLinks(/*@special@*/ FSM_t fsm)
1078 /*@uses fsm->path, fsm->nsuffix, fsm->ix, fsm->sb,
1079 fsm->li, fsm->links @*/
1080 /*@globals errno, fileSystem, internalState @*/
1081 /*@modifies fsm, errno, fileSystem, internalState @*/
1083 const char * path = fsm->path;
1084 const char * nsuffix = fsm->nsuffix;
1085 int iterIndex = fsm->ix;
1086 struct stat * st = &fsm->sb;
1091 fsm->nsuffix = NULL;
1095 for (fsm->li = fsm->links; fsm->li; fsm->li = fsm->li->next) {
1096 if (fsm->li->sb.st_ino == st->st_ino && fsm->li->sb.st_dev == st->st_dev)
1102 for (i = 0; i < fsm->li->nlink; i++) {
1103 if (fsm->li->filex[i] < 0) continue;
1104 fsm->ix = fsm->li->filex[i];
1105 rc = fsmNext(fsm, FSM_MAP);
1106 if (!XFA_SKIPPING(fsm->action))
1107 rc = fsmNext(fsm, FSM_COMMIT);
1108 fsm->path = _free(fsm->path);
1109 fsm->li->filex[i] = -1;
1113 fsm->ix = iterIndex;
1114 fsm->nsuffix = nsuffix;
1120 * Remove (if created) directories not explicitly included in package.
1121 * @param fsm file state machine data
1122 * @return 0 on success
1124 static int fsmRmdirs(/*@special@*/ FSM_t fsm)
1125 /*@uses fsm->path, fsm->dnlx, fsm->ldn, fsm->rdbuf, fsm->iter @*/
1126 /*@globals errno, fileSystem, internalState @*/
1127 /*@modifies fsm, errno, fileSystem, internalState @*/
1129 const char * path = fsm->path;
1130 void * dnli = dnlInitIterator(fsm, 1);
1131 char * dn = fsm->rdbuf;
1132 int dc = dnlCount(dnli);
1138 /*@-observertrans -dependenttrans@*/
1139 if (fsm->ldn != NULL && fsm->dnlx != NULL)
1140 while ((fsm->path = dnlNextIterator(dnli)) != NULL) {
1141 int dnlen = strlen(fsm->path);
1144 dc = dnlIndex(dnli);
1145 if (fsm->dnlx[dc] < 1 || fsm->dnlx[dc] >= dnlen)
1148 /* Copy to avoid const on fsm->path. */
1149 te = stpcpy(dn, fsm->path) - 1;
1152 /* Remove generated directories. */
1153 /*@-usereleased@*/ /* LCL: te used after release? */
1157 rc = fsmNext(fsm, FSM_RMDIR);
1161 /*@innerbreak@*/ break;
1163 } while ((te - fsm->path) > fsm->dnlx[dc]);
1167 dnli = dnlFreeIterator(dnli);
1168 /*@=observertrans =dependenttrans@*/
1175 * Create (if necessary) directories not explicitly included in package.
1176 * @param fsm file state machine data
1177 * @return 0 on success
1179 static int fsmMkdirs(/*@special@*/ FSM_t fsm)
1180 /*@uses fsm->path, fsm->sb, fsm->osb, fsm->rdbuf, fsm->iter,
1181 fsm->ldn, fsm->ldnlen, fsm->ldnalloc @*/
1182 /*@defines fsm->dnlx, fsm->ldn @*/
1183 /*@globals errno, fileSystem, internalState @*/
1184 /*@modifies fsm, errno, fileSystem, internalState @*/
1186 struct stat * st = &fsm->sb;
1187 struct stat * ost = &fsm->osb;
1188 const char * path = fsm->path;
1189 mode_t st_mode = st->st_mode;
1190 void * dnli = dnlInitIterator(fsm, 0);
1191 char * dn = fsm->rdbuf;
1192 int dc = dnlCount(dnli);
1200 fsm->dnlx = (dc ? xcalloc(dc, sizeof(*fsm->dnlx)) : NULL);
1201 /*@-observertrans -dependenttrans@*/
1202 if (fsm->dnlx != NULL)
1203 while ((fsm->path = dnlNextIterator(dnli)) != NULL) {
1204 int dnlen = strlen(fsm->path);
1207 dc = dnlIndex(dnli);
1208 if (dc < 0) continue;
1209 fsm->dnlx[dc] = dnlen;
1213 /*@-compdef -nullpass@*/ /* FIX: fsm->ldn not defined ??? */
1214 if (dnlen <= fsm->ldnlen && !strcmp(fsm->path, fsm->ldn))
1216 /*@=compdef =nullpass@*/
1218 /* Copy to avoid const on fsm->path. */
1219 (void) stpcpy(dn, fsm->path);
1222 /* Assume '/' directory exists, "mkdir -p" for others if non-existent */
1223 for (i = 1, te = dn + 1; *te != '\0'; te++, i++) {
1225 /*@innercontinue@*/ continue;
1229 /* Already validated? */
1230 /*@-usedef -compdef -nullpass -nullderef@*/
1231 if (i < fsm->ldnlen &&
1232 (fsm->ldn[i] == '/' || fsm->ldn[i] == '\0') &&
1233 !strncmp(fsm->path, fsm->ldn, i))
1236 /* Move pre-existing path marker forward. */
1237 fsm->dnlx[dc] = (te - dn);
1238 /*@innercontinue@*/ continue;
1240 /*@=usedef =compdef =nullpass =nullderef@*/
1242 /* Validate next component of path. */
1243 rc = fsmStage(fsm, FSM_LSTAT);
1246 /* Directory already exists? */
1247 if (rc == 0 && S_ISDIR(ost->st_mode)) {
1248 /* Move pre-existing path marker forward. */
1249 fsm->dnlx[dc] = (te - dn);
1250 } else if (rc == CPIOERR_LSTAT_FAILED) {
1251 rpmfi fi = fsmGetFi(fsm);
1253 st->st_mode = S_IFDIR | (fi->dperms & 07777);
1254 rc = fsmNext(fsm, FSM_MKDIR);
1256 rpmMessage(RPMMESS_DEBUG,
1257 _("%s directory created with perms %04o.\n"),
1258 fsm->path, (unsigned)(st->st_mode & 07777));
1262 /*@innerbreak@*/ break;
1266 /* Save last validated path. */
1267 /*@-compdef@*/ /* FIX: ldn/path annotations ? */
1268 if (fsm->ldnalloc < (dnlen + 1)) {
1269 fsm->ldnalloc = dnlen + 100;
1270 fsm->ldn = xrealloc(fsm->ldn, fsm->ldnalloc);
1272 if (fsm->ldn != NULL) { /* XXX can't happen */
1273 strcpy(fsm->ldn, fsm->path);
1274 fsm->ldnlen = dnlen;
1279 dnli = dnlFreeIterator(dnli);
1280 /*@=observertrans =dependenttrans@*/
1283 st->st_mode = st_mode; /* XXX restore st->st_mode */
1284 /*@-compdef@*/ /* FIX: ldn/path annotations ? */
1291 * Check for file on disk.
1292 * @param fsm file state machine data
1293 * @return 0 on success
1295 static int fsmStat(FSM_t fsm)
1296 /*@globals errno, fileSystem, internalState @*/
1297 /*@modifies fsm, errno, fileSystem, internalState @*/
1299 int saveerrno = errno;
1302 if (fsm->path != NULL) {
1303 int saveernno = errno;
1304 rc = fsmStage(fsm, (!(fsm->mapFlags & CPIO_FOLLOW_SYMLINKS)
1305 ? FSM_LSTAT : FSM_STAT));
1306 if (rc == CPIOERR_LSTAT_FAILED && errno == ENOENT) {
1310 } else if (rc == 0) {
1314 /* Skip %ghost files on build. */
1321 #define IS_DEV_LOG(_x) \
1322 ((_x) != NULL && strlen(_x) >= (sizeof("/dev/log")-1) && \
1323 !strncmp((_x), "/dev/log", sizeof("/dev/log")-1) && \
1324 ((_x)[sizeof("/dev/log")-1] == '\0' || \
1325 (_x)[sizeof("/dev/log")-1] == ';'))
1329 int fsmStage(FSM_t fsm, fileStage stage)
1332 fileStage prevStage = fsm->stage;
1333 const char * const prev = fileStageString(prevStage);
1335 static int modulo = 4;
1336 const char * const cur = fileStageString(stage);
1337 struct stat * st = &fsm->sb;
1338 struct stat * ost = &fsm->osb;
1339 int saveerrno = errno;
1344 #define _fafilter(_a) \
1345 (!((_a) == FA_CREATE || (_a) == FA_ERASE || (_a) == FA_COPYIN || (_a) == FA_COPYOUT) \
1346 ? fileActionString(_a) : "")
1348 if (stage & FSM_DEAD) {
1350 } else if (stage & FSM_INTERNAL) {
1351 if (_fsm_debug && !(stage & FSM_SYSCALL))
1352 rpmMessage(RPMMESS_DEBUG, " %8s %06o%3d (%4d,%4d)%10d %s %s\n",
1354 (unsigned)st->st_mode, (int)st->st_nlink,
1355 (int)st->st_uid, (int)st->st_gid, (int)st->st_size,
1356 (fsm->path ? fsm->path : ""),
1357 _fafilter(fsm->action));
1360 if (_fsm_debug || !(stage & FSM_VERBOSE))
1361 rpmMessage(RPMMESS_DEBUG, "%-8s %06o%3d (%4d,%4d)%10d %s %s\n",
1363 (unsigned)st->st_mode, (int)st->st_nlink,
1364 (int)st->st_uid, (int)st->st_gid, (int)st->st_size,
1365 (fsm->path ? fsm->path + fsm->astriplen : ""),
1366 _fafilter(fsm->action));
1374 case FSM_PKGINSTALL:
1376 /* Clean fsm, free'ing memory. Read next archive header. */
1377 rc = fsmUNSAFE(fsm, FSM_INIT);
1379 /* Exit on end-of-payload. */
1380 if (rc == CPIOERR_HDR_TRAILER) {
1382 /*@loopbreak@*/ break;
1385 /* Exit on error. */
1388 (void) fsmNext(fsm, FSM_UNDO);
1389 /*@loopbreak@*/ break;
1392 /* Extract file from archive. */
1393 rc = fsmNext(fsm, FSM_PROCESS);
1395 (void) fsmNext(fsm, FSM_UNDO);
1396 /*@loopbreak@*/ break;
1399 /* Notify on success. */
1400 (void) fsmNext(fsm, FSM_NOTIFY);
1402 rc = fsmNext(fsm, FSM_FINI);
1404 /*@loopbreak@*/ break;
1411 /* Clean fsm, free'ing memory. */
1412 rc = fsmUNSAFE(fsm, FSM_INIT);
1414 /* Exit on end-of-payload. */
1415 if (rc == CPIOERR_HDR_TRAILER) {
1417 /*@loopbreak@*/ break;
1420 /* Rename/erase next item. */
1421 if (fsmNext(fsm, FSM_FINI))
1422 /*@loopbreak@*/ break;
1428 rc = fsmUNSAFE(fsm, FSM_INIT);
1430 /* Exit on end-of-payload. */
1431 if (rc == CPIOERR_HDR_TRAILER) {
1433 /*@loopbreak@*/ break;
1436 /* Exit on error. */
1439 (void) fsmNext(fsm, FSM_UNDO);
1440 /*@loopbreak@*/ break;
1443 /* Copy file into archive. */
1444 rc = fsmNext(fsm, FSM_PROCESS);
1446 (void) fsmNext(fsm, FSM_UNDO);
1447 /*@loopbreak@*/ break;
1450 /* Notify on success. */
1451 (void) fsmNext(fsm, FSM_NOTIFY);
1453 if (fsmNext(fsm, FSM_FINI))
1454 /*@loopbreak@*/ break;
1457 /* Flush partial sets of hard linked files. */
1458 if (!(fsm->mapFlags & CPIO_ALL_HARDLINKS)) {
1460 while ((fsm->li = fsm->links) != NULL) {
1461 fsm->links = fsm->li->next;
1462 fsm->li->next = NULL;
1464 /* Re-calculate link count for archive header. */
1465 for (j = -1, nlink = 0, i = 0; i < fsm->li->nlink; i++) {
1466 if (fsm->li->filex[i] < 0)
1467 /*@innercontinue@*/ continue;
1471 /* XXX force the contents out as well. */
1474 fsm->li->filex[0] = fsm->li->filex[j];
1475 fsm->li->filex[j] = -1;
1478 fsm->li->sb.st_nlink = nlink;
1480 fsm->sb = fsm->li->sb; /* structure assignment */
1481 fsm->osb = fsm->sb; /* structure assignment */
1483 if (!rc) rc = writeLinkedFile(fsm);
1485 fsm->li = freeHardLink(fsm->li);
1490 rc = fsmNext(fsm, FSM_TRAILER);
1494 { rpmts ts = fsmGetTs(fsm);
1495 #define _tsmask (RPMTRANS_FLAG_PKGCOMMIT | RPMTRANS_FLAG_COMMIT)
1496 fsm->commit = ((ts && (rpmtsFlags(ts) & _tsmask) &&
1497 fsm->goal != FSM_PKGCOMMIT) ? 0 : 1);
1500 fsm->path = _free(fsm->path);
1501 fsm->opath = _free(fsm->opath);
1502 fsm->dnlx = _free(fsm->dnlx);
1504 fsm->ldn = _free(fsm->ldn);
1505 fsm->ldnalloc = fsm->ldnlen = 0;
1507 fsm->rdsize = fsm->wrsize = 0;
1508 fsm->rdbuf = fsm->rdb = _free(fsm->rdb);
1509 fsm->wrbuf = fsm->wrb = _free(fsm->wrb);
1510 if (fsm->goal == FSM_PKGINSTALL || fsm->goal == FSM_PKGBUILD) {
1511 fsm->rdsize = 8 * BUFSIZ;
1512 fsm->rdbuf = fsm->rdb = xmalloc(fsm->rdsize);
1513 fsm->wrsize = 8 * BUFSIZ;
1514 fsm->wrbuf = fsm->wrb = xmalloc(fsm->wrsize);
1517 fsm->mkdirsdone = 0;
1521 errno = 0; /* XXX get rid of EBADF */
1523 /* Detect and create directories not explicitly in package. */
1524 if (fsm->goal == FSM_PKGINSTALL) {
1525 rc = fsmNext(fsm, FSM_MKDIRS);
1526 if (!rc) fsm->mkdirsdone = 1;
1531 fsm->path = _free(fsm->path);
1533 fsm->diskchecked = fsm->exists = 0;
1535 fsm->suffix = (fsm->sufbuf[0] != '\0' ? fsm->sufbuf : NULL);
1536 fsm->action = FA_UNKNOWN;
1537 fsm->osuffix = NULL;
1538 fsm->nsuffix = NULL;
1540 if (fsm->goal == FSM_PKGINSTALL) {
1541 /* Read next header from payload, checking for end-of-payload. */
1542 rc = fsmUNSAFE(fsm, FSM_NEXT);
1546 /* Identify mapping index. */
1547 fsm->ix = ((fsm->goal == FSM_PKGINSTALL)
1548 ? mapFind(fsm->iter, fsm->path) : mapNextIterator(fsm->iter));
1550 /* Detect end-of-loop and/or mapping error. */
1552 if (fsm->goal == FSM_PKGINSTALL) {
1554 rpmMessage(RPMMESS_WARNING,
1555 _("archive file %s was not found in header file list\n"),
1559 if (fsm->failedFile && *fsm->failedFile == NULL)
1560 *fsm->failedFile = xstrdup(fsm->path);
1562 rc = CPIOERR_UNMAPPED_FILE;
1564 rc = CPIOERR_HDR_TRAILER;
1569 /* On non-install, mode must be known so that dirs don't get suffix. */
1570 if (fsm->goal != FSM_PKGINSTALL) {
1571 rpmfi fi = fsmGetFi(fsm);
1572 st->st_mode = fi->fmodes[fsm->ix];
1575 /* Generate file path. */
1576 rc = fsmNext(fsm, FSM_MAP);
1579 /* Perform lstat/stat for disk file. */
1583 if (fsm->path != NULL &&
1584 !(fsm->goal == FSM_PKGINSTALL && S_ISREG(st->st_mode)))
1586 rc = fsmStage(fsm, (!(fsm->mapFlags & CPIO_FOLLOW_SYMLINKS)
1587 ? FSM_LSTAT : FSM_STAT));
1588 if (rc == CPIOERR_LSTAT_FAILED && errno == ENOENT) {
1592 } else if (rc == 0) {
1596 /* Skip %ghost files on build. */
1600 fsm->diskchecked = 1;
1603 /* On non-install, the disk file stat is what's remapped. */
1605 if (fsm->goal != FSM_PKGINSTALL)
1606 *st = *ost; /* structure assignment */
1609 /* Remap file perms, owner, and group. */
1610 rc = fsmMapAttrs(fsm);
1613 fsm->postpone = XFA_SKIPPING(fsm->action);
1614 if (fsm->goal == FSM_PKGINSTALL || fsm->goal == FSM_PKGBUILD) {
1615 /*@-evalorder@*/ /* FIX: saveHardLink can modify fsm */
1616 if (!S_ISDIR(st->st_mode) && st->st_nlink > 1)
1617 fsm->postpone = saveHardLink(fsm);
1624 rc = fsmMapPath(fsm);
1627 rc = fsmMkdirs(fsm);
1631 rc = fsmRmdirs(fsm);
1634 if (fsm->postpone) {
1635 if (fsm->goal == FSM_PKGINSTALL)
1636 rc = fsmNext(fsm, FSM_EAT);
1640 if (fsm->goal == FSM_PKGBUILD) {
1641 if (fsm->fflags & RPMFILE_GHOST) /* XXX Don't if %ghost file. */
1643 if (!S_ISDIR(st->st_mode) && st->st_nlink > 1) {
1644 struct hardLink_s * li, * prev;
1646 if (!(fsm->mapFlags & CPIO_ALL_HARDLINKS)) break;
1647 rc = writeLinkedFile(fsm);
1648 if (rc) break; /* W2DO? */
1650 for (li = fsm->links, prev = NULL; li; prev = li, li = li->next)
1652 /*@loopbreak@*/ break;
1655 fsm->links = fsm->li->next;
1657 prev->next = fsm->li->next;
1658 fsm->li->next = NULL;
1659 fsm->li = freeHardLink(fsm->li);
1661 rc = writeFile(fsm, 1);
1666 if (fsm->goal != FSM_PKGINSTALL)
1669 if (S_ISREG(st->st_mode)) {
1670 const char * path = fsm->path;
1672 fsm->path = fsmFsPath(fsm, st, NULL, NULL);
1673 rc = fsmUNSAFE(fsm, FSM_VERIFY);
1675 if (rc == 0 && fsm->osuffix) {
1676 const char * opath = fsm->opath;
1677 fsm->opath = fsm->path;
1678 fsm->path = fsmFsPath(fsm, st, NULL, fsm->osuffix);
1679 rc = fsmNext(fsm, FSM_RENAME);
1681 rpmMessage(RPMMESS_WARNING,
1682 _("%s saved as %s\n"), fsm->opath, fsm->path);
1683 fsm->path = _free(fsm->path);
1687 /*@-dependenttrans@*/
1689 /*@=dependenttrans@*/
1690 if (rc != CPIOERR_LSTAT_FAILED) return rc;
1691 rc = expandRegular(fsm);
1692 } else if (S_ISDIR(st->st_mode)) {
1693 mode_t st_mode = st->st_mode;
1694 rc = fsmUNSAFE(fsm, FSM_VERIFY);
1695 if (rc == CPIOERR_LSTAT_FAILED) {
1696 st->st_mode &= ~07777; /* XXX abuse st->st_mode */
1697 st->st_mode |= 00700;
1698 rc = fsmNext(fsm, FSM_MKDIR);
1699 st->st_mode = st_mode; /* XXX restore st->st_mode */
1701 } else if (S_ISLNK(st->st_mode)) {
1702 const char * opath = fsm->opath;
1704 if ((st->st_size + 1) > fsm->rdsize) {
1705 rc = CPIOERR_HDR_SIZE;
1709 fsm->wrlen = st->st_size;
1710 rc = fsmNext(fsm, FSM_DREAD);
1711 if (!rc && fsm->rdnb != fsm->wrlen)
1712 rc = CPIOERR_READ_FAILED;
1716 fsm->wrbuf[st->st_size] = '\0';
1718 /* XXX symlink(fsm->opath, fsm->path) */
1719 /*@-dependenttrans@*/
1720 fsm->opath = fsm->wrbuf;
1721 /*@=dependenttrans@*/
1722 rc = fsmUNSAFE(fsm, FSM_VERIFY);
1723 if (rc == CPIOERR_LSTAT_FAILED)
1724 rc = fsmNext(fsm, FSM_SYMLINK);
1725 fsm->opath = opath; /* XXX restore fsm->path */
1726 } else if (S_ISFIFO(st->st_mode)) {
1727 mode_t st_mode = st->st_mode;
1728 /* This mimics cpio S_ISSOCK() behavior but probably isnt' right */
1729 rc = fsmUNSAFE(fsm, FSM_VERIFY);
1730 if (rc == CPIOERR_LSTAT_FAILED) {
1731 st->st_mode = 0000; /* XXX abuse st->st_mode */
1732 rc = fsmNext(fsm, FSM_MKFIFO);
1733 st->st_mode = st_mode; /* XXX restore st->st_mode */
1735 } else if (S_ISCHR(st->st_mode) ||
1736 S_ISBLK(st->st_mode) ||
1737 /*@-unrecog@*/ S_ISSOCK(st->st_mode) /*@=unrecog@*/)
1739 rc = fsmUNSAFE(fsm, FSM_VERIFY);
1740 if (rc == CPIOERR_LSTAT_FAILED)
1741 rc = fsmNext(fsm, FSM_MKNOD);
1743 /* XXX Special case /dev/log, which shouldn't be packaged anyways */
1744 if (!IS_DEV_LOG(fsm->path))
1745 rc = CPIOERR_UNKNOWN_FILETYPE;
1747 if (!S_ISDIR(st->st_mode) && st->st_nlink > 1) {
1748 fsm->li->createdPath = fsm->li->linkIndex;
1749 rc = fsmMakeLinks(fsm);
1755 rc = fsmMakeLinks(fsm);
1757 case FSM_NOTIFY: /* XXX move from fsm to psm -> tsm */
1758 if (fsm->goal == FSM_PKGINSTALL || fsm->goal == FSM_PKGBUILD) {
1759 rpmts ts = fsmGetTs(fsm);
1760 rpmfi fi = fsmGetFi(fsm);
1762 unsigned int archivePos = fdGetCpioPos(fsm->cfd);
1763 if (archivePos > fi->archivePos) {
1764 fi->archivePos = archivePos;
1765 ptr = rpmtsNotify(ts, fi->te, RPMCALLBACK_INST_PROGRESS,
1766 fi->archivePos, fi->archiveSize);
1773 if (fsm->goal == FSM_PKGINSTALL) {
1775 (S_ISDIR(st->st_mode) ? FSM_RMDIR : FSM_UNLINK));
1777 #ifdef NOTYET /* XXX remove only dirs just created, not all. */
1779 (void) fsmNext(fsm, FSM_RMDIRS);
1784 if (fsm->failedFile && *fsm->failedFile == NULL)
1785 *fsm->failedFile = xstrdup(fsm->path);
1789 if (!fsm->postpone && fsm->commit) {
1790 if (fsm->goal == FSM_PKGINSTALL)
1791 rc = ((!S_ISDIR(st->st_mode) && st->st_nlink > 1)
1792 ? fsmCommitLinks(fsm) : fsmNext(fsm, FSM_COMMIT));
1793 if (fsm->goal == FSM_PKGCOMMIT)
1794 rc = fsmNext(fsm, FSM_COMMIT);
1795 if (fsm->goal == FSM_PKGERASE)
1796 rc = fsmNext(fsm, FSM_COMMIT);
1798 fsm->path = _free(fsm->path);
1799 fsm->opath = _free(fsm->opath);
1801 memset(st, 0, sizeof(*st));
1802 memset(ost, 0, sizeof(*ost));
1806 /* Rename pre-existing modified or unmanaged file. */
1807 if (fsm->osuffix && fsm->diskchecked &&
1808 (fsm->exists || (fsm->goal == FSM_PKGINSTALL && S_ISREG(st->st_mode))))
1810 const char * opath = fsm->opath;
1811 const char * path = fsm->path;
1812 fsm->opath = fsmFsPath(fsm, st, NULL, NULL);
1813 fsm->path = fsmFsPath(fsm, st, NULL, fsm->osuffix);
1814 rc = fsmNext(fsm, FSM_RENAME);
1816 rpmMessage(RPMMESS_WARNING, _("%s saved as %s\n"),
1817 fsm->opath, fsm->path);
1819 fsm->path = _free(fsm->path);
1821 fsm->opath = _free(fsm->opath);
1825 /* Remove erased files. */
1826 if (fsm->goal == FSM_PKGERASE) {
1827 if (fsm->action == FA_ERASE) {
1828 rpmfi fi = fsmGetFi(fsm);
1829 if (S_ISDIR(st->st_mode)) {
1830 rc = fsmNext(fsm, FSM_RMDIR);
1833 case ENOENT: /* XXX rmdir("/") linux 2.2.x kernel hack */
1835 /* XXX make sure that build side permits %missingok on directories. */
1836 if (fsm->fflags & RPMFILE_MISSINGOK)
1837 /*@innerbreak@*/ break;
1839 /* XXX common error message. */
1841 (strict_erasures ? RPMERR_RMDIR : RPMDEBUG_RMDIR),
1842 _("%s rmdir of %s failed: Directory not empty\n"),
1843 rpmfiTypeString(fi), fsm->path);
1844 /*@innerbreak@*/ break;
1847 (strict_erasures ? RPMERR_RMDIR : RPMDEBUG_RMDIR),
1848 _("%s rmdir of %s failed: %s\n"),
1849 rpmfiTypeString(fi), fsm->path, strerror(errno));
1850 /*@innerbreak@*/ break;
1853 rc = fsmNext(fsm, FSM_UNLINK);
1855 if (!(errno == ENOENT && (fsm->fflags & RPMFILE_MISSINGOK)))
1857 (strict_erasures ? RPMERR_UNLINK : RPMDEBUG_UNLINK),
1858 _("%s unlink of %s failed: %s\n"),
1859 rpmfiTypeString(fi), fsm->path, strerror(errno));
1862 /* XXX Failure to remove is not (yet) cause for failure. */
1863 if (!strict_erasures) rc = 0;
1867 /* XXX Special case /dev/log, which shouldn't be packaged anyways */
1868 if (!S_ISSOCK(st->st_mode) && !IS_DEV_LOG(fsm->path)) {
1869 /* Rename temporary to final file name. */
1870 if (!S_ISDIR(st->st_mode) &&
1871 (fsm->subdir || fsm->suffix || fsm->nsuffix))
1873 fsm->opath = fsm->path;
1874 fsm->path = fsmFsPath(fsm, st, NULL, fsm->nsuffix);
1875 rc = fsmNext(fsm, FSM_RENAME);
1876 if (!rc && fsm->nsuffix) {
1877 const char * opath = fsmFsPath(fsm, st, NULL, NULL);
1878 rpmMessage(RPMMESS_WARNING, _("%s created as %s\n"),
1879 (opath ? opath : ""), fsm->path);
1880 opath = _free(opath);
1882 fsm->opath = _free(fsm->opath);
1884 if (S_ISLNK(st->st_mode)) {
1885 if (!rc && !getuid())
1886 rc = fsmNext(fsm, FSM_LCHOWN);
1888 if (!rc && !getuid())
1889 rc = fsmNext(fsm, FSM_CHOWN);
1891 rc = fsmNext(fsm, FSM_CHMOD);
1893 time_t mtime = st->st_mtime;
1894 rpmfi fi = fsmGetFi(fsm);
1896 st->st_mtime = fi->fmtimes[fsm->ix];
1897 rc = fsmNext(fsm, FSM_UTIME);
1898 st->st_mtime = mtime;
1903 /* Notify on success. */
1904 if (!rc) rc = fsmNext(fsm, FSM_NOTIFY);
1905 else if (fsm->failedFile && *fsm->failedFile == NULL) {
1907 *fsm->failedFile = fsm->path;
1913 fsm->path = _free(fsm->path);
1915 /* Check for hard links missing from payload. */
1916 while ((fsm->li = fsm->links) != NULL) {
1917 fsm->links = fsm->li->next;
1918 fsm->li->next = NULL;
1919 if (fsm->goal == FSM_PKGINSTALL &&
1920 fsm->commit && fsm->li->linksLeft)
1922 for (i = 0 ; i < fsm->li->linksLeft; i++) {
1923 if (fsm->li->filex[i] < 0)
1924 /*@innercontinue@*/ continue;
1925 rc = CPIOERR_MISSING_HARDLINK;
1926 if (fsm->failedFile && *fsm->failedFile == NULL) {
1927 fsm->ix = fsm->li->filex[i];
1928 if (!fsmNext(fsm, FSM_MAP)) {
1930 *fsm->failedFile = fsm->path;
1935 /*@loopbreak@*/ break;
1938 if (fsm->goal == FSM_PKGBUILD &&
1939 (fsm->mapFlags & CPIO_ALL_HARDLINKS))
1941 rc = CPIOERR_MISSING_HARDLINK;
1943 fsm->li = freeHardLink(fsm->li);
1945 fsm->ldn = _free(fsm->ldn);
1946 fsm->ldnalloc = fsm->ldnlen = 0;
1947 fsm->rdbuf = fsm->rdb = _free(fsm->rdb);
1948 fsm->wrbuf = fsm->wrb = _free(fsm->wrb);
1951 if (fsm->diskchecked && !fsm->exists) {
1952 rc = CPIOERR_LSTAT_FAILED;
1955 if (S_ISREG(st->st_mode)) {
1956 char * path = alloca(strlen(fsm->path) + sizeof("-RPMDELETE"));
1958 (void) stpcpy( stpcpy(path, fsm->path), "-RPMDELETE");
1961 * XXX HP-UX (and other os'es) don't permit unlink on busy
1964 fsm->opath = fsm->path;
1966 rc = fsmNext(fsm, FSM_RENAME);
1968 (void) fsmNext(fsm, FSM_UNLINK);
1970 rc = CPIOERR_UNLINK_FAILED;
1971 fsm->path = fsm->opath;
1973 return (rc ? rc : CPIOERR_LSTAT_FAILED); /* XXX HACK */
1974 /*@notreached@*/ break;
1975 } else if (S_ISDIR(st->st_mode)) {
1976 if (S_ISDIR(ost->st_mode)) return 0;
1977 if (S_ISLNK(ost->st_mode)) {
1978 rc = fsmStage(fsm, FSM_STAT);
1979 if (rc == CPIOERR_STAT_FAILED && errno == ENOENT) rc = 0;
1982 if (S_ISDIR(ost->st_mode)) return 0;
1984 } else if (S_ISLNK(st->st_mode)) {
1985 if (S_ISLNK(ost->st_mode)) {
1986 /* XXX NUL terminated result in fsm->rdbuf, len in fsm->rdnb. */
1987 rc = fsmStage(fsm, FSM_READLINK);
1990 if (!strcmp(fsm->opath, fsm->rdbuf)) return 0;
1992 } else if (S_ISFIFO(st->st_mode)) {
1993 if (S_ISFIFO(ost->st_mode)) return 0;
1994 } else if (S_ISCHR(st->st_mode) || S_ISBLK(st->st_mode)) {
1995 if ((S_ISCHR(ost->st_mode) || S_ISBLK(ost->st_mode)) &&
1996 (ost->st_rdev == st->st_rdev)) return 0;
1997 } else if (S_ISSOCK(st->st_mode)) {
1998 if (S_ISSOCK(ost->st_mode)) return 0;
2000 /* XXX shouldn't do this with commit/undo. */
2002 if (fsm->stage == FSM_PROCESS) rc = fsmNext(fsm, FSM_UNLINK);
2003 if (rc == 0) rc = CPIOERR_LSTAT_FAILED;
2004 return (rc ? rc : CPIOERR_LSTAT_FAILED); /* XXX HACK */
2005 /*@notreached@*/ break;
2008 rc = Unlink(fsm->path);
2009 if (_fsm_debug && (stage & FSM_SYSCALL))
2010 rpmMessage(RPMMESS_DEBUG, " %8s (%s) %s\n", cur,
2011 fsm->path, (rc < 0 ? strerror(errno) : ""));
2012 if (rc < 0) rc = CPIOERR_UNLINK_FAILED;
2015 rc = Rename(fsm->opath, fsm->path);
2016 #if defined(ETXTBSY)
2017 if (rc && errno == ETXTBSY) {
2018 char * path = alloca(strlen(fsm->path) + sizeof("-RPMDELETE"));
2019 (void) stpcpy( stpcpy(path, fsm->path), "-RPMDELETE");
2021 * XXX HP-UX (and other os'es) don't permit rename to busy
2024 rc = Rename(fsm->path, path);
2025 if (!rc) rc = Rename(fsm->opath, fsm->path);
2028 if (_fsm_debug && (stage & FSM_SYSCALL))
2029 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %s) %s\n", cur,
2030 fsm->opath, fsm->path, (rc < 0 ? strerror(errno) : ""));
2031 if (rc < 0) rc = CPIOERR_RENAME_FAILED;
2034 rc = Mkdir(fsm->path, (st->st_mode & 07777));
2035 if (_fsm_debug && (stage & FSM_SYSCALL))
2036 rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0%04o) %s\n", cur,
2037 fsm->path, (unsigned)(st->st_mode & 07777),
2038 (rc < 0 ? strerror(errno) : ""));
2039 if (rc < 0) rc = CPIOERR_MKDIR_FAILED;
2042 rc = Rmdir(fsm->path);
2043 if (_fsm_debug && (stage & FSM_SYSCALL))
2044 rpmMessage(RPMMESS_DEBUG, " %8s (%s) %s\n", cur,
2045 fsm->path, (rc < 0 ? strerror(errno) : ""));
2046 if (rc < 0) rc = CPIOERR_RMDIR_FAILED;
2049 rc = chown(fsm->path, st->st_uid, st->st_gid);
2050 if (_fsm_debug && (stage & FSM_SYSCALL))
2051 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %d, %d) %s\n", cur,
2052 fsm->path, (int)st->st_uid, (int)st->st_gid,
2053 (rc < 0 ? strerror(errno) : ""));
2054 if (rc < 0) rc = CPIOERR_CHOWN_FAILED;
2057 #if ! CHOWN_FOLLOWS_SYMLINK
2058 rc = lchown(fsm->path, st->st_uid, st->st_gid);
2059 if (_fsm_debug && (stage & FSM_SYSCALL))
2060 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %d, %d) %s\n", cur,
2061 fsm->path, (int)st->st_uid, (int)st->st_gid,
2062 (rc < 0 ? strerror(errno) : ""));
2063 if (rc < 0) rc = CPIOERR_CHOWN_FAILED;
2067 rc = chmod(fsm->path, (st->st_mode & 07777));
2068 if (_fsm_debug && (stage & FSM_SYSCALL))
2069 rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0%04o) %s\n", cur,
2070 fsm->path, (unsigned)(st->st_mode & 07777),
2071 (rc < 0 ? strerror(errno) : ""));
2072 if (rc < 0) rc = CPIOERR_CHMOD_FAILED;
2075 { struct utimbuf stamp;
2076 stamp.actime = st->st_mtime;
2077 stamp.modtime = st->st_mtime;
2078 rc = utime(fsm->path, &stamp);
2079 if (_fsm_debug && (stage & FSM_SYSCALL))
2080 rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0x%x) %s\n", cur,
2081 fsm->path, (unsigned)st->st_mtime,
2082 (rc < 0 ? strerror(errno) : ""));
2083 if (rc < 0) rc = CPIOERR_UTIME_FAILED;
2087 rc = symlink(fsm->opath, fsm->path);
2088 if (_fsm_debug && (stage & FSM_SYSCALL))
2089 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %s) %s\n", cur,
2090 fsm->opath, fsm->path, (rc < 0 ? strerror(errno) : ""));
2091 if (rc < 0) rc = CPIOERR_SYMLINK_FAILED;
2094 rc = Link(fsm->opath, fsm->path);
2095 if (_fsm_debug && (stage & FSM_SYSCALL))
2096 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %s) %s\n", cur,
2097 fsm->opath, fsm->path, (rc < 0 ? strerror(errno) : ""));
2098 if (rc < 0) rc = CPIOERR_LINK_FAILED;
2101 rc = mkfifo(fsm->path, (st->st_mode & 07777));
2102 if (_fsm_debug && (stage & FSM_SYSCALL))
2103 rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0%04o) %s\n", cur,
2104 fsm->path, (unsigned)(st->st_mode & 07777),
2105 (rc < 0 ? strerror(errno) : ""));
2106 if (rc < 0) rc = CPIOERR_MKFIFO_FAILED;
2109 /*@-unrecog -portability @*/ /* FIX: check S_IFIFO or dev != 0 */
2110 rc = mknod(fsm->path, (st->st_mode & ~07777), st->st_rdev);
2111 /*@=unrecog =portability @*/
2112 if (_fsm_debug && (stage & FSM_SYSCALL))
2113 rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0%o, 0x%x) %s\n", cur,
2114 fsm->path, (unsigned)(st->st_mode & ~07777),
2115 (unsigned)st->st_rdev,
2116 (rc < 0 ? strerror(errno) : ""));
2117 if (rc < 0) rc = CPIOERR_MKNOD_FAILED;
2120 rc = Lstat(fsm->path, ost);
2121 if (_fsm_debug && (stage & FSM_SYSCALL) && rc && errno != ENOENT)
2122 rpmMessage(RPMMESS_DEBUG, " %8s (%s, ost) %s\n", cur,
2123 fsm->path, (rc < 0 ? strerror(errno) : ""));
2124 if (rc < 0) rc = CPIOERR_LSTAT_FAILED;
2127 rc = Stat(fsm->path, ost);
2128 if (_fsm_debug && (stage & FSM_SYSCALL) && rc && errno != ENOENT)
2129 rpmMessage(RPMMESS_DEBUG, " %8s (%s, ost) %s\n", cur,
2130 fsm->path, (rc < 0 ? strerror(errno) : ""));
2131 if (rc < 0) rc = CPIOERR_STAT_FAILED;
2134 /* XXX NUL terminated result in fsm->rdbuf, len in fsm->rdnb. */
2136 rc = Readlink(fsm->path, fsm->rdbuf, fsm->rdsize - 1);
2138 if (_fsm_debug && (stage & FSM_SYSCALL))
2139 rpmMessage(RPMMESS_DEBUG, " %8s (%s, rdbuf, %d) %s\n", cur,
2140 fsm->path, (int)(fsm->rdsize -1), (rc < 0 ? strerror(errno) : ""));
2141 if (rc < 0) rc = CPIOERR_READLINK_FAILED;
2145 fsm->rdbuf[fsm->rdnb] = '\0';
2154 rc = fsmStage(fsm, FSM_HREAD);
2156 if (!strcmp(fsm->path, CPIO_TRAILER)) { /* Detect end-of-payload. */
2157 fsm->path = _free(fsm->path);
2158 rc = CPIOERR_HDR_TRAILER;
2161 rc = fsmNext(fsm, FSM_POS);
2164 for (left = st->st_size; left > 0; left -= fsm->rdnb) {
2165 fsm->wrlen = (left > fsm->wrsize ? fsm->wrsize : left);
2166 rc = fsmNext(fsm, FSM_DREAD);
2168 /*@loopbreak@*/ break;
2172 left = (modulo - (fdGetCpioPos(fsm->cfd) % modulo)) % modulo;
2175 (void) fsmNext(fsm, FSM_DREAD);
2179 left = (modulo - (fdGetCpioPos(fsm->cfd) % modulo)) % modulo;
2182 memset(fsm->rdbuf, 0, left);
2184 /* XXX DWRITE uses rdnb for I/O length. */
2186 (void) fsmNext(fsm, FSM_DWRITE);
2190 rc = cpioTrailerWrite(fsm);
2193 rc = fsmNext(fsm, FSM_POS);
2195 rc = cpioHeaderRead(fsm, st); /* Read next payload header. */
2198 rc = cpioHeaderWrite(fsm, st); /* Write next payload header. */
2202 fsm->rdnb = Fread(fsm->wrbuf, sizeof(*fsm->wrbuf), fsm->wrlen, fsm->cfd);
2204 if (_fsm_debug && (stage & FSM_SYSCALL))
2205 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %d, cfd)\trdnb %d\n",
2206 cur, (fsm->wrbuf == fsm->wrb ? "wrbuf" : "mmap"),
2207 (int)fsm->wrlen, (int)fsm->rdnb);
2208 if (fsm->rdnb != fsm->wrlen || Ferror(fsm->cfd))
2209 rc = CPIOERR_READ_FAILED;
2211 fdSetCpioPos(fsm->cfd, fdGetCpioPos(fsm->cfd) + fsm->rdnb);
2214 fsm->wrnb = Fwrite(fsm->rdbuf, sizeof(*fsm->rdbuf), fsm->rdnb, fsm->cfd);
2215 if (_fsm_debug && (stage & FSM_SYSCALL))
2216 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %d, cfd)\twrnb %d\n",
2217 cur, (fsm->rdbuf == fsm->rdb ? "rdbuf" : "mmap"),
2218 (int)fsm->rdnb, (int)fsm->wrnb);
2219 if (fsm->rdnb != fsm->wrnb || Ferror(fsm->cfd))
2220 rc = CPIOERR_WRITE_FAILED;
2222 fdSetCpioPos(fsm->cfd, fdGetCpioPos(fsm->cfd) + fsm->wrnb);
2226 fsm->rfd = Fopen(fsm->path, "r.ufdio");
2227 if (fsm->rfd == NULL || Ferror(fsm->rfd)) {
2228 if (fsm->rfd != NULL) (void) fsmNext(fsm, FSM_RCLOSE);
2230 rc = CPIOERR_OPEN_FAILED;
2233 if (_fsm_debug && (stage & FSM_SYSCALL))
2234 rpmMessage(RPMMESS_DEBUG, " %8s (%s, \"r\") rfd %p rdbuf %p\n", cur,
2235 fsm->path, fsm->rfd, fsm->rdbuf);
2239 fsm->rdnb = Fread(fsm->rdbuf, sizeof(*fsm->rdbuf), fsm->rdlen, fsm->rfd);
2241 if (_fsm_debug && (stage & FSM_SYSCALL))
2242 rpmMessage(RPMMESS_DEBUG, " %8s (rdbuf, %d, rfd)\trdnb %d\n",
2243 cur, (int)fsm->rdlen, (int)fsm->rdnb);
2244 if (fsm->rdnb != fsm->rdlen || Ferror(fsm->rfd))
2245 rc = CPIOERR_READ_FAILED;
2248 if (fsm->rfd != NULL) {
2249 if (_fsm_debug && (stage & FSM_SYSCALL))
2250 rpmMessage(RPMMESS_DEBUG, " %8s (%p)\n", cur, fsm->rfd);
2251 (void) Fclose(fsm->rfd);
2257 fsm->wfd = Fopen(fsm->path, "w.ufdio");
2258 if (fsm->wfd == NULL || Ferror(fsm->wfd)) {
2259 if (fsm->wfd != NULL) (void) fsmNext(fsm, FSM_WCLOSE);
2261 rc = CPIOERR_OPEN_FAILED;
2263 if (_fsm_debug && (stage & FSM_SYSCALL))
2264 rpmMessage(RPMMESS_DEBUG, " %8s (%s, \"w\") wfd %p wrbuf %p\n", cur,
2265 fsm->path, fsm->wfd, fsm->wrbuf);
2268 fsm->wrnb = Fwrite(fsm->wrbuf, sizeof(*fsm->wrbuf), fsm->rdnb, fsm->wfd);
2269 if (_fsm_debug && (stage & FSM_SYSCALL))
2270 rpmMessage(RPMMESS_DEBUG, " %8s (wrbuf, %d, wfd)\twrnb %d\n",
2271 cur, (int)fsm->rdnb, (int)fsm->wrnb);
2272 if (fsm->rdnb != fsm->wrnb || Ferror(fsm->wfd))
2273 rc = CPIOERR_WRITE_FAILED;
2276 if (fsm->wfd != NULL) {
2277 if (_fsm_debug && (stage & FSM_SYSCALL))
2278 rpmMessage(RPMMESS_DEBUG, " %8s (%p)\n", cur, fsm->wfd);
2279 (void) Fclose(fsm->wfd);
2290 if (!(stage & FSM_INTERNAL)) {
2291 fsm->rc = (rc == CPIOERR_HDR_TRAILER ? 0 : rc);
2298 /*@obserever@*/ const char *const fileActionString(fileAction a)
2301 case FA_UNKNOWN: return "unknown";
2302 case FA_CREATE: return "create";
2303 case FA_COPYOUT: return "copyout";
2304 case FA_COPYIN: return "copyin";
2305 case FA_BACKUP: return "backup";
2306 case FA_SAVE: return "save";
2307 case FA_SKIP: return "skip";
2308 case FA_ALTNAME: return "altname";
2309 case FA_ERASE: return "erase";
2310 case FA_SKIPNSTATE: return "skipnstate";
2311 case FA_SKIPNETSHARED: return "skipnetshared";
2312 case FA_SKIPCOLOR: return "skipcolor";
2313 default: return "???";
2318 /*@observer@*/ const char *const fileStageString(fileStage a) {
2320 case FSM_UNKNOWN: return "unknown";
2322 case FSM_PKGINSTALL:return "INSTALL";
2323 case FSM_PKGERASE: return "ERASE";
2324 case FSM_PKGBUILD: return "BUILD";
2325 case FSM_PKGCOMMIT: return "COMMIT";
2326 case FSM_PKGUNDO: return "UNDO";
2328 case FSM_CREATE: return "create";
2329 case FSM_INIT: return "init";
2330 case FSM_MAP: return "map";
2331 case FSM_MKDIRS: return "mkdirs";
2332 case FSM_RMDIRS: return "rmdirs";
2333 case FSM_PRE: return "pre";
2334 case FSM_PROCESS: return "process";
2335 case FSM_POST: return "post";
2336 case FSM_MKLINKS: return "mklinks";
2337 case FSM_NOTIFY: return "notify";
2338 case FSM_UNDO: return "undo";
2339 case FSM_FINI: return "fini";
2340 case FSM_COMMIT: return "commit";
2341 case FSM_DESTROY: return "destroy";
2342 case FSM_VERIFY: return "verify";
2344 case FSM_UNLINK: return "Unlink";
2345 case FSM_RENAME: return "Rename";
2346 case FSM_MKDIR: return "Mkdir";
2347 case FSM_RMDIR: return "rmdir";
2348 case FSM_CHOWN: return "chown";
2349 case FSM_LCHOWN: return "lchown";
2350 case FSM_CHMOD: return "chmod";
2351 case FSM_UTIME: return "utime";
2352 case FSM_SYMLINK: return "symlink";
2353 case FSM_LINK: return "Link";
2354 case FSM_MKFIFO: return "mkfifo";
2355 case FSM_MKNOD: return "mknod";
2356 case FSM_LSTAT: return "Lstat";
2357 case FSM_STAT: return "Stat";
2358 case FSM_READLINK: return "Readlink";
2359 case FSM_CHROOT: return "chroot";
2361 case FSM_NEXT: return "next";
2362 case FSM_EAT: return "eat";
2363 case FSM_POS: return "pos";
2364 case FSM_PAD: return "pad";
2365 case FSM_TRAILER: return "trailer";
2366 case FSM_HREAD: return "hread";
2367 case FSM_HWRITE: return "hwrite";
2368 case FSM_DREAD: return "Fread";
2369 case FSM_DWRITE: return "Fwrite";
2371 case FSM_ROPEN: return "Fopen";
2372 case FSM_READ: return "Fread";
2373 case FSM_RCLOSE: return "Fclose";
2374 case FSM_WOPEN: return "Fopen";
2375 case FSM_WRITE: return "Fwrite";
2376 case FSM_WCLOSE: return "Fclose";
2378 default: return "???";