diff options
author | jbj <devnull@localhost> | 2002-08-04 16:55:55 +0000 |
---|---|---|
committer | jbj <devnull@localhost> | 2002-08-04 16:55:55 +0000 |
commit | de0ff3b553d9f1b44c73b378637544ed6092df1e (patch) | |
tree | 35e9ff8f95719cfa257184adba816e1b65c3ea53 /lib | |
parent | 00375ca2bf6017f6fb652558776fb588e9df142f (diff) | |
download | rpm-de0ff3b553d9f1b44c73b378637544ed6092df1e.tar.gz rpm-de0ff3b553d9f1b44c73b378637544ed6092df1e.tar.bz2 rpm-de0ff3b553d9f1b44c73b378637544ed6092df1e.zip |
- resurrect --rollback.
- renumber the callback types to be an orthogonal bit mask.
- provide repackage progress callbacks, compression is slow.
CVS patchset: 5597
CVS date: 2002/08/04 16:55:55
Diffstat (limited to 'lib')
-rw-r--r-- | lib/fsm.c | 24 | ||||
-rw-r--r-- | lib/psm.c | 20 | ||||
-rw-r--r-- | lib/rpmcli.h | 21 | ||||
-rw-r--r-- | lib/rpmfi.c | 1 | ||||
-rw-r--r-- | lib/rpmfi.h | 1 | ||||
-rw-r--r-- | lib/rpminstall.c | 173 | ||||
-rw-r--r-- | lib/transaction.c | 20 |
7 files changed, 185 insertions, 75 deletions
@@ -524,10 +524,11 @@ int fsmSetup(FSM_t fsm, fileStage goal, } fsm->iter = mapInitIterator(ts, fi); - if (fsm->goal == FSM_PKGINSTALL) { + if (fsm->goal == FSM_PKGINSTALL || fsm->goal == FSM_PKGBUILD) { void * ptr; + fi->archivePos = 0; ptr = rpmtsNotify(ts, fi->te, - RPMCALLBACK_INST_START, 0, fi->archiveSize); + RPMCALLBACK_INST_START, fi->archivePos, fi->archiveSize); } /*@-boundswrite@*/ @@ -808,7 +809,6 @@ static int writeFile(/*@special@*/ FSM_t fsm, int writeData) const char * opath = fsm->opath; struct stat * st = &fsm->sb; struct stat * ost = &fsm->osb; - size_t pos = fdGetCpioPos(fsm->cfd); char * symbuf = NULL; int left; int xx; @@ -923,13 +923,6 @@ static int writeFile(/*@special@*/ FSM_t fsm, int writeData) rc = fsmStage(fsm, FSM_PAD); if (rc) goto exit; - { const rpmts ts = fsmGetTs(fsm); - rpmfi fi = fsmGetFi(fsm); - size_t size = (fdGetCpioPos(fsm->cfd) - pos); - void * ptr; - ptr = rpmtsNotify(ts, fi->te, RPMCALLBACK_INST_PROGRESS, size, size); - } - rc = 0; exit: @@ -1430,6 +1423,9 @@ int fsmStage(FSM_t fsm, fileStage stage) /*@loopbreak@*/ break; } + /* Notify on success. */ + (void) fsmStage(fsm, FSM_NOTIFY); + if (fsmStage(fsm, FSM_FINI)) /*@loopbreak@*/ break; } @@ -1741,8 +1737,12 @@ if (!(fsm->mapFlags & CPIO_ALL_HARDLINKS)) break; rpmts ts = fsmGetTs(fsm); rpmfi fi = fsmGetFi(fsm); void * ptr; - ptr = rpmtsNotify(ts, fi->te, RPMCALLBACK_INST_PROGRESS, - fdGetCpioPos(fsm->cfd), fi->archiveSize); + unsigned int archivePos = fdGetCpioPos(fsm->cfd); + if (archivePos > fi->archivePos) { + fi->archivePos = archivePos; + ptr = rpmtsNotify(ts, fi->te, RPMCALLBACK_INST_PROGRESS, + fi->archivePos, fi->archiveSize); + } } break; case FSM_UNDO: @@ -21,6 +21,8 @@ #define _RPMTE_INTERNAL #include "rpmte.h" + +#define _RPMTS_INTERNAL /* XXX ts->notify */ #include "rpmts.h" #include "rpmlead.h" /* writeLead proto */ @@ -1509,6 +1511,12 @@ psm->te->h = headerLink(fi->h); if (!rc) rc = psmStage(psm, PSM_COMMIT); + /* XXX make sure progress is closed out */ + psm->what = RPMCALLBACK_INST_PROGRESS; + psm->amount = (fi->archiveSize ? fi->archiveSize : 100); + psm->total = psm->amount; + xx = psmStage(psm, PSM_NOTIFY); + if (rc) { rpmError(RPMERR_CPIO, _("unpacking of archive failed%s%s: %s\n"), @@ -1525,10 +1533,6 @@ psm->te->h = headerLink(fi->h); break; } - psm->what = RPMCALLBACK_INST_PROGRESS; - psm->amount = (fi->archiveSize ? fi->archiveSize : 100); - psm->total = psm->amount; - xx = psmStage(psm, PSM_NOTIFY); } if (psm->goal == PSM_PKGERASE) { int fc = rpmfiFC(fi); @@ -1583,6 +1587,12 @@ psm->te->h = headerLink(fi->h); errno = saveerrno; /*@=mods@*/ + /* XXX make sure progress is closed out */ + psm->what = RPMCALLBACK_INST_PROGRESS; + psm->amount = (fi->archiveSize ? fi->archiveSize : 100); + psm->total = psm->amount; + xx = psmStage(psm, PSM_NOTIFY); + fi->action = action; fi->actions = actions; } @@ -1698,7 +1708,7 @@ psm->te->h = headerLink(fi->h); } if (psm->goal == PSM_PKGSAVE) { - if (!rc) { + if (!rc && ts && ts->notify == NULL) { rpmMessage(RPMMESS_VERBOSE, _("Wrote: %s\n"), (psm->pkgURL ? psm->pkgURL : "???")); } diff --git a/lib/rpmcli.h b/lib/rpmcli.h index 1ebf5e469..875df09ca 100644 --- a/lib/rpmcli.h +++ b/lib/rpmcli.h @@ -462,10 +462,19 @@ extern struct poptOption rpmBuildPoptTable[]; /* --- install/upgrade/erase modes */ /*@unchecked@*/ -extern int packagesTotal; +extern int rpmcliPackagesTotal; +/*@unchecked@*/ +extern int rpmcliHashesCurrent; +/*@unchecked@*/ +extern int rpmcliHashesTotal; +/*@unchecked@*/ +extern int rpmcliProgressCurrent; +/*@unchecked@*/ +extern int rpmcliProgressTotal; /** \ingroup rpmcli - * The rpm CLI generic transaction callback. + * The rpm CLI generic transaction callback handler. + * @todo Remove headerSprintf() from the progress callback. * @deprecated Transaction callback arguments need to change, so don't rely on * this routine in the rpmcli API. * @@ -483,8 +492,12 @@ extern int packagesTotal; const unsigned long total, /*@null@*/ fnpyKey key, /*@null@*/ void * data) - /*@globals fileSystem, internalState @*/ - /*@modifies fileSystem, internalState @*/; + /*@globals rpmcliHashesCurrent, + rpmcliProgressCurrent, rpmcliProgressTotal, + fileSystem, internalState @*/ + /*@modifies rpmcliHashesCurrent, + rpmcliProgressCurrent, rpmcliProgressTotal, + fileSystem, internalState @*/; /** \ingroup rpmcli * Install source rpm package. diff --git a/lib/rpmfi.c b/lib/rpmfi.c index f9e3a1daf..686ebcd84 100644 --- a/lib/rpmfi.c +++ b/lib/rpmfi.c @@ -1026,6 +1026,7 @@ rpmfi rpmfiNew(rpmts ts, rpmfi fi, /* 0 means unknown */ xx = hge(h, RPMTAG_ARCHIVESIZE, NULL, (void **) &uip, NULL); + fi->archivePos = 0; fi->archiveSize = (xx ? *uip : 0); if (!hge(h, RPMTAG_BASENAMES, NULL, (void **) &fi->bnl, &fi->fc)) { diff --git a/lib/rpmfi.h b/lib/rpmfi.h index 4237d4794..da112b4c3 100644 --- a/lib/rpmfi.h +++ b/lib/rpmfi.h @@ -118,6 +118,7 @@ struct rpmfi_s { int astriplen; int striplen; + unsigned int archivePos; unsigned int archiveSize; mode_t dperms; /*!< Directory perms (0755) if not mapped. */ mode_t fperms; /*!< File perms (0644) if not mapped. */ diff --git a/lib/rpminstall.c b/lib/rpminstall.c index 5c6a89641..7b866d82e 100644 --- a/lib/rpminstall.c +++ b/lib/rpminstall.c @@ -24,52 +24,60 @@ /*@access IDT @*/ /*@unchecked@*/ -static int hashesPrinted = 0; - +int rpmcliPackagesTotal = 0; +/*@unchecked@*/ +int rpmcliHashesCurrent = 0; /*@unchecked@*/ -int packagesTotal = 0; +int rpmcliHashesTotal = 0; /*@unchecked@*/ -static int progressTotal = 0; +int rpmcliProgressCurrent = 0; /*@unchecked@*/ -static int progressCurrent = 0; +int rpmcliProgressTotal = 0; /** + * Print a CLI progress bar. + * @todo Unsnarl isatty(STDOUT_FILENO) from the control flow. + * @param amount current + * @param total final */ static void printHash(const unsigned long amount, const unsigned long total) - /*@globals hashesPrinted, progressCurrent, fileSystem @*/ - /*@modifies hashesPrinted, progressCurrent, fileSystem @*/ + /*@globals rpmcliHashesCurrent, rpmcliProgressCurrent, fileSystem @*/ + /*@modifies rpmcliHashesCurrent, rpmcliProgressCurrent, fileSystem @*/ { int hashesNeeded; - int hashesTotal = 50; - if (isatty (STDOUT_FILENO)) - hashesTotal = 44; + rpmcliHashesTotal = (isatty (STDOUT_FILENO) ? 44 : 50); - if (hashesPrinted != hashesTotal) { - hashesNeeded = hashesTotal * (total ? (((float) amount) / total) : 1); - while (hashesNeeded > hashesPrinted) { + if (rpmcliHashesCurrent != rpmcliHashesTotal) { + float pct = (total ? (((float) amount) / total) : 1); + hashesNeeded = rpmcliHashesTotal * pct; + while (hashesNeeded > rpmcliHashesCurrent) { if (isatty (STDOUT_FILENO)) { int i; - for (i = 0; i < hashesPrinted; i++) (void) putchar ('#'); - for (; i < hashesTotal; i++) (void) putchar (' '); - fprintf(stdout, "(%3d%%)", - (int)(100 * (total ? (((float) amount) / total) : 1))); - for (i = 0; i < (hashesTotal + 6); i++) (void) putchar ('\b'); + for (i = 0; i < rpmcliHashesCurrent; i++) + (void) putchar ('#'); + for (; i < rpmcliHashesTotal; i++) + (void) putchar (' '); + fprintf(stdout, "(%3d%%)", (int)(100 * pct)); + for (i = 0; i < (rpmcliHashesTotal + 6); i++) + (void) putchar ('\b'); } else fprintf(stdout, "#"); - hashesPrinted++; + rpmcliHashesCurrent++; } (void) fflush(stdout); - hashesPrinted = hashesNeeded; - if (hashesPrinted == hashesTotal) { + if (rpmcliHashesCurrent == rpmcliHashesTotal) { int i; - progressCurrent++; + rpmcliProgressCurrent++; if (isatty(STDOUT_FILENO)) { - for (i = 1; i < hashesPrinted; i++) (void) putchar ('#'); - fprintf(stdout, " [%3d%%]", (int)(100 * (progressTotal ? - (((float) progressCurrent) / progressTotal) : 1))); + for (i = 1; i < rpmcliHashesCurrent; i++) + (void) putchar ('#'); + pct = (rpmcliProgressTotal + ? (((float) rpmcliProgressCurrent) / rpmcliProgressTotal) + : 1); + fprintf(stdout, " [%3d%%]", (int)(100 * pct)); } fprintf(stdout, "\n"); } @@ -83,9 +91,9 @@ void * rpmShowProgress(/*@null@*/ const void * arg, const unsigned long total, /*@null@*/ fnpyKey key, /*@null@*/ void * data) - /*@globals hashesPrinted, progressCurrent, progressTotal, + /*@globals rpmcliHashesCurrent, rpmcliProgressCurrent, rpmcliProgressTotal, fileSystem @*/ - /*@modifies hashesPrinted, progressCurrent, progressTotal, + /*@modifies rpmcliHashesCurrent, rpmcliProgressCurrent, rpmcliProgressTotal, fileSystem @*/ { /*@-castexpose@*/ @@ -124,14 +132,19 @@ void * rpmShowProgress(/*@null@*/ const void * arg, break; case RPMCALLBACK_INST_START: - hashesPrinted = 0; +#if 0 +if (_hash_debug) +fprintf(stderr, "--- INST_START: %p %lu:%lu %p %p\n", arg, amount, total, key, data); +#endif + rpmcliHashesCurrent = 0; if (h == NULL || !(flags & INSTALL_LABEL)) break; + /* @todo Remove headerSprintf() on a progress callback. */ if (flags & INSTALL_HASH) { s = headerSprintf(h, "%{NAME}", rpmTagTable, rpmHeaderFormats, NULL); if (isatty (STDOUT_FILENO)) - fprintf(stdout, "%4d:%-23.23s", progressCurrent + 1, s); + fprintf(stdout, "%4d:%-23.23s", rpmcliProgressCurrent + 1, s); else fprintf(stdout, "%-28.28s", s); (void) fflush(stdout); @@ -157,9 +170,9 @@ void * rpmShowProgress(/*@null@*/ const void * arg, break; case RPMCALLBACK_TRANS_START: - hashesPrinted = 0; - progressTotal = 1; - progressCurrent = 0; + rpmcliHashesCurrent = 0; + rpmcliProgressTotal = 1; + rpmcliProgressCurrent = 0; if (!(flags & INSTALL_LABEL)) break; if (flags & INSTALL_HASH) @@ -172,16 +185,56 @@ void * rpmShowProgress(/*@null@*/ const void * arg, case RPMCALLBACK_TRANS_STOP: if (flags & INSTALL_HASH) printHash(1, 1); /* Fixes "preparing..." progress bar */ - progressTotal = packagesTotal; - progressCurrent = 0; + rpmcliProgressTotal = rpmcliPackagesTotal; + rpmcliProgressCurrent = 0; + break; + + case RPMCALLBACK_REPACKAGE_START: + rpmcliHashesCurrent = 0; + rpmcliProgressTotal = total; + rpmcliProgressCurrent = 0; + if (!(flags & INSTALL_LABEL)) + break; + if (flags & INSTALL_HASH) + fprintf(stdout, "%-28s\n", _("Repackaging...")); + else + fprintf(stdout, "%s\n", _("Repackaging erased files...")); + (void) fflush(stdout); + break; + + case RPMCALLBACK_REPACKAGE_PROGRESS: + if (amount && (flags & INSTALL_HASH)) + printHash(1, 1); /* Fixes "preparing..." progress bar */ + break; + + case RPMCALLBACK_REPACKAGE_STOP: + rpmcliProgressTotal = total; + rpmcliProgressCurrent = total; + if (flags & INSTALL_HASH) + printHash(1, 1); /* Fixes "preparing..." progress bar */ + rpmcliProgressTotal = rpmcliPackagesTotal; + rpmcliProgressCurrent = 0; + if (!(flags & INSTALL_LABEL)) + break; + if (flags & INSTALL_HASH) + fprintf(stdout, "%-28s\n", _("Upgrading...")); + else + fprintf(stdout, "%s\n", _("Upgrading packages...")); + (void) fflush(stdout); break; case RPMCALLBACK_UNINST_PROGRESS: + break; case RPMCALLBACK_UNINST_START: + break; case RPMCALLBACK_UNINST_STOP: + break; case RPMCALLBACK_UNPACK_ERROR: + break; case RPMCALLBACK_CPIO_ERROR: - /* ignore */ + break; + case RPMCALLBACK_UNKNOWN: + default: break; } @@ -573,7 +626,7 @@ restart: if (eiu->numRPMS && !stopInstall) { - packagesTotal = eiu->numRPMS + eiu->numSRPMS; + rpmcliPackagesTotal = eiu->numRPMS + eiu->numSRPMS; rpmMessage(RPMMESS_DEBUG, _("installing binary packages\n")); @@ -949,15 +1002,10 @@ int rpmRollback(rpmts ts, /*@unused@*/ struct rpmInstallArguments_s * ia, const char ** argv) { -#ifdef NOTYET - rpmdb db = NULL; - rpmts ts = NULL; - rpmps ps; int ifmask= (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL|INSTALL_ERASE); unsigned thistid = 0xffffffff; unsigned prevtid; time_t tid; -#endif IDTX itids = NULL; IDTX rtids = NULL; IDT rp; @@ -965,12 +1013,28 @@ int rpmRollback(rpmts ts, IDT ip; int niids = 0; int rc = 0; + int vsflags, ovsflags; + int numAdded; + int numRemoved; + rpmps ps; if (argv != NULL && *argv != NULL) { rc = -1; goto exit; } + vsflags = rpmExpandNumeric("%{?_vsflags_erase}"); + if (ia->qva_flags & VERIFY_DIGEST) + vsflags |= _RPMTS_VSF_NODIGESTS; + if (ia->qva_flags & VERIFY_SIGNATURE) + vsflags |= _RPMTS_VSF_NOSIGNATURES; + if (ia->qva_flags & VERIFY_HDRCHK) + vsflags |= _RPMTS_VSF_NOHDRCHK; + vsflags |= _RPMTS_VSF_VERIFY_LEGACY; + ovsflags = rpmtsSetVerifySigFlags(ts, (vsflags & ~_RPMTS_VSF_VERIFY_LEGACY)); + + (void) rpmtsSetFlags(ts, ia->transFlags); + itids = IDTXload(ts, RPMTAG_INSTALLTID); if (itids != NULL) { ip = itids->idt; @@ -997,20 +1061,19 @@ int rpmRollback(rpmts ts, globstr = _free(globstr); } -#ifdef NOTYET - { int notifyFlags; + { int notifyFlags, xx; notifyFlags = ia->installInterfaceFlags | (rpmIsVerbose() ? INSTALL_LABEL : 0 ); xx = rpmtsSetNotifyCallback(ts, rpmShowProgress, (void *) ((long)notifyFlags)); } - (void) rpmtsSetFlags(ts, ia->transFlags); - /* Run transactions until rollback goal is achieved. */ do { prevtid = thistid; rc = 0; - packagesTotal = 0; + rpmcliPackagesTotal = 0; + numAdded = 0; + numRemoved = 0; ia->installInterfaceFlags &= ~ifmask; /* Find larger of the remaining install/erase transaction id's. */ @@ -1034,7 +1097,8 @@ int rpmRollback(rpmts ts, if (rc != 0) goto exit; - packagesTotal++; + numAdded++; + rpmcliPackagesTotal++; if (!(ia->installInterfaceFlags & ifmask)) ia->installInterfaceFlags |= INSTALL_UPGRADE; @@ -1054,11 +1118,14 @@ int rpmRollback(rpmts ts, rpmMessage(RPMMESS_DEBUG, "\t--- rpmdb instance #%u\n", ip->instance); - rc = rpmtsAddEraseElement(ts, ip->instance); + rc = rpmtsAddEraseElement(ts, ip->h, ip->instance); if (rc != 0) goto exit; - packagesTotal++; + numRemoved++; +#ifdef NOTYET /* XXX don't count erasures yet */ + rpmcliPackagesTotal++; +#endif if (!(ia->installInterfaceFlags & ifmask)) ia->installInterfaceFlags |= INSTALL_ERASE; @@ -1073,12 +1140,13 @@ int rpmRollback(rpmts ts, } /* Anything to do? */ - if (packagesTotal <= 0) + if (rpmcliPackagesTotal <= 0) break; tid = (time_t)thistid; - rpmMessage(RPMMESS_DEBUG, _("rollback %d packages to %s"), - packagesTotal, ctime(&tid)); + rpmMessage(RPMMESS_NORMAL, + _("Rollback packages (+%d/-%d) to %-24.24s (0x%08x):\n"), + numAdded, numRemoved, ctime(&tid), tid); rc = rpmtsCheck(ts); ps = rpmtsProblems(ts); @@ -1117,7 +1185,6 @@ int rpmRollback(rpmts ts, } } while (1); -#endif exit: diff --git a/lib/transaction.c b/lib/transaction.c index c38aaa951..c84229ddc 100644 --- a/lib/transaction.c +++ b/lib/transaction.c @@ -967,6 +967,8 @@ int rpmtsRun(rpmts ts, rpmps okProbs, rpmprobFilterFlags ignoreSet) PSM_t psm = memset(alloca(sizeof(*psm)), 0, sizeof(*psm)); rpmtsi pi; rpmte p; rpmtsi qi; rpmte q; + int numAdded; + int numRemoved; int xx; /* FIXME: what if the same package is included in ts twice? */ @@ -1101,6 +1103,7 @@ rpmMessage(RPMMESS_DEBUG, _("sanity checking %d elments\n"), rpmtsNElements(ts)) * worth the trouble though. */ rpmMessage(RPMMESS_DEBUG, _("computing %d file fingerprints\n"), totalFileCount); + numAdded = numRemoved = 0; pi = rpmtsiInit(ts); while ((p = rpmtsiNext(pi, 0)) != NULL) { int fc; @@ -1112,12 +1115,14 @@ rpmMessage(RPMMESS_DEBUG, _("computing %d file fingerprints\n"), totalFileCount) /*@-branchstate@*/ switch (rpmteType(p)) { case TR_ADDED: + numAdded++; fi->record = 0; /* Skip netshared paths, not our i18n files, and excluded docs */ if (fc > 0) skipFiles(ts, fi); /*@switchbreak@*/ break; case TR_REMOVED: + numRemoved++; fi->record = rpmteDBOffset(p); /*@switchbreak@*/ break; } @@ -1338,8 +1343,9 @@ rpmMessage(RPMMESS_DEBUG, _("computing file dispositions\n")); /* =============================================== * Save removed files before erasing. */ -rpmMessage(RPMMESS_DEBUG, _("repackage about-to-be-erased packages\n")); if (rpmtsFlags(ts) & (RPMTRANS_FLAG_DIRSTASH | RPMTRANS_FLAG_REPACKAGE)) { + int progress; + progress = 0; pi = rpmtsiInit(ts); while ((p = rpmtsiNext(pi, 0)) != NULL) { fi = rpmtsiFi(pi); @@ -1349,6 +1355,14 @@ rpmMessage(RPMMESS_DEBUG, _("repackage about-to-be-erased packages\n")); case TR_REMOVED: if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_REPACKAGE)) /*@switchbreak@*/ break; + if (!progress) + NOTIFY(ts, (NULL, RPMCALLBACK_REPACKAGE_START, + 7, numRemoved, NULL, ts->notifyData)); + + NOTIFY(ts, (NULL, RPMCALLBACK_REPACKAGE_PROGRESS, progress, + numRemoved, NULL, ts->notifyData)); + progress++; + psm->te = p; psm->fi = rpmfiLink(fi, "tsRepackage"); /* XXX TR_REMOVED needs CPIO_MAP_{ABSOLUTE,ADDDOT} CPIO_ALL_HARDLINKS */ @@ -1363,6 +1377,10 @@ rpmMessage(RPMMESS_DEBUG, _("repackage about-to-be-erased packages\n")); } } pi = rpmtsiFree(pi); + if (progress) { + NOTIFY(ts, (NULL, RPMCALLBACK_REPACKAGE_STOP, 7, numRemoved, + NULL, ts->notifyData)); + } } /* =============================================== |