7 #define UP2DATEGLOB "/var/spool/up2date/*.rpm"
10 static int XrpmRollback(struct rpmInstallArguments_s * ia, const char ** argv)
13 rpmTransactionSet ts = NULL;
14 rpmProblemSet probs = NULL;
17 unsigned thistid = 0xffffffff;
24 if (argv != NULL && *argv != NULL) {
29 rc = rpmdbOpen(ia->rootdir, &db, O_RDWR, 0644);
33 itids = IDTXload(db, RPMTAG_INSTALLTID);
34 ip = (itids != NULL && itids->nidt > 0) ? itids->idt : NULL;
36 { const char * globstr = rpmExpand("%{_repackage_dir}/*.rpm", NULL);
37 if (globstr == NULL || *globstr == '%') {
38 globstr = _free(globstr);
42 rtids = IDTXglob(globstr, RPMTAG_REMOVETID);
43 rp = (rtids != NULL && rtids->nidt > 0) ? rtids->idt : NULL;
44 globstr = _free(globstr);
47 /* Run transactions until rollback goal is achieved. */
53 /* Find larger of the remaining install/erase transaction id's. */
55 if (ip != NULL && ip->val.u32 > thistid)
56 thistid = ip->val.u32;
57 if (rp != NULL && rp->val.u32 > thistid)
58 thistid = rp->val.u32;
60 /* If we've achieved the rollback goal, then we're done. */
61 if (thistid == 0 || thistid < ia->rbtid)
64 ts = rpmtransCreateSet(db, ia->rootdir);
66 /* Install the previously erased packages for this transaction. */
67 while (rp != NULL && rp->val.u32 == thistid) {
69 rpmMessage(RPMMESS_DEBUG, "\t+++ %s\n", rp->key);
71 rc = rpmtransAddPackage(ts, rp->h, NULL, rp->key,
72 (ia->installInterfaceFlags & INSTALL_UPGRADE) != 0,
79 rp->h = headerFree(rp->h);
87 /* Erase the previously installed packages for this transaction. */
88 while (ip != NULL && ip->val.u32 == thistid) {
90 rpmMessage(RPMMESS_DEBUG,
91 "\t--- rpmdb instance #%u\n", ip->instance);
93 rc = rpmtransRemovePackage(ts, ip->instance);
107 /* Anything to do? */
108 if (packagesTotal <= 0)
111 tid = (time_t)thistid;
112 rpmMessage(RPMMESS_DEBUG, _("rollback %d packages to %s"),
113 packagesTotal, ctime(&tid));
115 rc = rpmdepOrder(ts);
120 rc = rpmRunTransactions(ts, rpmShowProgress,
121 (void *) ((long)ia->installInterfaceFlags),
122 NULL, &probs, ia->transFlags,
123 (ia->probFilter|RPMPROB_FILTER_OLDPACKAGE));
125 rpmProblemSetPrint(stderr, probs);
130 rpmProblemSetFree(probs);
133 ts = rpmtransFree(ts);
139 rpmProblemSetFree(probs);
142 ts = rpmtransFree(ts);
144 if (db != NULL) (void) rpmdbClose(db);
146 rtids = IDTXfree(rtids);
147 itids = IDTXfree(itids);
153 static struct poptOption optionsTable[] = {
154 { "verbose", 'v', 0, 0, 'v',
155 N_("provide more detailed output"), NULL},
156 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmInstallPoptTable, 0,
157 N_("Install/Upgrade/Erase options:"),
164 main(int argc, const char *argv[])
167 struct rpmInstallArguments_s * ia = &rpmIArgs;
171 #if HAVE_MCHECK_H && HAVE_MTRACE
172 mtrace(); /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */
174 setprogname(argv[0]); /* Retrofit glibc __progname */
176 /* set up the correct locale */
177 (void) setlocale(LC_ALL, "" );
179 bindtextdomain(PACKAGE, LOCALEDIR);
182 rpmSetVerbosity(RPMMESS_NORMAL);
184 optCon = poptGetContext(argv[0], argc, argv, optionsTable, 0);
185 (void) poptReadConfigFile(optCon, LIBRPMALIAS_FILENAME);
186 (void) poptReadDefaultConfig(optCon, 1);
187 poptSetExecPath(optCon, RPMCONFIGDIR, 1);
189 while ((arg = poptGetNextOpt(optCon)) > 0) {
192 rpmIncreaseVerbosity();
199 if (ia->rbtid == 0) {
200 fprintf(stderr, "--rollback <timestamp> is required\n");
204 if (rpmReadConfigFiles(NULL, NULL))
207 ec = rpmRollback(ia, NULL);
209 optCon = poptFreeContext(optCon);
212 #if HAVE_MCHECK_H && HAVE_MTRACE
213 muntrace(); /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */