From acbbbb19f712e0fc00976e45247c5a5608a59fd8 Mon Sep 17 00:00:00 2001 From: jbj Date: Sat, 3 Mar 2001 20:41:37 +0000 Subject: [PATCH] Move fileActionString to fsm.c where it belongs. Open repackage output fd in PSM_INIT, not PSM_PROCESS. Factor common chroot calls to beginning of PSM_PRE and end of PSM_POST. Factor common rpmdbCountPackages to top of PSM_INIT. CVS patchset: 4602 CVS date: 2001/03/03 20:41:37 --- lib/fsm.c | 20 ++++++++++ lib/fsm.h | 7 ++++ lib/psm.c | 123 +++++++++++++++++++++++++++---------------------------------- lib/psm.h | 10 +---- po/rpm.pot | 36 +++++++++--------- 5 files changed, 102 insertions(+), 94 deletions(-) diff --git a/lib/fsm.c b/lib/fsm.c index 0fd18e4..3e38965 100644 --- a/lib/fsm.c +++ b/lib/fsm.c @@ -1905,6 +1905,26 @@ if (fsm->rdnb != fsm->wrnb) fprintf(stderr, "*** short write: had %d, got %d\n", return rc; } +/*@obserever@*/ const char *const fileActionString(fileAction a) +{ + switch (a) { + case FA_UNKNOWN: return "unknown"; + case FA_CREATE: return "create"; + case FA_COPYOUT: return "copyout"; + case FA_COPYIN: return "copyin"; + case FA_BACKUP: return "backup"; + case FA_SAVE: return "save"; + case FA_SKIP: return "skip"; + case FA_ALTNAME: return "altname"; + case FA_ERASE: return "erase"; + case FA_SKIPNSTATE: return "skipnstate"; + case FA_SKIPNETSHARED: return "skipnetshared"; + case FA_SKIPMULTILIB: return "skipmultilib"; + default: return "???"; + } + /*@notreached@*/ +} + /*@observer@*/ const char *const fileStageString(fileStage a) { switch(a) { case FSM_UNKNOWN: return "unknown"; diff --git a/lib/fsm.h b/lib/fsm.h index 85c0d2d..e8e1b0f 100644 --- a/lib/fsm.h +++ b/lib/fsm.h @@ -173,6 +173,13 @@ extern "C" { /*@observer@*/ const char *const fileStageString(fileStage a); /** + * Return formatted string representation of file disposition. + * @param a file dispostion + * @return formatted string + */ +/*@observer@*/ const char *const fileActionString(fileAction a); + +/** * Create file state machine instance. * @return file state machine data */ diff --git a/lib/psm.c b/lib/psm.c index 91fa6a8..2d9cb17 100644 --- a/lib/psm.c +++ b/lib/psm.c @@ -192,26 +192,6 @@ void freeFi(TFI_t fi) /*@noteached@*/ } -/*@obserever@*/ const char *const fileActionString(fileAction a) -{ - switch (a) { - case FA_UNKNOWN: return "unknown"; - case FA_CREATE: return "create"; - case FA_COPYOUT: return "copyout"; - case FA_COPYIN: return "copyin"; - case FA_BACKUP: return "backup"; - case FA_SAVE: return "save"; - case FA_SKIP: return "skip"; - case FA_ALTNAME: return "altname"; - case FA_ERASE: return "erase"; - case FA_SKIPNSTATE: return "skipnstate"; - case FA_SKIPNETSHARED: return "skipnetshared"; - case FA_SKIPMULTILIB: return "skipmultilib"; - default: return "???"; - } - /*@notreached@*/ -} - /** * Macros to be defined from per-header tag values. * @todo Should other macros be added from header when installing a package? @@ -1011,14 +991,14 @@ static int runScript(PSM_t psm, Header h, if (waitpid(child, &status, 0) < 0) { rpmError(RPMERR_SCRIPT, - _("execution of %s scriptlet from %s-%s-%s failed, waitpid returned %s\n"), + _("execution of %s scriptlet from %s-%s-%s failed, waitpid returned %s\n"), sln, n, v, r, strerror (errno)); /* XXX what to do here? */ rc = RPMRC_OK; } else { if (!WIFEXITED(status) || WEXITSTATUS(status)) { rpmError(RPMERR_SCRIPT, - _("execution of %s scriptlet from %s-%s-%s failed, exit status %d\n"), + _("execution of %s scriptlet from %s-%s-%s failed, exit status %d\n"), sln, n, v, r, WEXITSTATUS(status)); rc = RPMRC_FAIL; } @@ -1043,7 +1023,6 @@ static int runScript(PSM_t psm, Header h, */ static rpmRC runInstScript(PSM_t psm) { - const rpmTransactionSet ts = psm->ts; TFI_t fi = psm->fi; HGE_t hge = fi->hge; HFD_t hfd = fi->hfd; @@ -1054,9 +1033,6 @@ static rpmRC runInstScript(PSM_t psm) const char * script; rpmRC rc = RPMRC_OK; - if (ts->transFlags & RPMTRANS_FLAG_NOSCRIPTS) - return rc; - /* * headerGetEntry() sets the data pointer to NULL if the entry does * not exist. @@ -1073,6 +1049,7 @@ static rpmRC runInstScript(PSM_t psm) rc = runScript(psm, fi->h, tag2sln(psm->scriptTag), programArgc, argv, script, psm->scriptArg, -1); + programArgv = hfd(programArgv, ptt); script = hfd(script, stt); return rc; @@ -1329,17 +1306,19 @@ int psmStage(PSM_t psm, pkgStage stage) psm->stepName, fi->name, fi->version, fi->release, fi->fc, (ts->transFlags & RPMTRANS_FLAG_TEST)); + /* + * When we run scripts, we pass an argument which is the number of + * versions of this package that will be installed when we are + * finished. + */ + psm->npkgs_installed = rpmdbCountPackages(ts->rpmdb, fi->name); + if (psm->npkgs_installed < 0) { + rc = RPMRC_FAIL; + break; + } + if (psm->goal == PSM_PKGINSTALL) { - /* - * When we run scripts, we pass an argument which is the number of - * versions of this package that will be installed when we are - * finished. - */ - psm->scriptArg = rpmdbCountPackages(ts->rpmdb, fi->name) + 1; - if (psm->scriptArg < 1) { - rc = RPMRC_FAIL; - break; - } + psm->scriptArg = psm->npkgs_installed + 1; assert(psm->mi == NULL); psm->mi = rpmdbInitIterator(ts->rpmdb, RPMTAG_NAME, fi->name, 0); @@ -1393,29 +1372,42 @@ assert(psm->mi == NULL); rc = RPMRC_OK; } if (psm->goal == PSM_PKGERASE) { - /* - * When we run scripts, we pass an argument which is the number of - * versions of this package that will be installed when we are - * finished. - */ - psm->scriptArg = rpmdbCountPackages(ts->rpmdb, fi->name) - 1; - if (psm->scriptArg < 0) { - rc = RPMRC_FAIL; - break; - } + psm->scriptArg = psm->npkgs_installed - 1; /* Retrieve installed header. */ rc = psmStage(psm, PSM_RPMDB_LOAD); - if (rc) break; } if (psm->goal == PSM_PKGSAVE) { + psm->scriptArg = psm->npkgs_installed - 1; + /* Retrieve installed header. */ rc = psmStage(psm, PSM_RPMDB_LOAD); + + /* Open output package for writing. */ + { const char * bfmt = rpmGetPath("%{_repackage_name_fmt}", NULL); + const char * pkgbn = + headerSprintf(fi->h, bfmt, rpmTagTable, rpmHeaderFormats, NULL); + + bfmt = _free(bfmt); + psm->pkgURL = rpmGenPath("%{?_repackage_root:%{_repackage_root}}", + "%{?_repackage_dir:%{_repackage_dir}}", + pkgbn); + pkgbn = _free(pkgbn); + (void) urlPath(psm->pkgURL, &psm->pkgfn); + psm->fd = Fopen(psm->pkgfn, "w.ufdio"); + if (psm->fd == NULL || Ferror(psm->fd)) { + rc = RPMRC_FAIL; + break; + } + } } break; case PSM_PRE: if (ts->transFlags & RPMTRANS_FLAG_TEST) break; + /* Change root directory if requested and not already done. */ + rc = psmStage(psm, PSM_CHROOT_IN); + if (psm->goal == PSM_PKGINSTALL) { psm->scriptTag = RPMTAG_PREIN; psm->progTag = RPMTAG_PREINPROG; @@ -1428,8 +1420,10 @@ assert(psm->mi == NULL); break; } +#ifdef DYING /* Change root directory if requested and not already done. */ (void) psmStage(psm, PSM_CHROOT_IN); +#endif } if (psm->goal == PSM_PKGERASE) { psm->scriptTag = RPMTAG_PREUN; @@ -1437,9 +1431,11 @@ assert(psm->mi == NULL); psm->sense = RPMSENSE_TRIGGERUN; psm->countCorrection = -1; +#ifdef DYING /* Change root directory if requested and not already done. */ rc = psmStage(psm, PSM_CHROOT_IN); if (rc) break; +#endif rc = psmStage(psm, PSM_TRIGGERS); if (rc) break; @@ -1462,24 +1458,6 @@ assert(psm->mi == NULL); } } - /* Open output package for writing. */ - { const char * bfmt = rpmGetPath("%{_repackage_name_fmt}", NULL); - const char * pkgbn = - headerSprintf(fi->h, bfmt, rpmTagTable, rpmHeaderFormats, NULL); - - bfmt = _free(bfmt); - psm->pkgURL = rpmGenPath("%{?_repackage_root:%{_repackage_root}}", - "%{?_repackage_dir:%{_repackage_dir}}", - pkgbn); - pkgbn = _free(pkgbn); - (void) urlPath(psm->pkgURL, &psm->pkgfn); - psm->fd = Fopen(psm->pkgfn, "w.ufdio"); - if (psm->fd == NULL || Ferror(psm->fd)) { - rc = RPMRC_FAIL; - break; - } - } - /* Retrieve type of payload compression. */ rc = psmStage(psm, PSM_RPMIO_FLAGS); @@ -1527,12 +1505,15 @@ assert(psm->mi == NULL); rc = headerWrite(psm->fd, psm->oh, HEADER_MAGIC_YES); if (rc) break; +#ifdef DYING /* Change root directory if requested and not already done. */ rc = psmStage(psm, PSM_CHROOT_IN); +#endif } break; case PSM_PROCESS: if (ts->transFlags & RPMTRANS_FLAG_TEST) break; + if (psm->goal == PSM_PKGINSTALL) { struct availablePackage * alp = fi->ap; @@ -1618,11 +1599,14 @@ assert(psm->mi == NULL); break; case PSM_POST: if (ts->transFlags & RPMTRANS_FLAG_TEST) break; + if (psm->goal == PSM_PKGINSTALL) { int_32 installTime = time(NULL); +#ifdef DYING /* Restore root directory if changed. */ (void) psmStage(psm, PSM_CHROOT_OUT); +#endif if (fi->fc > 0 && fi->fstates) headerAddEntry(fi->h, RPMTAG_FILESTATES, RPM_CHAR_TYPE, @@ -1690,10 +1674,16 @@ assert(psm->mi == NULL); } if (psm->goal == PSM_PKGSAVE) { } + + /* Restore root directory if changed. */ + (void) psmStage(psm, PSM_CHROOT_OUT); break; case PSM_UNDO: break; case PSM_FINI: + /* Restore root directory if changed. */ + (void) psmStage(psm, PSM_CHROOT_OUT); + if (psm->fd) { saveerrno = errno; /* XXX FIXME: Fclose with libio destroys errno */ Fclose(psm->fd); @@ -1706,9 +1696,6 @@ assert(psm->mi == NULL); rpmMessage(RPMMESS_VERBOSE, _("Wrote: %s\n"), psm->pkgURL); } - /* Restore root directory if changed. */ - (void) psmStage(psm, PSM_CHROOT_OUT); - if (fi->h && (psm->goal == PSM_PKGERASE || psm->goal == PSM_PKGSAVE)) { headerFree(fi->h); fi->h = NULL; diff --git a/lib/psm.h b/lib/psm.h index e0c1735..27add31 100644 --- a/lib/psm.h +++ b/lib/psm.h @@ -148,7 +148,8 @@ struct psm_s { /*@dependent@*/ const char * pkgfn; /*!< Repackage file name. */ int scriptTag; /*!< Scriptlet data tag. */ int progTag; /*!< Scriptlet interpreter tag. */ - int scriptArg; /*!< No. of installed instances. */ + int npkgs_installed; /*!< No. of installed instances. */ + int scriptArg; /*!< Scriptlet package arg. */ int sense; /*!< One of RPMSENSE_TRIGGER{IN,UN,POSTUN}. */ int countCorrection; /*!< 0 if installing, -1 if removing. */ int chrootDone; /*!< Was chroot(2) done by pkgStage? */ @@ -184,13 +185,6 @@ void freeFi(TFI_t fi) /*@observer@*/ const char *const fiTypeString(TFI_t fi); /** - * Return formatted string representation of file disposition. - * @param a file dispostion - * @return formatted string - */ -/*@observer@*/ const char *const fileActionString(fileAction a); - -/** * Package state machine driver. * @param psm package state machine data * @param stage next stage diff --git a/po/rpm.pot b/po/rpm.pot index 5e1a921..4df4a05 100644 --- a/po/rpm.pot +++ b/po/rpm.pot @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2001-03-02 14:26-0500\n" +"POT-Creation-Date: 2001-03-03 15:26-0500\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -1808,7 +1808,7 @@ msgstr "" msgid "Could not open %s: %s\n" msgstr "" -#: build/pack.c:484 lib/psm.c:1512 +#: build/pack.c:484 lib/psm.c:1490 #, c-format msgid "Unable to write package: %s\n" msgstr "" @@ -1838,7 +1838,7 @@ msgstr "" msgid "Unable to write payload to %s: %s\n" msgstr "" -#: build/pack.c:566 lib/psm.c:1706 +#: build/pack.c:566 lib/psm.c:1696 #, c-format msgid "Wrote: %s\n" msgstr "" @@ -2511,7 +2511,7 @@ msgstr "" msgid "dataLength() RPM_STRING_TYPE count must be 1.\n" msgstr "" -#: lib/header.c:207 lib/header.c:1081 lib/psm.c:390 +#: lib/header.c:207 lib/header.c:1081 lib/psm.c:370 #, c-format msgid "Data type %d not supported\n" msgstr "" @@ -2879,68 +2879,68 @@ msgstr "" msgid "unknown error %d encountered while manipulating package %s" msgstr "" -#: lib/psm.c:278 +#: lib/psm.c:258 #, c-format msgid "user %s does not exist - using root\n" msgstr "" -#: lib/psm.c:286 +#: lib/psm.c:266 #, c-format msgid "group %s does not exist - using root\n" msgstr "" -#: lib/psm.c:577 +#: lib/psm.c:557 #, c-format msgid "cannot create %s %s\n" msgstr "" -#: lib/psm.c:583 +#: lib/psm.c:563 #, c-format msgid "cannot write to %s\n" msgstr "" -#: lib/psm.c:605 +#: lib/psm.c:585 msgid "installing a source package\n" msgstr "" -#: lib/psm.c:655 +#: lib/psm.c:635 msgid "source package contains no .spec file\n" msgstr "" -#: lib/psm.c:744 +#: lib/psm.c:724 msgid "source package expected, binary found\n" msgstr "" -#: lib/psm.c:1014 +#: lib/psm.c:994 #, c-format msgid "execution of %s scriptlet from %s-%s-%s failed, waitpid returned %s\n" msgstr "" -#: lib/psm.c:1021 +#: lib/psm.c:1001 #, c-format msgid "execution of %s scriptlet from %s-%s-%s failed, exit status %d\n" msgstr "" -#: lib/psm.c:1328 +#: lib/psm.c:1305 #, c-format msgid "%s: %s-%s-%s has %d files, test = %d\n" msgstr "" -#: lib/psm.c:1425 +#: lib/psm.c:1417 #, c-format msgid "%s: %s scriptlet failed (%d), skipping %s-%s-%s\n" msgstr "" -#: lib/psm.c:1563 +#: lib/psm.c:1544 #, c-format msgid "unpacking of archive failed%s%s: %s\n" msgstr "" -#: lib/psm.c:1564 +#: lib/psm.c:1545 msgid " on file " msgstr "" -#: lib/psm.c:1796 +#: lib/psm.c:1783 #, c-format msgid "%s: running %s script(s) (if any)\n" msgstr "" -- 2.7.4