00001
00006 #include "system.h"
00007
00008 #include "psm.h"
00009 #include "rpmerr.h"
00010 #include "debug.h"
00011
00012
00013
00014
00015
00016
00017
00018 #define alloca_strdup(_s) strcpy(alloca(strlen(_s)+1), (_s))
00019
00020 int _fsm_debug = 0;
00021
00022
00023
00024 int strict_erasures = 0;
00025
00026
00027 rpmTransactionSet fsmGetTs(const FSM_t fsm) {
00028 const FSMI_t iter = fsm->iter;
00029
00030 return (iter ? iter->ts : NULL);
00031
00032 }
00033
00034 TFI_t fsmGetFi(const FSM_t fsm)
00035 {
00036 const FSMI_t iter = fsm->iter;
00037
00038 return (iter ? iter->fi : NULL);
00039
00040 }
00041
00042 #define SUFFIX_RPMORIG ".rpmorig"
00043 #define SUFFIX_RPMSAVE ".rpmsave"
00044 #define SUFFIX_RPMNEW ".rpmnew"
00045
00054 static
00055 const char * fsmFsPath( const FSM_t fsm,
00056 const struct stat * st,
00057 const char * subdir,
00058 const char * suffix)
00059
00060 {
00061 const char * s = NULL;
00062
00063 if (fsm) {
00064 int nb;
00065 char * t;
00066
00067 nb = strlen(fsm->dirName) +
00068 (st && subdir && !S_ISDIR(st->st_mode) ? strlen(subdir) : 0) +
00069 (st && suffix && !S_ISDIR(st->st_mode) ? strlen(suffix) : 0) +
00070 strlen(fsm->baseName) + 1;
00071 s = t = xmalloc(nb);
00072 t = stpcpy(t, fsm->dirName);
00073 if (st && subdir && !S_ISDIR(st->st_mode))
00074 t = stpcpy(t, subdir);
00075 t = stpcpy(t, fsm->baseName);
00076 if (st && suffix && !S_ISDIR(st->st_mode))
00077 t = stpcpy(t, suffix);
00078
00079 }
00080 return s;
00081 }
00082
00088 static void * mapFreeIterator(const void * p)
00089 {
00090 return _free((void *)p);
00091 }
00092
00099 static void *
00100 mapInitIterator( const void * a, const void * b)
00101 {
00102 rpmTransactionSet ts = (void *)a;
00103 TFI_t fi = (void *)b;
00104 FSMI_t iter = NULL;
00105
00106 iter = xcalloc(1, sizeof(*iter));
00107
00108 iter->ts = ts;
00109 iter->fi = fi;
00110
00111 iter->reverse = (fi->type == TR_REMOVED && fi->action != FA_COPYOUT);
00112 iter->i = (iter->reverse ? (fi->fc - 1) : 0);
00113 iter->isave = iter->i;
00114 return iter;
00115 }
00116
00122 static int mapNextIterator(void * a) {
00123 FSMI_t iter = a;
00124 const TFI_t fi = iter->fi;
00125 int i = -1;
00126
00127 if (iter->reverse) {
00128 if (iter->i >= 0) i = iter->i--;
00129 } else {
00130 if (iter->i < fi->fc) i = iter->i++;
00131 }
00132 iter->isave = i;
00133 return i;
00134 }
00135
00138 static int cpioStrCmp(const void * a, const void * b)
00139
00140 {
00141 const char * afn = *(const char **)a;
00142 const char * bfn = *(const char **)b;
00143
00144
00145 if (afn[0] == '.' && afn[1] == '/') afn += 2;
00146 if (bfn[0] == '.' && bfn[1] == '/') bfn += 2;
00147
00148
00149 if (afn[0] == '/') afn += 1;
00150 if (bfn[0] == '/') bfn += 1;
00151
00152 return strcmp(afn, bfn);
00153 }
00154
00161 static int mapFind(void * a, const char * fsmPath)
00162
00163 {
00164 FSMI_t iter = a;
00165 const TFI_t fi = iter->fi;
00166 int ix = -1;
00167
00168 if (fi && fi->fc > 0 && fi->apath && fsmPath && *fsmPath) {
00169 const char ** p = NULL;
00170
00171 if (fi->apath != NULL)
00172 p = bsearch(&fsmPath, fi->apath, fi->fc, sizeof(fsmPath),
00173 cpioStrCmp);
00174 if (p) {
00175 iter->i = p - fi->apath;
00176 ix = mapNextIterator(iter);
00177 }
00178 }
00179 return ix;
00180 }
00181
00185 typedef struct dnli_s {
00186 TFI_t fi;
00187 char * active;
00188 int reverse;
00189 int isave;
00190 int i;
00191 } * DNLI_t;
00192
00198 static void * dnlFreeIterator( const void * a)
00199
00200 {
00201 if (a) {
00202 DNLI_t dnli = (void *)a;
00203 if (dnli->active) free(dnli->active);
00204 }
00205 return _free(a);
00206 }
00207
00210 static inline int dnlCount(const DNLI_t dnli)
00211
00212 {
00213 return (dnli ? dnli->fi->dc : 0);
00214 }
00215
00218 static inline int dnlIndex(const DNLI_t dnli)
00219
00220 {
00221 return (dnli ? dnli->isave : -1);
00222 }
00223
00230 static void * dnlInitIterator( const FSM_t fsm,
00231 int reverse)
00232
00233
00234 {
00235 TFI_t fi = fsmGetFi(fsm);
00236 DNLI_t dnli;
00237 int i, j;
00238
00239 if (fi == NULL)
00240 return NULL;
00241 dnli = xcalloc(1, sizeof(*dnli));
00242 dnli->fi = fi;
00243 dnli->reverse = reverse;
00244 dnli->i = (reverse ? fi->dc : 0);
00245
00246 if (fi->dc) {
00247 dnli->active = xcalloc(fi->dc, sizeof(*dnli->active));
00248
00249
00250 for (i = 0; i < fi->fc; i++)
00251 if (!XFA_SKIPPING(fi->actions[i])) dnli->active[fi->dil[i]] = 1;
00252
00253
00254 for (i = 0; i < fi->fc; i++) {
00255 int dil, dnlen, bnlen;
00256
00257 if (!S_ISDIR(fi->fmodes[i]))
00258 continue;
00259
00260 dil = fi->dil[i];
00261 dnlen = strlen(fi->dnl[dil]);
00262 bnlen = strlen(fi->bnl[i]);
00263
00264 for (j = 0; j < fi->dc; j++) {
00265 const char * dnl;
00266 int jlen;
00267
00268 if (!dnli->active[j] || j == dil) continue;
00269 dnl = fi->dnl[j];
00270 jlen = strlen(dnl);
00271 if (jlen != (dnlen+bnlen+1)) continue;
00272 if (strncmp(dnl, fi->dnl[dil], dnlen)) continue;
00273 if (strncmp(dnl+dnlen, fi->bnl[i], bnlen)) continue;
00274 if (dnl[dnlen+bnlen] != '/' || dnl[dnlen+bnlen+1] != '\0')
00275 continue;
00276
00277 dnli->active[j] = 0;
00278 break;
00279 }
00280 }
00281
00282
00283 if (!reverse) {
00284 j = 0;
00285 for (i = 0; i < fi->dc; i++) {
00286 if (!dnli->active[i]) continue;
00287 if (j == 0) {
00288 j = 1;
00289 rpmMessage(RPMMESS_DEBUG,
00290 _("========= Directories not explictly included in package:\n"));
00291 }
00292 rpmMessage(RPMMESS_DEBUG, _("%9d %s\n"), i, fi->dnl[i]);
00293 }
00294 if (j)
00295 rpmMessage(RPMMESS_DEBUG, "=========\n");
00296 }
00297 }
00298 return dnli;
00299 }
00300
00306 static const char * dnlNextIterator( DNLI_t dnli)
00307
00308 {
00309 const char * dn = NULL;
00310
00311 if (dnli) {
00312 TFI_t fi = dnli->fi;
00313 int i = -1;
00314
00315 if (dnli->active)
00316 do {
00317 i = (!dnli->reverse ? dnli->i++ : --dnli->i);
00318 } while (i >= 0 && i < fi->dc && !dnli->active[i]);
00319
00320 if (i >= 0 && i < fi->dc)
00321 dn = fi->dnl[i];
00322 else
00323 i = -1;
00324 dnli->isave = i;
00325 }
00326 return dn;
00327 }
00328
00334
00335 static int saveHardLink( FSM_t fsm)
00336
00337
00338
00339
00340 {
00341 struct stat * st = &fsm->sb;
00342 int rc = 0;
00343 int ix = -1;
00344 int j;
00345
00346
00347 for (fsm->li = fsm->links; fsm->li; fsm->li = fsm->li->next) {
00348 if (fsm->li->sb.st_ino == st->st_ino && fsm->li->sb.st_dev == st->st_dev)
00349 break;
00350 }
00351
00352
00353 if (fsm->li == NULL) {
00354 fsm->li = xcalloc(1, sizeof(*fsm->li));
00355 fsm->li->next = NULL;
00356 fsm->li->sb = *st;
00357 fsm->li->nlink = st->st_nlink;
00358 fsm->li->linkIndex = fsm->ix;
00359 fsm->li->createdPath = -1;
00360
00361 fsm->li->filex = xcalloc(st->st_nlink, sizeof(fsm->li->filex[0]));
00362 memset(fsm->li->filex, -1, (st->st_nlink * sizeof(fsm->li->filex[0])));
00363 fsm->li->nsuffix = xcalloc(st->st_nlink, sizeof(*fsm->li->nsuffix));
00364
00365 if (fsm->goal == FSM_PKGBUILD)
00366 fsm->li->linksLeft = st->st_nlink;
00367 if (fsm->goal == FSM_PKGINSTALL)
00368 fsm->li->linksLeft = 0;
00369
00370
00371 fsm->li->next = fsm->links;
00372
00373 fsm->links = fsm->li;
00374 }
00375
00376 if (fsm->goal == FSM_PKGBUILD) --fsm->li->linksLeft;
00377 fsm->li->filex[fsm->li->linksLeft] = fsm->ix;
00378
00379 fsm->li->nsuffix[fsm->li->linksLeft] = fsm->nsuffix;
00380
00381 if (fsm->goal == FSM_PKGINSTALL) fsm->li->linksLeft++;
00382
00383 if (fsm->goal == FSM_PKGBUILD)
00384 return (fsm->li->linksLeft > 0);
00385
00386 if (fsm->goal != FSM_PKGINSTALL)
00387 return 0;
00388
00389 if (!(st->st_size || fsm->li->linksLeft == st->st_nlink))
00390 return 1;
00391
00392
00393 { TFI_t fi = fsmGetFi(fsm);
00394
00395 for (j = fsm->li->linksLeft - 1; j >= 0; j--) {
00396 ix = fsm->li->filex[j];
00397 if (ix < 0 || XFA_SKIPPING(fi->actions[ix]))
00398 continue;
00399 break;
00400 }
00401 }
00402
00403
00404 if (ix < 0 || j < 0)
00405 return 1;
00406
00407
00408 fsm->li->linkIndex = j;
00409 fsm->path = _free(fsm->path);
00410 fsm->ix = ix;
00411 rc = fsmStage(fsm, FSM_MAP);
00412
00413 return rc;
00414
00415 }
00416
00417
00422 static void * freeHardLink( struct hardLink * li)
00423
00424 {
00425 if (li) {
00426 li->nsuffix = _free(li->nsuffix);
00427 li->filex = _free(li->filex);
00428 }
00429 return _free(li);
00430 }
00431
00432 FSM_t newFSM(void)
00433 {
00434 FSM_t fsm = xcalloc(1, sizeof(*fsm));
00435 return fsm;
00436 }
00437
00438 FSM_t freeFSM(FSM_t fsm)
00439 {
00440 if (fsm) {
00441 fsm->path = _free(fsm->path);
00442 while ((fsm->li = fsm->links) != NULL) {
00443 fsm->links = fsm->li->next;
00444 fsm->li->next = NULL;
00445 fsm->li = freeHardLink(fsm->li);
00446 }
00447 fsm->dnlx = _free(fsm->dnlx);
00448 fsm->ldn = _free(fsm->ldn);
00449 fsm->iter = mapFreeIterator(fsm->iter);
00450 }
00451 return _free(fsm);
00452 }
00453
00454 int fsmSetup(FSM_t fsm, fileStage goal,
00455 const rpmTransactionSet ts, const TFI_t fi, FD_t cfd,
00456 unsigned int * archiveSize, const char ** failedFile)
00457 {
00458 size_t pos = 0;
00459 int rc, ec = 0;
00460
00461 fsm->goal = goal;
00462 if (cfd) {
00463 fsm->cfd = fdLink(cfd, "persist (fsm)");
00464 pos = fdGetCpioPos(fsm->cfd);
00465 fdSetCpioPos(fsm->cfd, 0);
00466 }
00467 fsm->iter = mapInitIterator(ts, fi);
00468
00469 if (fsm->goal == FSM_PKGINSTALL) {
00470 if (ts && ts->notify) {
00471 (void)ts->notify(fi->h, RPMCALLBACK_INST_START, 0, fi->archiveSize,
00472 (fi->ap ? fi->ap->key : NULL), ts->notifyData);
00473 }
00474 }
00475
00476
00477 fsm->archiveSize = archiveSize;
00478 if (fsm->archiveSize)
00479 *fsm->archiveSize = 0;
00480 fsm->failedFile = failedFile;
00481 if (fsm->failedFile)
00482 *fsm->failedFile = NULL;
00483
00484
00485 memset(fsm->sufbuf, 0, sizeof(fsm->sufbuf));
00486 if (fsm->goal == FSM_PKGINSTALL) {
00487 if (ts && ts->id > 0)
00488 sprintf(fsm->sufbuf, ";%08x", (unsigned)ts->id);
00489 }
00490
00491 ec = fsm->rc = 0;
00492 rc = fsmStage(fsm, FSM_CREATE);
00493 if (rc && !ec) ec = rc;
00494
00495 rc = fsmStage(fsm, fsm->goal);
00496 if (rc && !ec) ec = rc;
00497
00498 if (fsm->archiveSize && ec == 0)
00499 *fsm->archiveSize = (fdGetCpioPos(fsm->cfd) - pos);
00500
00501 return ec;
00502 }
00503
00504 int fsmTeardown(FSM_t fsm) {
00505 int rc = fsm->rc;
00506
00507 if (!rc)
00508 rc = fsmStage(fsm, FSM_DESTROY);
00509
00510 fsm->iter = mapFreeIterator(fsm->iter);
00511 if (fsm->cfd) {
00512 fsm->cfd = fdFree(fsm->cfd, "persist (fsm)");
00513 fsm->cfd = NULL;
00514 }
00515 fsm->failedFile = NULL;
00516
00517 return rc;
00518
00519 }
00520
00521 int fsmMapPath(FSM_t fsm)
00522 {
00523 TFI_t fi = fsmGetFi(fsm);
00524 int rc = 0;
00525 int i;
00526
00527 fsm->osuffix = NULL;
00528 fsm->nsuffix = NULL;
00529 fsm->astriplen = 0;
00530 fsm->action = FA_UNKNOWN;
00531 fsm->mapFlags = 0;
00532
00533 i = fsm->ix;
00534 if (fi && i >= 0 && i < fi->fc) {
00535
00536 fsm->astriplen = fi->astriplen;
00537 fsm->action = (fi->actions ? fi->actions[i] : fi->action);
00538 fsm->fflags = (fi->fflags ? fi->fflags[i] : fi->flags);
00539 fsm->mapFlags = (fi->fmapflags ? fi->fmapflags[i] : fi->mapflags);
00540
00541
00542 fsm->dirName = fi->dnl[fi->dil[i]];
00543 fsm->baseName = fi->bnl[i];
00544
00545 switch (fsm->action) {
00546 case FA_SKIP:
00547 break;
00548 case FA_SKIPMULTILIB:
00549 break;
00550 case FA_UNKNOWN:
00551 break;
00552
00553 case FA_COPYOUT:
00554 break;
00555 case FA_COPYIN:
00556 case FA_CREATE:
00557 assert(fi->type == TR_ADDED);
00558 break;
00559
00560 case FA_SKIPNSTATE:
00561 if (fi->fstates && fi->type == TR_ADDED)
00562 fi->fstates[i] = RPMFILE_STATE_NOTINSTALLED;
00563 break;
00564
00565 case FA_SKIPNETSHARED:
00566 if (fi->fstates && fi->type == TR_ADDED)
00567 fi->fstates[i] = RPMFILE_STATE_NETSHARED;
00568 break;
00569
00570 case FA_BACKUP:
00571 if (!(fsm->fflags & RPMFILE_GHOST))
00572 switch (fi->type) {
00573 case TR_ADDED:
00574 fsm->osuffix = SUFFIX_RPMORIG;
00575 break;
00576 case TR_REMOVED:
00577 fsm->osuffix = SUFFIX_RPMSAVE;
00578 break;
00579 }
00580 break;
00581
00582 case FA_ALTNAME:
00583 assert(fi->type == TR_ADDED);
00584 if (!(fsm->fflags & RPMFILE_GHOST))
00585 fsm->nsuffix = SUFFIX_RPMNEW;
00586 break;
00587
00588 case FA_SAVE:
00589 assert(fi->type == TR_ADDED);
00590 if (!(fsm->fflags & RPMFILE_GHOST))
00591 fsm->osuffix = SUFFIX_RPMSAVE;
00592 break;
00593 case FA_ERASE:
00594 assert(fi->type == TR_REMOVED);
00595
00596
00597
00598
00599 break;
00600 default:
00601 break;
00602 }
00603
00604 if ((fsm->mapFlags & CPIO_MAP_PATH) || fsm->nsuffix) {
00605 const struct stat * st = &fsm->sb;
00606 fsm->path = _free(fsm->path);
00607
00608 fsm->path = fsmFsPath(fsm, st, fsm->subdir,
00609 (fsm->suffix ? fsm->suffix : fsm->nsuffix));
00610
00611 }
00612 }
00613 return rc;
00614 }
00615
00616 int fsmMapAttrs(FSM_t fsm)
00617 {
00618 struct stat * st = &fsm->sb;
00619 TFI_t fi = fsmGetFi(fsm);
00620 int i = fsm->ix;
00621
00622 if (fi && i >= 0 && i < fi->fc) {
00623 mode_t perms =
00624 (S_ISDIR(st->st_mode) ? fi->dperms : fi->fperms);
00625 mode_t finalMode =
00626 (fi->fmodes ? fi->fmodes[i] : perms);
00627 uid_t finalUid =
00628 (fi->fuids ? fi->fuids[i] : fi->uid);
00629 gid_t finalGid =
00630 (fi->fgids ? fi->fgids[i] : fi->gid);
00631 dev_t finalRdev =
00632 (fi->frdevs ? fi->frdevs[i] : 0);
00633 int_32 finalMtime =
00634 (fi->fmtimes ? fi->fmtimes[i] : 0);
00635
00636 if (fsm->mapFlags & CPIO_MAP_MODE)
00637 st->st_mode = (st->st_mode & S_IFMT) | (finalMode & ~S_IFMT);
00638 if (fsm->mapFlags & CPIO_MAP_TYPE) {
00639 st->st_mode = (st->st_mode & ~S_IFMT) | (finalMode & S_IFMT);
00640 if ((S_ISCHR(st->st_mode) || S_ISBLK(st->st_mode))
00641 && st->st_nlink == 0)
00642 st->st_nlink = 1;
00643 st->st_rdev = finalRdev;
00644 st->st_mtime = finalMtime;
00645 }
00646 if (fsm->mapFlags & CPIO_MAP_UID)
00647 st->st_uid = finalUid;
00648 if (fsm->mapFlags & CPIO_MAP_GID)
00649 st->st_gid = finalGid;
00650
00651 fsm->fmd5sum = (fi->fmd5s ? fi->fmd5s[i] : NULL);
00652
00653 }
00654 return 0;
00655 }
00656
00663 static int expandRegular( FSM_t fsm)
00664
00665
00666 {
00667 const char * fmd5sum;
00668 const struct stat * st = &fsm->sb;
00669 int left = st->st_size;
00670 int rc = 0;
00671
00672 rc = fsmStage(fsm, FSM_WOPEN);
00673 if (rc)
00674 goto exit;
00675
00676
00677 fmd5sum = fsm->fmd5sum;
00678
00679
00680 if (st->st_size > 0 && fmd5sum)
00681 fdInitMD5(fsm->wfd, 0);
00682
00683 while (left) {
00684
00685 fsm->wrlen = (left > fsm->wrsize ? fsm->wrsize : left);
00686 rc = fsmStage(fsm, FSM_DREAD);
00687 if (rc)
00688 goto exit;
00689
00690 rc = fsmStage(fsm, FSM_WRITE);
00691 if (rc)
00692 goto exit;
00693
00694 left -= fsm->wrnb;
00695
00696
00697 if (!rc && left)
00698 (void) fsmStage(fsm, FSM_NOTIFY);
00699 }
00700
00701 if (st->st_size > 0 && fmd5sum) {
00702 const char * md5sum = NULL;
00703
00704 (void) Fflush(fsm->wfd);
00705 fdFiniMD5(fsm->wfd, (void **)&md5sum, NULL, 1);
00706
00707 if (md5sum == NULL) {
00708 rc = CPIOERR_MD5SUM_MISMATCH;
00709 } else {
00710 if (strcmp(md5sum, fmd5sum))
00711 rc = CPIOERR_MD5SUM_MISMATCH;
00712 md5sum = _free(md5sum);
00713 }
00714 }
00715
00716 exit:
00717 (void) fsmStage(fsm, FSM_WCLOSE);
00718 return rc;
00719 }
00720
00727 static int writeFile( FSM_t fsm, int writeData)
00728
00729
00730 {
00731 const char * path = fsm->path;
00732 const char * opath = fsm->opath;
00733 struct stat * st = &fsm->sb;
00734 struct stat * ost = &fsm->osb;
00735 size_t pos = fdGetCpioPos(fsm->cfd);
00736 char * symbuf = NULL;
00737 int left;
00738 int rc;
00739
00740 st->st_size = (writeData ? ost->st_size : 0);
00741
00742 if (S_ISDIR(st->st_mode)) {
00743 st->st_size = 0;
00744 } else if (S_ISLNK(st->st_mode)) {
00745
00746
00747
00748
00749
00750 rc = fsmStage(fsm, FSM_READLINK);
00751 if (rc) goto exit;
00752 st->st_size = fsm->rdnb;
00753 symbuf = alloca_strdup(fsm->rdbuf);
00754 }
00755
00756 if (fsm->mapFlags & CPIO_MAP_ABSOLUTE) {
00757 int nb = strlen(fsm->dirName) + strlen(fsm->baseName) + sizeof(".");
00758 char * t = alloca(nb);
00759 *t = '\0';
00760 fsm->path = t;
00761 if (fsm->mapFlags & CPIO_MAP_ADDDOT)
00762 *t++ = '.';
00763 t = stpcpy( stpcpy(t, fsm->dirName), fsm->baseName);
00764 } else if (fsm->mapFlags & CPIO_MAP_PATH) {
00765 TFI_t fi = fsmGetFi(fsm);
00766 fsm->path =
00767 (fi->apath ? fi->apath[fsm->ix] + fi->striplen : fi->bnl[fsm->ix]);
00768 }
00769
00770 rc = fsmStage(fsm, FSM_HWRITE);
00771 fsm->path = path;
00772 if (rc) goto exit;
00773
00774 if (writeData && S_ISREG(st->st_mode)) {
00775 #if HAVE_MMAP
00776 char * rdbuf = NULL;
00777 void * mapped = (void *)-1;
00778 size_t nmapped;
00779 #endif
00780
00781 rc = fsmStage(fsm, FSM_ROPEN);
00782 if (rc) goto exit;
00783
00784
00785 #if HAVE_MMAP
00786 nmapped = 0;
00787 mapped = mmap(NULL, st->st_size, PROT_READ, MAP_SHARED, Fileno(fsm->rfd), 0);
00788 if (mapped != (void *)-1) {
00789 rdbuf = fsm->rdbuf;
00790 fsm->rdbuf = (char *) mapped;
00791 fsm->rdlen = nmapped = st->st_size;
00792 }
00793 #endif
00794
00795 left = st->st_size;
00796
00797 while (left) {
00798 #if HAVE_MMAP
00799 if (mapped != (void *)-1) {
00800 fsm->rdnb = nmapped;
00801 } else
00802 #endif
00803 {
00804 fsm->rdlen = (left > fsm->rdsize ? fsm->rdsize : left),
00805 rc = fsmStage(fsm, FSM_READ);
00806 if (rc) goto exit;
00807 }
00808
00809
00810 rc = fsmStage(fsm, FSM_DWRITE);
00811 if (rc) goto exit;
00812
00813 left -= fsm->wrnb;
00814 }
00815
00816 #if HAVE_MMAP
00817 if (mapped != (void *)-1) {
00818 (void) munmap(mapped, nmapped) ;
00819 fsm->rdbuf = rdbuf;
00820 }
00821 #endif
00822
00823 } else if (writeData && S_ISLNK(st->st_mode)) {
00824
00825 strcpy(fsm->rdbuf, symbuf);
00826 fsm->rdnb = strlen(symbuf);
00827 rc = fsmStage(fsm, FSM_DWRITE);
00828 if (rc) goto exit;
00829 }
00830
00831 rc = fsmStage(fsm, FSM_PAD);
00832 if (rc) goto exit;
00833
00834 { const rpmTransactionSet ts = fsmGetTs(fsm);
00835 TFI_t fi = fsmGetFi(fsm);
00836 if (ts && fi && ts->notify) {
00837 size_t size = (fdGetCpioPos(fsm->cfd) - pos);
00838
00839 (void)ts->notify(fi->h, RPMCALLBACK_INST_PROGRESS, size, size,
00840 (fi->ap ? fi->ap->key : NULL), ts->notifyData);
00841
00842 }
00843 }
00844
00845 rc = 0;
00846
00847 exit:
00848 if (fsm->rfd)
00849 (void) fsmStage(fsm, FSM_RCLOSE);
00850
00851 fsm->opath = opath;
00852 fsm->path = path;
00853
00854 return rc;
00855 }
00856
00862 static int writeLinkedFile( FSM_t fsm)
00863
00864
00865 {
00866 const char * path = fsm->path;
00867 const char * nsuffix = fsm->nsuffix;
00868 int iterIndex = fsm->ix;
00869 int ec = 0;
00870 int rc;
00871 int i;
00872
00873 fsm->path = NULL;
00874 fsm->nsuffix = NULL;
00875 fsm->ix = -1;
00876
00877 for (i = fsm->li->nlink - 1; i >= 0; i--) {
00878
00879 if (fsm->li->filex[i] < 0) continue;
00880
00881 fsm->ix = fsm->li->filex[i];
00882 rc = fsmStage(fsm, FSM_MAP);
00883
00884
00885 rc = writeFile(fsm, (i == 0));
00886 if (fsm->failedFile && rc != 0 && *fsm->failedFile == NULL) {
00887 ec = rc;
00888 *fsm->failedFile = xstrdup(fsm->path);
00889 }
00890
00891 fsm->path = _free(fsm->path);
00892 fsm->li->filex[i] = -1;
00893 }
00894
00895 fsm->ix = iterIndex;
00896 fsm->nsuffix = nsuffix;
00897 fsm->path = path;
00898 return ec;
00899 }
00900
00906 static int fsmMakeLinks( FSM_t fsm)
00907
00908
00909 {
00910 const char * path = fsm->path;
00911 const char * opath = fsm->opath;
00912 const char * nsuffix = fsm->nsuffix;
00913 int iterIndex = fsm->ix;
00914 int ec = 0;
00915 int rc;
00916 int i;
00917
00918 fsm->path = NULL;
00919 fsm->opath = NULL;
00920 fsm->nsuffix = NULL;
00921 fsm->ix = -1;
00922
00923 fsm->ix = fsm->li->filex[fsm->li->createdPath];
00924 rc = fsmStage(fsm, FSM_MAP);
00925 fsm->opath = fsm->path;
00926 fsm->path = NULL;
00927 for (i = 0; i < fsm->li->nlink; i++) {
00928 if (fsm->li->filex[i] < 0) continue;
00929 if (i == fsm->li->createdPath) continue;
00930
00931 fsm->ix = fsm->li->filex[i];
00932 fsm->path = _free(fsm->path);
00933 rc = fsmStage(fsm, FSM_MAP);
00934 rc = fsmStage(fsm, FSM_VERIFY);
00935 if (!rc) continue;
00936 if (rc != CPIOERR_LSTAT_FAILED) break;
00937
00938
00939 rc = fsmStage(fsm, FSM_LINK);
00940 if (fsm->failedFile && rc != 0 && *fsm->failedFile == NULL) {
00941 ec = rc;
00942 *fsm->failedFile = xstrdup(fsm->path);
00943 }
00944
00945 fsm->li->linksLeft--;
00946 }
00947 fsm->path = _free(fsm->path);
00948 fsm->opath = _free(fsm->opath);
00949
00950 fsm->ix = iterIndex;
00951 fsm->nsuffix = nsuffix;
00952 fsm->path = path;
00953 fsm->opath = opath;
00954 return ec;
00955 }
00956
00962 static int fsmCommitLinks( FSM_t fsm)
00963
00964
00965
00966 {
00967 const char * path = fsm->path;
00968 const char * nsuffix = fsm->nsuffix;
00969 int iterIndex = fsm->ix;
00970 struct stat * st = &fsm->sb;
00971 int rc = 0;
00972 int i;
00973
00974 fsm->path = NULL;
00975 fsm->nsuffix = NULL;
00976 fsm->ix = -1;
00977
00978 for (fsm->li = fsm->links; fsm->li; fsm->li = fsm->li->next) {
00979 if (fsm->li->sb.st_ino == st->st_ino && fsm->li->sb.st_dev == st->st_dev)
00980 break;
00981 }
00982
00983 for (i = 0; i < fsm->li->nlink; i++) {
00984 if (fsm->li->filex[i] < 0) continue;
00985 fsm->ix = fsm->li->filex[i];
00986 rc = fsmStage(fsm, FSM_MAP);
00987 rc = fsmStage(fsm, FSM_COMMIT);
00988 fsm->path = _free(fsm->path);
00989 fsm->li->filex[i] = -1;
00990 }
00991
00992 fsm->ix = iterIndex;
00993 fsm->nsuffix = nsuffix;
00994 fsm->path = path;
00995 return rc;
00996 }
00997
01003
01004 static int fsmRmdirs( FSM_t fsm)
01005
01006
01007 {
01008 const char * path = fsm->path;
01009 void * dnli = dnlInitIterator(fsm, 1);
01010 char * dn = fsm->rdbuf;
01011 int dc = dnlCount(dnli);
01012 int rc = 0;
01013
01014 fsm->path = NULL;
01015 dn[0] = '\0';
01016
01017 if (fsm->ldn != NULL && fsm->dnlx != NULL)
01018 while ((fsm->path = dnlNextIterator(dnli)) != NULL) {
01019 int dnlen = strlen(fsm->path);
01020 char * te;
01021
01022 dc = dnlIndex(dnli);
01023 if (fsm->dnlx[dc] < 1 || fsm->dnlx[dc] >= dnlen)
01024 continue;
01025
01026
01027 te = stpcpy(dn, fsm->path) - 1;
01028 fsm->path = dn;
01029
01030
01031 do {
01032 if (*te == '/') {
01033 *te = '\0';
01034 rc = fsmStage(fsm, FSM_RMDIR);
01035 *te = '/';
01036 }
01037 if (rc)
01038 break;
01039 te--;
01040 } while ((te - dn) > fsm->dnlx[dc]);
01041 }
01042 dnli = dnlFreeIterator(dnli);
01043
01044
01045 fsm->path = path;
01046 return rc;
01047 }
01048
01049
01055 static int fsmMkdirs( FSM_t fsm)
01056
01057
01058
01059
01060 {
01061 struct stat * st = &fsm->sb;
01062 struct stat * ost = &fsm->osb;
01063 const char * path = fsm->path;
01064 mode_t st_mode = st->st_mode;
01065 void * dnli = dnlInitIterator(fsm, 0);
01066 char * dn = fsm->rdbuf;
01067 int dc = dnlCount(dnli);
01068 int rc = 0;
01069 int i;
01070
01071 fsm->path = NULL;
01072
01073 dn[0] = '\0';
01074 fsm->dnlx = (dc ? xcalloc(dc, sizeof(*fsm->dnlx)) : NULL);
01075
01076 if (fsm->dnlx != NULL)
01077 while ((fsm->path = dnlNextIterator(dnli)) != NULL) {
01078 int dnlen = strlen(fsm->path);
01079 char * te;
01080
01081 dc = dnlIndex(dnli);
01082 if (dc < 0) continue;
01083 fsm->dnlx[dc] = dnlen;
01084 if (dnlen <= 1)
01085 continue;
01086
01087
01088 if (dnlen <= fsm->ldnlen && !strcmp(fsm->path, fsm->ldn))
01089 continue;
01090
01091
01092
01093 (void) stpcpy(dn, fsm->path);
01094 fsm->path = dn;
01095
01096
01097 for (i = 1, te = dn + 1; *te != '\0'; te++, i++) {
01098 if (*te != '/') continue;
01099
01100 *te = '\0';
01101
01102
01103
01104 if (i < fsm->ldnlen &&
01105 (fsm->ldn[i] == '/' || fsm->ldn[i] == '\0') &&
01106 !strncmp(fsm->path, fsm->ldn, i))
01107 {
01108 *te = '/';
01109
01110 fsm->dnlx[dc] = (te - dn);
01111 continue;
01112 }
01113
01114
01115
01116 rc = fsmStage(fsm, FSM_LSTAT);
01117 *te = '/';
01118
01119
01120 if (rc == 0 && S_ISDIR(ost->st_mode)) {
01121
01122 fsm->dnlx[dc] = (te - dn);
01123 } else if (rc == CPIOERR_LSTAT_FAILED) {
01124 TFI_t fi = fsmGetFi(fsm);
01125 *te = '\0';
01126 st->st_mode = S_IFDIR | (fi->dperms & 07777);
01127 rc = fsmStage(fsm, FSM_MKDIR);
01128 if (!rc)
01129 rpmMessage(RPMMESS_DEBUG,
01130 _("%s directory created with perms %04o.\n"),
01131 fsm->path, (unsigned)(st->st_mode & 07777));
01132 *te = '/';
01133 }
01134 if (rc)
01135 break;
01136 }
01137 if (rc) break;
01138
01139
01140 if (fsm->ldnalloc < (dnlen + 1)) {
01141 fsm->ldnalloc = dnlen + 100;
01142 fsm->ldn = xrealloc(fsm->ldn, fsm->ldnalloc);
01143 }
01144 if (fsm->ldn != NULL) {
01145 strcpy(fsm->ldn, fsm->path);
01146 fsm->ldnlen = dnlen;
01147 }
01148 }
01149 dnli = dnlFreeIterator(dnli);
01150
01151
01152 fsm->path = path;
01153 st->st_mode = st_mode;
01154 return rc;
01155 }
01156
01157 #ifdef NOTYET
01158
01163 static int fsmStat(FSM_t fsm)
01164 {
01165 int saveerrno = errno;
01166 int rc = 0;
01167
01168 if (fsm->path != NULL) {
01169 int saveernno = errno;
01170 rc = fsmStage(fsm, (!(fsm->mapFlags & CPIO_FOLLOW_SYMLINKS)
01171 ? FSM_LSTAT : FSM_STAT));
01172 if (rc == CPIOERR_LSTAT_FAILED && errno == ENOENT) {
01173 errno = saveerrno;
01174 rc = 0;
01175 fsm->exists = 0;
01176 } else if (rc == 0) {
01177 fsm->exists = 1;
01178 }
01179 } else {
01180
01181 fsm->exists = 0;
01182 }
01183 return rc;
01184 }
01185 #endif
01186
01187
01188 int fsmStage(FSM_t fsm, fileStage stage)
01189 {
01190 #ifdef UNUSED
01191 fileStage prevStage = fsm->stage;
01192 const char * const prev = fileStageString(prevStage);
01193 #endif
01194 static int modulo = 4;
01195 const char * const cur = fileStageString(stage);
01196 struct stat * st = &fsm->sb;
01197 struct stat * ost = &fsm->osb;
01198 int saveerrno = errno;
01199 int rc = fsm->rc;
01200 size_t left;
01201 int i;
01202
01203 #define _fafilter(_a) \
01204 (!((_a) == FA_CREATE || (_a) == FA_ERASE || (_a) == FA_COPYIN || (_a) == FA_COPYOUT) \
01205 ? fileActionString(_a) : "")
01206
01207 if (stage & FSM_DEAD) {
01208
01209 } else if (stage & FSM_INTERNAL) {
01210 if (_fsm_debug && !(stage & FSM_SYSCALL))
01211 rpmMessage(RPMMESS_DEBUG, " %8s %06o%3d (%4d,%4d)%10d %s %s\n",
01212 cur,
01213 (unsigned)st->st_mode, (int)st->st_nlink,
01214 (int)st->st_uid, (int)st->st_gid, (int)st->st_size,
01215 (fsm->path ? fsm->path : ""),
01216 _fafilter(fsm->action));
01217 } else {
01218 fsm->stage = stage;
01219 if (_fsm_debug || !(stage & FSM_VERBOSE))
01220 rpmMessage(RPMMESS_DEBUG, "%-8s %06o%3d (%4d,%4d)%10d %s %s\n",
01221 cur,
01222 (unsigned)st->st_mode, (int)st->st_nlink,
01223 (int)st->st_uid, (int)st->st_gid, (int)st->st_size,
01224 (fsm->path ? fsm->path + fsm->astriplen : ""),
01225 _fafilter(fsm->action));
01226 }
01227 #undef _fafilter
01228
01229 switch (stage) {
01230 case FSM_UNKNOWN:
01231 break;
01232 case FSM_PKGINSTALL:
01233 while (1) {
01234
01235 rc = fsmStage(fsm, FSM_INIT);
01236
01237
01238 if (rc == CPIOERR_HDR_TRAILER) {
01239 rc = 0;
01240 break;
01241 }
01242
01243
01244 if (rc) {
01245 fsm->postpone = 1;
01246 (void) fsmStage(fsm, FSM_UNDO);
01247 break;
01248 }
01249
01250
01251 rc = fsmStage(fsm, FSM_PROCESS);
01252 if (rc) {
01253 (void) fsmStage(fsm, FSM_UNDO);
01254 break;
01255 }
01256
01257
01258 (void) fsmStage(fsm, FSM_NOTIFY);
01259
01260 rc = fsmStage(fsm, FSM_FINI);
01261 if (rc) {
01262 break;
01263 }
01264 }
01265 break;
01266 case FSM_PKGERASE:
01267 case FSM_PKGCOMMIT:
01268 while (1) {
01269
01270 rc = fsmStage(fsm, FSM_INIT);
01271
01272
01273 if (rc == CPIOERR_HDR_TRAILER) {
01274 rc = 0;
01275 break;
01276 }
01277
01278
01279 if (fsmStage(fsm, FSM_FINI))
01280 break;
01281 }
01282 break;
01283 case FSM_PKGBUILD:
01284 while (1) {
01285
01286 rc = fsmStage(fsm, FSM_INIT);
01287
01288
01289 if (rc == CPIOERR_HDR_TRAILER) {
01290 rc = 0;
01291 break;
01292 }
01293
01294
01295 if (rc) {
01296 fsm->postpone = 1;
01297 (void) fsmStage(fsm, FSM_UNDO);
01298 break;
01299 }
01300
01301
01302 rc = fsmStage(fsm, FSM_PROCESS);
01303 if (rc) {
01304 (void) fsmStage(fsm, FSM_UNDO);
01305 break;
01306 }
01307
01308 if (fsmStage(fsm, FSM_FINI))
01309 break;
01310 }
01311
01312
01313 if (!(fsm->mapFlags & CPIO_ALL_HARDLINKS)) {
01314 int nlink, j;
01315 while ((fsm->li = fsm->links) != NULL) {
01316 fsm->links = fsm->li->next;
01317 fsm->li->next = NULL;
01318
01319
01320 for (j = -1, nlink = 0, i = 0; i < fsm->li->nlink; i++) {
01321 if (fsm->li->filex[i] < 0) continue;
01322 nlink++;
01323 if (j == -1) j = i;
01324 }
01325
01326 if (j != 0) {
01327 fsm->li->filex[0] = fsm->li->filex[j];
01328 fsm->li->filex[j] = -1;
01329 }
01330 fsm->li->sb.st_nlink = nlink;
01331
01332 fsm->sb = fsm->li->sb;
01333 fsm->osb = fsm->sb;
01334
01335 if (!rc) rc = writeLinkedFile(fsm);
01336
01337 fsm->li = freeHardLink(fsm->li);
01338 }
01339 }
01340
01341 if (!rc)
01342 rc = fsmStage(fsm, FSM_TRAILER);
01343
01344 break;
01345 case FSM_CREATE:
01346 { rpmTransactionSet ts = fsmGetTs(fsm);
01347 #define _tsmask (RPMTRANS_FLAG_PKGCOMMIT | RPMTRANS_FLAG_COMMIT)
01348 fsm->commit = ((ts && (ts->transFlags & _tsmask) &&
01349 fsm->goal != FSM_PKGCOMMIT) ? 0 : 1);
01350 #undef _tsmask
01351 }
01352 fsm->path = _free(fsm->path);
01353 fsm->opath = _free(fsm->opath);
01354 fsm->dnlx = _free(fsm->dnlx);
01355
01356 fsm->ldn = _free(fsm->ldn);
01357 fsm->ldnalloc = fsm->ldnlen = 0;
01358
01359 fsm->rdsize = fsm->wrsize = 0;
01360 fsm->rdbuf = fsm->rdb = _free(fsm->rdb);
01361 fsm->wrbuf = fsm->wrb = _free(fsm->wrb);
01362 if (fsm->goal == FSM_PKGINSTALL || fsm->goal == FSM_PKGBUILD) {
01363 fsm->rdsize = 8 * BUFSIZ;
01364 fsm->rdbuf = fsm->rdb = xmalloc(fsm->rdsize);
01365 fsm->wrsize = 8 * BUFSIZ;
01366 fsm->wrbuf = fsm->wrb = xmalloc(fsm->wrsize);
01367 }
01368
01369 fsm->mkdirsdone = 0;
01370 fsm->ix = -1;
01371 fsm->links = NULL;
01372 fsm->li = NULL;
01373 errno = 0;
01374
01375
01376 if (fsm->goal == FSM_PKGINSTALL) {
01377 rc = fsmStage(fsm, FSM_MKDIRS);
01378 if (!rc) fsm->mkdirsdone = 1;
01379 }
01380
01381 break;
01382 case FSM_INIT:
01383 fsm->path = _free(fsm->path);
01384 fsm->postpone = 0;
01385 fsm->diskchecked = fsm->exists = 0;
01386 fsm->subdir = NULL;
01387 fsm->suffix = (fsm->sufbuf[0] != '\0' ? fsm->sufbuf : NULL);
01388 fsm->action = FA_UNKNOWN;
01389 fsm->osuffix = NULL;
01390 fsm->nsuffix = NULL;
01391
01392 if (fsm->goal == FSM_PKGINSTALL) {
01393
01394 rc = fsmStage(fsm, FSM_NEXT);
01395 }
01396 if (rc) break;
01397
01398
01399 fsm->ix = ((fsm->goal == FSM_PKGINSTALL)
01400 ? mapFind(fsm->iter, fsm->path) : mapNextIterator(fsm->iter));
01401
01402
01403 if (fsm->ix < 0) {
01404 if (fsm->goal == FSM_PKGINSTALL) {
01405 #if 0
01406 rpmMessage(RPMMESS_WARNING,
01407 _("archive file %s was not found in header file list\n"),
01408 fsm->path);
01409 #endif
01410 if (fsm->failedFile && *fsm->failedFile == NULL)
01411 *fsm->failedFile = xstrdup(fsm->path);
01412 rc = CPIOERR_UNMAPPED_FILE;
01413 } else {
01414 rc = CPIOERR_HDR_TRAILER;
01415 }
01416 break;
01417 }
01418
01419
01420 if (fsm->goal != FSM_PKGINSTALL) {
01421 TFI_t fi = fsmGetFi(fsm);
01422 st->st_mode = fi->fmodes[fsm->ix];
01423 }
01424
01425
01426 rc = fsmStage(fsm, FSM_MAP);
01427 if (rc) break;
01428
01429
01430 #ifdef NOTYET
01431 rc = fsmStat(fsm);
01432 #else
01433 if (fsm->path != NULL) {
01434 rc = fsmStage(fsm, (!(fsm->mapFlags & CPIO_FOLLOW_SYMLINKS)
01435 ? FSM_LSTAT : FSM_STAT));
01436 if (rc == CPIOERR_LSTAT_FAILED && errno == ENOENT) {
01437 errno = saveerrno;
01438 rc = 0;
01439 fsm->exists = 0;
01440 } else if (rc == 0) {
01441 fsm->exists = 1;
01442 }
01443 } else {
01444
01445 fsm->exists = 0;
01446 }
01447 #endif
01448 fsm->diskchecked = 1;
01449 if (rc) break;
01450
01451
01452 if (fsm->goal != FSM_PKGINSTALL)
01453 *st = *ost;
01454
01455
01456 rc = fsmMapAttrs(fsm);
01457 if (rc) break;
01458
01459 fsm->postpone = XFA_SKIPPING(fsm->action);
01460 if (fsm->goal == FSM_PKGINSTALL || fsm->goal == FSM_PKGBUILD) {
01461
01462 if (!S_ISDIR(st->st_mode) && st->st_nlink > 1)
01463 fsm->postpone = saveHardLink(fsm);
01464
01465 }
01466 break;
01467 case FSM_PRE:
01468 break;
01469 case FSM_MAP:
01470 rc = fsmMapPath(fsm);
01471 break;
01472 case FSM_MKDIRS:
01473 rc = fsmMkdirs(fsm);
01474 break;
01475 case FSM_RMDIRS:
01476 if (fsm->dnlx)
01477 rc = fsmRmdirs(fsm);
01478 break;
01479 case FSM_PROCESS:
01480 if (fsm->postpone) {
01481 if (fsm->goal == FSM_PKGINSTALL)
01482 rc = fsmStage(fsm, FSM_EAT);
01483 break;
01484 }
01485
01486 if (fsm->goal == FSM_PKGBUILD) {
01487 if (!S_ISDIR(st->st_mode) && st->st_nlink > 1) {
01488 struct hardLink * li, * prev;
01489
01490 if (!(fsm->mapFlags & CPIO_ALL_HARDLINKS)) break;
01491 rc = writeLinkedFile(fsm);
01492 if (rc) break;
01493
01494 for (li = fsm->links, prev = NULL; li; prev = li, li = li->next)
01495 if (li == fsm->li)
01496 break;
01497
01498 if (prev == NULL)
01499 fsm->links = fsm->li->next;
01500 else
01501 prev->next = fsm->li->next;
01502 fsm->li->next = NULL;
01503 fsm->li = freeHardLink(fsm->li);
01504 } else {
01505 rc = writeFile(fsm, 1);
01506 }
01507 break;
01508 }
01509
01510 if (fsm->goal != FSM_PKGINSTALL)
01511 break;
01512
01513 if (S_ISREG(st->st_mode)) {
01514 const char * path = fsm->path;
01515 if (fsm->osuffix)
01516 fsm->path = fsmFsPath(fsm, st, NULL, NULL);
01517 rc = fsmStage(fsm, FSM_VERIFY);
01518
01519 if (rc == 0 && fsm->osuffix) {
01520 const char * opath = fsm->opath;
01521 fsm->opath = fsm->path;
01522 fsm->path = fsmFsPath(fsm, st, NULL, fsm->osuffix);
01523 rc = fsmStage(fsm, FSM_RENAME);
01524 if (!rc)
01525 rpmMessage(RPMMESS_WARNING,
01526 _("%s saved as %s\n"), fsm->opath, fsm->path);
01527 fsm->path = _free(fsm->path);
01528 fsm->opath = opath;
01529 }
01530
01531
01532 fsm->path = path;
01533
01534 if (rc != CPIOERR_LSTAT_FAILED) return rc;
01535 rc = expandRegular(fsm);
01536 } else if (S_ISDIR(st->st_mode)) {
01537 mode_t st_mode = st->st_mode;
01538 rc = fsmStage(fsm, FSM_VERIFY);
01539 if (rc == CPIOERR_LSTAT_FAILED) {
01540 st->st_mode &= ~07777;
01541 st->st_mode |= 00700;
01542 rc = fsmStage(fsm, FSM_MKDIR);
01543 st->st_mode = st_mode;
01544 }
01545 } else if (S_ISLNK(st->st_mode)) {
01546 const char * opath = fsm->opath;
01547
01548 if ((st->st_size + 1) > fsm->rdsize) {
01549 rc = CPIOERR_HDR_SIZE;
01550 break;
01551 }
01552
01553 fsm->wrlen = st->st_size;
01554 rc = fsmStage(fsm, FSM_DREAD);
01555 if (!rc && fsm->rdnb != fsm->wrlen)
01556 rc = CPIOERR_READ_FAILED;
01557 if (rc) break;
01558
01559 fsm->wrbuf[st->st_size] = '\0';
01560
01561
01562 fsm->opath = fsm->wrbuf;
01563
01564 rc = fsmStage(fsm, FSM_VERIFY);
01565 if (rc == CPIOERR_LSTAT_FAILED)
01566 rc = fsmStage(fsm, FSM_SYMLINK);
01567 fsm->opath = opath;
01568 } else if (S_ISFIFO(st->st_mode)) {
01569 mode_t st_mode = st->st_mode;
01570
01571 rc = fsmStage(fsm, FSM_VERIFY);
01572 if (rc == CPIOERR_LSTAT_FAILED) {
01573 st->st_mode = 0000;
01574 rc = fsmStage(fsm, FSM_MKFIFO);
01575 st->st_mode = st_mode;
01576 }
01577 } else if (S_ISCHR(st->st_mode) ||
01578 S_ISBLK(st->st_mode) ||
01579 S_ISSOCK(st->st_mode) )
01580 {
01581 rc = fsmStage(fsm, FSM_VERIFY);
01582 if (rc == CPIOERR_LSTAT_FAILED)
01583 rc = fsmStage(fsm, FSM_MKNOD);
01584 } else {
01585 rc = CPIOERR_UNKNOWN_FILETYPE;
01586 }
01587 if (!S_ISDIR(st->st_mode) && st->st_nlink > 1) {
01588 fsm->li->createdPath = fsm->li->linkIndex;
01589 rc = fsmMakeLinks(fsm);
01590 }
01591 break;
01592 case FSM_POST:
01593 break;
01594 case FSM_MKLINKS:
01595 rc = fsmMakeLinks(fsm);
01596 break;
01597 case FSM_NOTIFY:
01598 if (fsm->goal == FSM_PKGINSTALL || fsm->goal == FSM_PKGBUILD) {
01599 rpmTransactionSet ts = fsmGetTs(fsm);
01600 TFI_t fi = fsmGetFi(fsm);
01601 if (ts && ts->notify && fi)
01602 (void)ts->notify(fi->h, RPMCALLBACK_INST_PROGRESS,
01603 fdGetCpioPos(fsm->cfd), fi->archiveSize,
01604 (fi->ap ? fi->ap->key : NULL), ts->notifyData);
01605 }
01606 break;
01607 case FSM_UNDO:
01608 if (fsm->postpone)
01609 break;
01610 if (fsm->goal == FSM_PKGINSTALL) {
01611 (void) fsmStage(fsm,
01612 (S_ISDIR(st->st_mode) ? FSM_RMDIR : FSM_UNLINK));
01613
01614 #ifdef NOTYET
01615 if (fsm->dnlx)
01616 (void) fsmStage(fsm, FSM_RMDIRS);
01617 #endif
01618 errno = saveerrno;
01619 }
01620 if (fsm->failedFile && *fsm->failedFile == NULL)
01621 *fsm->failedFile = xstrdup(fsm->path);
01622 break;
01623 case FSM_FINI:
01624 if (!fsm->postpone && fsm->commit) {
01625 if (fsm->goal == FSM_PKGINSTALL)
01626 rc = ((!S_ISDIR(st->st_mode) && st->st_nlink > 1)
01627 ? fsmCommitLinks(fsm) : fsmStage(fsm, FSM_COMMIT));
01628 if (fsm->goal == FSM_PKGCOMMIT)
01629 rc = fsmStage(fsm, FSM_COMMIT);
01630 if (fsm->goal == FSM_PKGERASE)
01631 rc = fsmStage(fsm, FSM_COMMIT);
01632 }
01633 fsm->path = _free(fsm->path);
01634 fsm->opath = _free(fsm->opath);
01635 memset(st, 0, sizeof(*st));
01636 memset(ost, 0, sizeof(*ost));
01637 break;
01638 case FSM_COMMIT:
01639
01640 if (fsm->diskchecked && fsm->exists && fsm->osuffix) {
01641 const char * opath = fsm->opath;
01642 const char * path = fsm->path;
01643
01644 fsm->opath = fsmFsPath(fsm, st, NULL, NULL);
01645
01646
01647 fsm->path = fsmFsPath(fsm, st, NULL, fsm->osuffix);
01648
01649 rc = fsmStage(fsm, FSM_RENAME);
01650 if (!rc) {
01651 rpmMessage(RPMMESS_WARNING, _("%s saved as %s\n"),
01652 fsm->opath, fsm->path);
01653 }
01654 fsm->path = _free(fsm->path);
01655 fsm->path = path;
01656 fsm->opath = _free(fsm->opath);
01657 fsm->opath = opath;
01658 }
01659
01660
01661 if (fsm->goal == FSM_PKGERASE) {
01662 if (fsm->action == FA_ERASE) {
01663 TFI_t fi = fsmGetFi(fsm);
01664 if (S_ISDIR(st->st_mode)) {
01665 rc = fsmStage(fsm, FSM_RMDIR);
01666 if (!rc) break;
01667 switch (errno) {
01668 case ENOENT:
01669 case ENOTEMPTY:
01670
01671 if (fsm->fflags & RPMFILE_MISSINGOK)
01672 break;
01673
01674
01675 rpmError(
01676 (strict_erasures ? RPMERR_RMDIR : RPMDEBUG_RMDIR),
01677 _("%s rmdir of %s failed: Directory not empty\n"),
01678 fiTypeString(fi), fsm->path);
01679 break;
01680 default:
01681 rpmError(
01682 (strict_erasures ? RPMERR_RMDIR : RPMDEBUG_RMDIR),
01683 _("%s rmdir of %s failed: %s\n"),
01684 fiTypeString(fi), fsm->path, strerror(errno));
01685 break;
01686 }
01687 } else {
01688 rc = fsmStage(fsm, FSM_UNLINK);
01689 if (!rc) break;
01690 if (!(errno == ENOENT && (fsm->fflags & RPMFILE_MISSINGOK)))
01691 rpmError(
01692 (strict_erasures ? RPMERR_UNLINK : RPMDEBUG_UNLINK),
01693 _("%s unlink of %s failed: %s\n"),
01694 fiTypeString(fi), fsm->path, strerror(errno));
01695 }
01696 }
01697
01698 if (!strict_erasures) rc = 0;
01699 break;
01700 }
01701
01702 if (!S_ISSOCK(st->st_mode)) {
01703
01704 if (!S_ISDIR(st->st_mode) &&
01705 (fsm->subdir || fsm->suffix || fsm->nsuffix))
01706 {
01707 fsm->opath = fsm->path;
01708 fsm->path = fsmFsPath(fsm, st, NULL, fsm->nsuffix);
01709 rc = fsmStage(fsm, FSM_RENAME);
01710 if (!rc && fsm->nsuffix) {
01711 const char * opath = fsmFsPath(fsm, st, NULL, NULL);
01712 rpmMessage(RPMMESS_WARNING, _("%s created as %s\n"),
01713 (opath ? opath : ""), fsm->path);
01714 opath = _free(opath);
01715 }
01716 fsm->opath = _free(fsm->opath);
01717 }
01718 if (S_ISLNK(st->st_mode)) {
01719 if (!rc && !getuid())
01720 rc = fsmStage(fsm, FSM_LCHOWN);
01721 } else {
01722 if (!rc && !getuid())
01723 rc = fsmStage(fsm, FSM_CHOWN);
01724 if (!rc)
01725 rc = fsmStage(fsm, FSM_CHMOD);
01726 if (!rc) {
01727 time_t mtime = st->st_mtime;
01728 TFI_t fi = fsmGetFi(fsm);
01729 if (fi->fmtimes)
01730 st->st_mtime = fi->fmtimes[fsm->ix];
01731 rc = fsmStage(fsm, FSM_UTIME);
01732 st->st_mtime = mtime;
01733 }
01734 }
01735 }
01736
01737
01738 if (!rc) rc = fsmStage(fsm, FSM_NOTIFY);
01739 else if (fsm->failedFile && *fsm->failedFile == NULL) {
01740 *fsm->failedFile = fsm->path;
01741 fsm->path = NULL;
01742 }
01743 break;
01744 case FSM_DESTROY:
01745 fsm->path = _free(fsm->path);
01746
01747
01748 while ((fsm->li = fsm->links) != NULL) {
01749 fsm->links = fsm->li->next;
01750 fsm->li->next = NULL;
01751 if (fsm->goal == FSM_PKGINSTALL &&
01752 fsm->commit && fsm->li->linksLeft)
01753 {
01754 for (i = 0 ; i < fsm->li->linksLeft; i++) {
01755 if (fsm->li->filex[i] < 0) continue;
01756 rc = CPIOERR_MISSING_HARDLINK;
01757 if (fsm->failedFile && *fsm->failedFile == NULL) {
01758 fsm->ix = fsm->li->filex[i];
01759 if (!fsmStage(fsm, FSM_MAP)) {
01760 *fsm->failedFile = fsm->path;
01761 fsm->path = NULL;
01762 }
01763 }
01764 break;
01765 }
01766 }
01767 if (fsm->goal == FSM_PKGBUILD &&
01768 (fsm->mapFlags & CPIO_ALL_HARDLINKS))
01769 {
01770 rc = CPIOERR_MISSING_HARDLINK;
01771 }
01772 fsm->li = freeHardLink(fsm->li);
01773 }
01774 fsm->ldn = _free(fsm->ldn);
01775 fsm->ldnalloc = fsm->ldnlen = 0;
01776 fsm->rdbuf = fsm->rdb = _free(fsm->rdb);
01777 fsm->wrbuf = fsm->wrb = _free(fsm->wrb);
01778 break;
01779 case FSM_VERIFY:
01780 if (fsm->diskchecked && !fsm->exists) {
01781 rc = CPIOERR_LSTAT_FAILED;
01782 break;
01783 }
01784 if (S_ISREG(st->st_mode)) {
01785 char * path = alloca(strlen(fsm->path) + sizeof("-RPMDELETE"));
01786 (void) stpcpy( stpcpy(path, fsm->path), "-RPMDELETE");
01787
01788
01789
01790
01791 fsm->opath = fsm->path;
01792 fsm->path = path;
01793 rc = fsmStage(fsm, FSM_RENAME);
01794 if (!rc)
01795 (void) fsmStage(fsm, FSM_UNLINK);
01796 else
01797 rc = CPIOERR_UNLINK_FAILED;
01798 fsm->path = fsm->opath;
01799 fsm->opath = NULL;
01800 return (rc ? rc : CPIOERR_LSTAT_FAILED);
01801 break;
01802 } else if (S_ISDIR(st->st_mode)) {
01803 if (S_ISDIR(ost->st_mode)) return 0;
01804 if (S_ISLNK(ost->st_mode)) {
01805 rc = fsmStage(fsm, FSM_STAT);
01806 if (rc == CPIOERR_STAT_FAILED && errno == ENOENT) rc = 0;
01807 if (rc) break;
01808 errno = saveerrno;
01809 if (S_ISDIR(ost->st_mode)) return 0;
01810 }
01811 } else if (S_ISLNK(st->st_mode)) {
01812 if (S_ISLNK(ost->st_mode)) {
01813
01814 rc = fsmStage(fsm, FSM_READLINK);
01815 errno = saveerrno;
01816 if (rc) break;
01817 if (!strcmp(fsm->opath, fsm->rdbuf)) return 0;
01818 }
01819 } else if (S_ISFIFO(st->st_mode)) {
01820 if (S_ISFIFO(ost->st_mode)) return 0;
01821 } else if (S_ISCHR(st->st_mode) || S_ISBLK(st->st_mode)) {
01822 if ((S_ISCHR(ost->st_mode) || S_ISBLK(ost->st_mode)) &&
01823 (ost->st_rdev == st->st_rdev)) return 0;
01824 } else if (S_ISSOCK(st->st_mode)) {
01825 if (S_ISSOCK(ost->st_mode)) return 0;
01826 }
01827
01828 rc = 0;
01829 if (fsm->stage == FSM_PROCESS) rc = fsmStage(fsm, FSM_UNLINK);
01830 if (rc == 0) rc = CPIOERR_LSTAT_FAILED;
01831 return (rc ? rc : CPIOERR_LSTAT_FAILED);
01832 break;
01833
01834 case FSM_UNLINK:
01835 rc = Unlink(fsm->path);
01836 if (_fsm_debug && (stage & FSM_SYSCALL))
01837 rpmMessage(RPMMESS_DEBUG, " %8s (%s) %s\n", cur,
01838 fsm->path, (rc < 0 ? strerror(errno) : ""));
01839 if (rc < 0) rc = CPIOERR_UNLINK_FAILED;
01840 break;
01841 case FSM_RENAME:
01842 rc = Rename(fsm->opath, fsm->path);
01843 if (_fsm_debug && (stage & FSM_SYSCALL))
01844 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %s) %s\n", cur,
01845 fsm->opath, fsm->path, (rc < 0 ? strerror(errno) : ""));
01846 if (rc < 0) rc = CPIOERR_RENAME_FAILED;
01847 break;
01848 case FSM_MKDIR:
01849 rc = Mkdir(fsm->path, (st->st_mode & 07777));
01850 if (_fsm_debug && (stage & FSM_SYSCALL))
01851 rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0%04o) %s\n", cur,
01852 fsm->path, (unsigned)(st->st_mode & 07777),
01853 (rc < 0 ? strerror(errno) : ""));
01854 if (rc < 0) rc = CPIOERR_MKDIR_FAILED;
01855 break;
01856 case FSM_RMDIR:
01857 rc = Rmdir(fsm->path);
01858 if (_fsm_debug && (stage & FSM_SYSCALL))
01859 rpmMessage(RPMMESS_DEBUG, " %8s (%s) %s\n", cur,
01860 fsm->path, (rc < 0 ? strerror(errno) : ""));
01861 if (rc < 0) rc = CPIOERR_RMDIR_FAILED;
01862 break;
01863 case FSM_CHOWN:
01864 rc = chown(fsm->path, st->st_uid, st->st_gid);
01865 if (_fsm_debug && (stage & FSM_SYSCALL))
01866 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %d, %d) %s\n", cur,
01867 fsm->path, (int)st->st_uid, (int)st->st_gid,
01868 (rc < 0 ? strerror(errno) : ""));
01869 if (rc < 0) rc = CPIOERR_CHOWN_FAILED;
01870 break;
01871 case FSM_LCHOWN:
01872 #if ! CHOWN_FOLLOWS_SYMLINK
01873 rc = lchown(fsm->path, st->st_uid, st->st_gid);
01874 if (_fsm_debug && (stage & FSM_SYSCALL))
01875 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %d, %d) %s\n", cur,
01876 fsm->path, (int)st->st_uid, (int)st->st_gid,
01877 (rc < 0 ? strerror(errno) : ""));
01878 if (rc < 0) rc = CPIOERR_CHOWN_FAILED;
01879 #endif
01880 break;
01881 case FSM_CHMOD:
01882 rc = chmod(fsm->path, (st->st_mode & 07777));
01883 if (_fsm_debug && (stage & FSM_SYSCALL))
01884 rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0%04o) %s\n", cur,
01885 fsm->path, (unsigned)(st->st_mode & 07777),
01886 (rc < 0 ? strerror(errno) : ""));
01887 if (rc < 0) rc = CPIOERR_CHMOD_FAILED;
01888 break;
01889 case FSM_UTIME:
01890 { struct utimbuf stamp;
01891 stamp.actime = st->st_mtime;
01892 stamp.modtime = st->st_mtime;
01893 rc = utime(fsm->path, &stamp);
01894 if (_fsm_debug && (stage & FSM_SYSCALL))
01895 rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0x%x) %s\n", cur,
01896 fsm->path, (unsigned)st->st_mtime,
01897 (rc < 0 ? strerror(errno) : ""));
01898 if (rc < 0) rc = CPIOERR_UTIME_FAILED;
01899 }
01900 break;
01901 case FSM_SYMLINK:
01902 rc = symlink(fsm->opath, fsm->path);
01903 if (_fsm_debug && (stage & FSM_SYSCALL))
01904 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %s) %s\n", cur,
01905 fsm->opath, fsm->path, (rc < 0 ? strerror(errno) : ""));
01906 if (rc < 0) rc = CPIOERR_SYMLINK_FAILED;
01907 break;
01908 case FSM_LINK:
01909 rc = Link(fsm->opath, fsm->path);
01910 if (_fsm_debug && (stage & FSM_SYSCALL))
01911 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %s) %s\n", cur,
01912 fsm->opath, fsm->path, (rc < 0 ? strerror(errno) : ""));
01913 if (rc < 0) rc = CPIOERR_LINK_FAILED;
01914 break;
01915 case FSM_MKFIFO:
01916 rc = mkfifo(fsm->path, (st->st_mode & 07777));
01917 if (_fsm_debug && (stage & FSM_SYSCALL))
01918 rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0%04o) %s\n", cur,
01919 fsm->path, (unsigned)(st->st_mode & 07777),
01920 (rc < 0 ? strerror(errno) : ""));
01921 if (rc < 0) rc = CPIOERR_MKFIFO_FAILED;
01922 break;
01923 case FSM_MKNOD:
01924
01925 rc = mknod(fsm->path, (st->st_mode & ~07777), st->st_rdev);
01926
01927 if (_fsm_debug && (stage & FSM_SYSCALL))
01928 rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0%o, 0x%x) %s\n", cur,
01929 fsm->path, (unsigned)(st->st_mode & ~07777),
01930 (unsigned)st->st_rdev,
01931 (rc < 0 ? strerror(errno) : ""));
01932 if (rc < 0) rc = CPIOERR_MKNOD_FAILED;
01933 break;
01934 case FSM_LSTAT:
01935 rc = Lstat(fsm->path, ost);
01936 if (_fsm_debug && (stage & FSM_SYSCALL) && rc && errno != ENOENT)
01937 rpmMessage(RPMMESS_DEBUG, " %8s (%s, ost) %s\n", cur,
01938 fsm->path, (rc < 0 ? strerror(errno) : ""));
01939 if (rc < 0) rc = CPIOERR_LSTAT_FAILED;
01940 break;
01941 case FSM_STAT:
01942 rc = Stat(fsm->path, ost);
01943 if (_fsm_debug && (stage & FSM_SYSCALL) && rc && errno != ENOENT)
01944 rpmMessage(RPMMESS_DEBUG, " %8s (%s, ost) %s\n", cur,
01945 fsm->path, (rc < 0 ? strerror(errno) : ""));
01946 if (rc < 0) rc = CPIOERR_STAT_FAILED;
01947 break;
01948 case FSM_READLINK:
01949
01950 rc = Readlink(fsm->path, fsm->rdbuf, fsm->rdsize - 1);
01951 if (_fsm_debug && (stage & FSM_SYSCALL))
01952 rpmMessage(RPMMESS_DEBUG, " %8s (%s, rdbuf, %d) %s\n", cur,
01953 fsm->path, (int)(fsm->rdsize -1), (rc < 0 ? strerror(errno) : ""));
01954 if (rc < 0) rc = CPIOERR_READLINK_FAILED;
01955 else {
01956 fsm->rdnb = rc;
01957 fsm->rdbuf[fsm->rdnb] = '\0';
01958 rc = 0;
01959 }
01960 break;
01961 case FSM_CHROOT:
01962 break;
01963
01964 case FSM_NEXT:
01965 rc = fsmStage(fsm, FSM_HREAD);
01966 if (rc) break;
01967 if (!strcmp(fsm->path, CPIO_TRAILER)) {
01968 fsm->path = _free(fsm->path);
01969 rc = CPIOERR_HDR_TRAILER;
01970 }
01971 if (!rc)
01972 rc = fsmStage(fsm, FSM_POS);
01973 break;
01974 case FSM_EAT:
01975 for (left = st->st_size; left > 0; left -= fsm->rdnb) {
01976 fsm->wrlen = (left > fsm->wrsize ? fsm->wrsize : left);
01977 rc = fsmStage(fsm, FSM_DREAD);
01978 if (rc)
01979 break;
01980 }
01981 break;
01982 case FSM_POS:
01983 left = (modulo - (fdGetCpioPos(fsm->cfd) % modulo)) % modulo;
01984 if (left) {
01985 fsm->wrlen = left;
01986 (void) fsmStage(fsm, FSM_DREAD);
01987 }
01988 break;
01989 case FSM_PAD:
01990 left = (modulo - (fdGetCpioPos(fsm->cfd) % modulo)) % modulo;
01991 if (left) {
01992 memset(fsm->rdbuf, 0, left);
01993
01994 fsm->rdnb = left;
01995 (void) fsmStage(fsm, FSM_DWRITE);
01996 }
01997 break;
01998 case FSM_TRAILER:
01999 rc = cpioTrailerWrite(fsm);
02000 break;
02001 case FSM_HREAD:
02002 rc = fsmStage(fsm, FSM_POS);
02003 if (!rc)
02004 rc = cpioHeaderRead(fsm, st);
02005 break;
02006 case FSM_HWRITE:
02007 rc = cpioHeaderWrite(fsm, st);
02008 break;
02009 case FSM_DREAD:
02010 fsm->rdnb = Fread(fsm->wrbuf, sizeof(*fsm->wrbuf), fsm->wrlen, fsm->cfd);
02011 if (_fsm_debug && (stage & FSM_SYSCALL))
02012 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %d, cfd)\trdnb %d\n",
02013 cur, (fsm->wrbuf == fsm->wrb ? "wrbuf" : "mmap"),
02014 (int)fsm->wrlen, (int)fsm->rdnb);
02015 if (fsm->rdnb != fsm->wrlen || Ferror(fsm->cfd))
02016 rc = CPIOERR_READ_FAILED;
02017 if (fsm->rdnb > 0)
02018 fdSetCpioPos(fsm->cfd, fdGetCpioPos(fsm->cfd) + fsm->rdnb);
02019 break;
02020 case FSM_DWRITE:
02021 fsm->wrnb = Fwrite(fsm->rdbuf, sizeof(*fsm->rdbuf), fsm->rdnb, fsm->cfd);
02022 if (_fsm_debug && (stage & FSM_SYSCALL))
02023 rpmMessage(RPMMESS_DEBUG, " %8s (%s, %d, cfd)\twrnb %d\n",
02024 cur, (fsm->rdbuf == fsm->rdb ? "rdbuf" : "mmap"),
02025 (int)fsm->rdnb, (int)fsm->wrnb);
02026 if (fsm->rdnb != fsm->wrnb || Ferror(fsm->cfd))
02027 rc = CPIOERR_WRITE_FAILED;
02028 if (fsm->wrnb > 0)
02029 fdSetCpioPos(fsm->cfd, fdGetCpioPos(fsm->cfd) + fsm->wrnb);
02030 break;
02031
02032 case FSM_ROPEN:
02033 fsm->rfd = Fopen(fsm->path, "r.ufdio");
02034 if (fsm->rfd == NULL || Ferror(fsm->rfd)) {
02035 if (fsm->rfd) (void) fsmStage(fsm, FSM_RCLOSE);
02036 fsm->rfd = NULL;
02037 rc = CPIOERR_OPEN_FAILED;
02038 break;
02039 }
02040 if (_fsm_debug && (stage & FSM_SYSCALL))
02041 rpmMessage(RPMMESS_DEBUG, " %8s (%s, \"r\") rfd %p rdbuf %p\n", cur,
02042 fsm->path, fsm->rfd, fsm->rdbuf);
02043 break;
02044 case FSM_READ:
02045 fsm->rdnb = Fread(fsm->rdbuf, sizeof(*fsm->rdbuf), fsm->rdlen, fsm->rfd);
02046 if (_fsm_debug && (stage & FSM_SYSCALL))
02047 rpmMessage(RPMMESS_DEBUG, " %8s (rdbuf, %d, rfd)\trdnb %d\n",
02048 cur, (int)fsm->rdlen, (int)fsm->rdnb);
02049 if (fsm->rdnb != fsm->rdlen || Ferror(fsm->rfd))
02050 rc = CPIOERR_READ_FAILED;
02051 break;
02052 case FSM_RCLOSE:
02053 if (fsm->rfd) {
02054 if (_fsm_debug && (stage & FSM_SYSCALL))
02055 rpmMessage(RPMMESS_DEBUG, " %8s (%p)\n", cur, fsm->rfd);
02056 (void) Fclose(fsm->rfd);
02057 errno = saveerrno;
02058 }
02059 fsm->rfd = NULL;
02060 break;
02061 case FSM_WOPEN:
02062 fsm->wfd = Fopen(fsm->path, "w.ufdio");
02063 if (fsm->wfd == NULL || Ferror(fsm->wfd)) {
02064 if (fsm->wfd) (void) fsmStage(fsm, FSM_WCLOSE);
02065 fsm->wfd = NULL;
02066 rc = CPIOERR_OPEN_FAILED;
02067 }
02068 if (_fsm_debug && (stage & FSM_SYSCALL))
02069 rpmMessage(RPMMESS_DEBUG, " %8s (%s, \"w\") wfd %p wrbuf %p\n", cur,
02070 fsm->path, fsm->wfd, fsm->wrbuf);
02071 break;
02072 case FSM_WRITE:
02073 fsm->wrnb = Fwrite(fsm->wrbuf, sizeof(*fsm->wrbuf), fsm->rdnb, fsm->wfd);
02074 if (_fsm_debug && (stage & FSM_SYSCALL))
02075 rpmMessage(RPMMESS_DEBUG, " %8s (wrbuf, %d, wfd)\twrnb %d\n",
02076 cur, (int)fsm->rdnb, (int)fsm->wrnb);
02077 if (fsm->rdnb != fsm->wrnb || Ferror(fsm->wfd))
02078 rc = CPIOERR_WRITE_FAILED;
02079 break;
02080 case FSM_WCLOSE:
02081 if (fsm->wfd) {
02082 if (_fsm_debug && (stage & FSM_SYSCALL))
02083 rpmMessage(RPMMESS_DEBUG, " %8s (%p)\n", cur, fsm->wfd);
02084 (void) Fclose(fsm->wfd);
02085 errno = saveerrno;
02086 }
02087 fsm->wfd = NULL;
02088 break;
02089
02090 default:
02091 break;
02092 }
02093
02094 if (!(stage & FSM_INTERNAL)) {
02095 fsm->rc = (rc == CPIOERR_HDR_TRAILER ? 0 : rc);
02096 }
02097 return rc;
02098 }
02099
02100
02101 const char *const fileActionString(fileAction a)
02102 {
02103 switch (a) {
02104 case FA_UNKNOWN: return "unknown";
02105 case FA_CREATE: return "create";
02106 case FA_COPYOUT: return "copyout";
02107 case FA_COPYIN: return "copyin";
02108 case FA_BACKUP: return "backup";
02109 case FA_SAVE: return "save";
02110 case FA_SKIP: return "skip";
02111 case FA_ALTNAME: return "altname";
02112 case FA_ERASE: return "erase";
02113 case FA_SKIPNSTATE: return "skipnstate";
02114 case FA_SKIPNETSHARED: return "skipnetshared";
02115 case FA_SKIPMULTILIB: return "skipmultilib";
02116 default: return "???";
02117 }
02118
02119 }
02120
02121 const char *const fileStageString(fileStage a) {
02122 switch(a) {
02123 case FSM_UNKNOWN: return "unknown";
02124
02125 case FSM_PKGINSTALL:return "pkginstall";
02126 case FSM_PKGERASE: return "pkgerase";
02127 case FSM_PKGBUILD: return "pkgbuild";
02128 case FSM_PKGCOMMIT: return "pkgcommit";
02129 case FSM_PKGUNDO: return "pkgundo";
02130
02131 case FSM_CREATE: return "create";
02132 case FSM_INIT: return "init";
02133 case FSM_MAP: return "map";
02134 case FSM_MKDIRS: return "mkdirs";
02135 case FSM_RMDIRS: return "rmdirs";
02136 case FSM_PRE: return "pre";
02137 case FSM_PROCESS: return "process";
02138 case FSM_POST: return "post";
02139 case FSM_MKLINKS: return "mklinks";
02140 case FSM_NOTIFY: return "notify";
02141 case FSM_UNDO: return "undo";
02142 case FSM_FINI: return "fini";
02143 case FSM_COMMIT: return "commit";
02144 case FSM_DESTROY: return "destroy";
02145 case FSM_VERIFY: return "verify";
02146
02147 case FSM_UNLINK: return "Unlink";
02148 case FSM_RENAME: return "Rename";
02149 case FSM_MKDIR: return "Mkdir";
02150 case FSM_RMDIR: return "rmdir";
02151 case FSM_CHOWN: return "chown";
02152 case FSM_LCHOWN: return "lchown";
02153 case FSM_CHMOD: return "chmod";
02154 case FSM_UTIME: return "utime";
02155 case FSM_SYMLINK: return "symlink";
02156 case FSM_LINK: return "Link";
02157 case FSM_MKFIFO: return "mkfifo";
02158 case FSM_MKNOD: return "mknod";
02159 case FSM_LSTAT: return "Lstat";
02160 case FSM_STAT: return "Stat";
02161 case FSM_READLINK: return "Readlink";
02162 case FSM_CHROOT: return "chroot";
02163
02164 case FSM_NEXT: return "next";
02165 case FSM_EAT: return "eat";
02166 case FSM_POS: return "pos";
02167 case FSM_PAD: return "pad";
02168 case FSM_TRAILER: return "trailer";
02169 case FSM_HREAD: return "hread";
02170 case FSM_HWRITE: return "hwrite";
02171 case FSM_DREAD: return "Fread";
02172 case FSM_DWRITE: return "Fwrite";
02173
02174 case FSM_ROPEN: return "Fopen";
02175 case FSM_READ: return "Fread";
02176 case FSM_RCLOSE: return "Fclose";
02177 case FSM_WOPEN: return "Fopen";
02178 case FSM_WRITE: return "Fwrite";
02179 case FSM_WCLOSE: return "Fclose";
02180
02181 default: return "???";
02182 }
02183
02184 }