Deal with a return value of "-2" when database locking failed.
[platform/upstream/rpm.git] / lib / rpminstall.c
1 /** \ingroup rpmcli
2  * \file lib/rpminstall.c
3  */
4
5 #include "system.h"
6
7 #include <rpmcli.h>
8
9 #include "rpmdb.h"
10 #include "rpmds.h"
11
12 #include "rpmte.h"      /* XXX: rpmts.h needs this for rpmtsScoreEntries */
13 #define _RPMTS_INTERNAL         /* ts->goal, ts->dbmode, ts->suggests */
14 #include "rpmts.h"
15
16 #include "manifest.h"
17 #include "misc.h"       /* XXX for rpmGlob() */
18 #include "debug.h"
19
20 /*@access rpmts @*/     /* XXX ts->goal, ts->dbmode */
21 /*@access IDTX @*/
22 /*@access IDT @*/
23
24 /*@unchecked@*/
25 int rpmcliPackagesTotal = 0;
26 /*@unchecked@*/
27 int rpmcliHashesCurrent = 0;
28 /*@unchecked@*/
29 int rpmcliHashesTotal = 0;
30 /*@unchecked@*/
31 int rpmcliProgressCurrent = 0;
32 /*@unchecked@*/
33 int rpmcliProgressTotal = 0;
34
35 /**
36  * Print a CLI progress bar.
37  * @todo Unsnarl isatty(STDOUT_FILENO) from the control flow.
38  * @param amount        current
39  * @param total         final
40  */
41 static void printHash(const unsigned long amount, const unsigned long total)
42         /*@globals rpmcliHashesCurrent, rpmcliHashesTotal,
43                 rpmcliProgressCurrent, fileSystem @*/
44         /*@modifies rpmcliHashesCurrent, rpmcliHashesTotal,
45                 rpmcliProgressCurrent, fileSystem @*/
46 {
47     int hashesNeeded;
48
49     rpmcliHashesTotal = (isatty (STDOUT_FILENO) ? 44 : 50);
50
51     if (rpmcliHashesCurrent != rpmcliHashesTotal) {
52 /*@+relaxtypes@*/
53         float pct = (total ? (((float) amount) / total) : 1.0);
54         hashesNeeded = (rpmcliHashesTotal * pct) + 0.5;
55 /*@=relaxtypes@*/
56         while (hashesNeeded > rpmcliHashesCurrent) {
57             if (isatty (STDOUT_FILENO)) {
58                 int i;
59                 for (i = 0; i < rpmcliHashesCurrent; i++)
60                     (void) putchar ('#');
61                 for (; i < rpmcliHashesTotal; i++)
62                     (void) putchar (' ');
63                 fprintf(stdout, "(%3d%%)", (int)((100 * pct) + 0.5));
64                 for (i = 0; i < (rpmcliHashesTotal + 6); i++)
65                     (void) putchar ('\b');
66             } else
67                 fprintf(stdout, "#");
68
69             rpmcliHashesCurrent++;
70         }
71         (void) fflush(stdout);
72
73         if (rpmcliHashesCurrent == rpmcliHashesTotal) {
74             int i;
75             rpmcliProgressCurrent++;
76             if (isatty(STDOUT_FILENO)) {
77                 for (i = 1; i < rpmcliHashesCurrent; i++)
78                     (void) putchar ('#');
79 /*@+relaxtypes@*/
80                 pct = (rpmcliProgressTotal
81                     ? (((float) rpmcliProgressCurrent) / rpmcliProgressTotal)
82                     : 1);
83 /*@=relaxtypes@*/
84                 fprintf(stdout, " [%3d%%]", (int)((100 * pct) + 0.5));
85             }
86             fprintf(stdout, "\n");
87         }
88         (void) fflush(stdout);
89     }
90 }
91
92 void * rpmShowProgress(/*@null@*/ const void * arg,
93                         const rpmCallbackType what,
94                         const unsigned long amount,
95                         const unsigned long total,
96                         /*@null@*/ fnpyKey key,
97                         /*@null@*/ void * data)
98         /*@globals rpmcliHashesCurrent, rpmcliProgressCurrent, rpmcliProgressTotal,
99                 fileSystem @*/
100         /*@modifies rpmcliHashesCurrent, rpmcliProgressCurrent, rpmcliProgressTotal,
101                 fileSystem @*/
102 {
103 /*@-abstract -castexpose @*/
104     Header h = (Header) arg;
105 /*@=abstract =castexpose @*/
106     char * s;
107     int flags = (int) ((long)data);
108     void * rc = NULL;
109 /*@-abstract -assignexpose @*/
110     const char * filename = (const char *)key;
111 /*@=abstract =assignexpose @*/
112     static FD_t fd = NULL;
113     int xx;
114
115     switch (what) {
116     case RPMCALLBACK_INST_OPEN_FILE:
117 /*@-boundsread@*/
118         if (filename == NULL || filename[0] == '\0')
119             return NULL;
120 /*@=boundsread@*/
121         fd = Fopen(filename, "r.ufdio");
122         /*@-type@*/ /* FIX: still necessary? */
123         if (fd == NULL || Ferror(fd)) {
124             rpmError(RPMERR_OPEN, _("open of %s failed: %s\n"), filename,
125                         Fstrerror(fd));
126             if (fd != NULL) {
127                 xx = Fclose(fd);
128                 fd = NULL;
129             }
130         } else
131             fd = fdLink(fd, "persist (showProgress)");
132         /*@=type@*/
133 /*@+voidabstract@*/
134         return (void *)fd;
135 /*@=voidabstract@*/
136         /*@notreached@*/ break;
137
138     case RPMCALLBACK_INST_CLOSE_FILE:
139         /*@-type@*/ /* FIX: still necessary? */
140         fd = fdFree(fd, "persist (showProgress)");
141         /*@=type@*/
142         if (fd != NULL) {
143             xx = Fclose(fd);
144             fd = NULL;
145         }
146         break;
147
148     case RPMCALLBACK_INST_START:
149         rpmcliHashesCurrent = 0;
150         if (h == NULL || !(flags & INSTALL_LABEL))
151             break;
152         /* @todo Remove headerSprintf() on a progress callback. */
153         if (flags & INSTALL_HASH) {
154             s = headerSprintf(h, "%{NAME}",
155                                 rpmTagTable, rpmHeaderFormats, NULL);
156             if (isatty (STDOUT_FILENO))
157                 fprintf(stdout, "%4d:%-23.23s", rpmcliProgressCurrent + 1, s);
158             else
159                 fprintf(stdout, "%-28.28s", s);
160             (void) fflush(stdout);
161             s = _free(s);
162         } else {
163             s = headerSprintf(h, "%{NAME}-%{VERSION}-%{RELEASE}",
164                                   rpmTagTable, rpmHeaderFormats, NULL);
165             fprintf(stdout, "%s\n", s);
166             (void) fflush(stdout);
167             s = _free(s);
168         }
169         break;
170
171     case RPMCALLBACK_TRANS_PROGRESS:
172     case RPMCALLBACK_INST_PROGRESS:
173 /*@+relaxtypes@*/
174         if (flags & INSTALL_PERCENT)
175             fprintf(stdout, "%%%% %f\n", (double) (total
176                                 ? ((((float) amount) / total) * 100)
177                                 : 100.0));
178         else if (flags & INSTALL_HASH)
179             printHash(amount, total);
180 /*@=relaxtypes@*/
181         (void) fflush(stdout);
182         break;
183
184     case RPMCALLBACK_TRANS_START:
185         rpmcliHashesCurrent = 0;
186         rpmcliProgressTotal = 1;
187         rpmcliProgressCurrent = 0;
188         if (!(flags & INSTALL_LABEL))
189             break;
190         if (flags & INSTALL_HASH)
191             fprintf(stdout, "%-28s", _("Preparing..."));
192         else
193             fprintf(stdout, "%s\n", _("Preparing packages for installation..."));
194         (void) fflush(stdout);
195         break;
196
197     case RPMCALLBACK_TRANS_STOP:
198         if (flags & INSTALL_HASH)
199             printHash(1, 1);    /* Fixes "preparing..." progress bar */
200         rpmcliProgressTotal = rpmcliPackagesTotal;
201         rpmcliProgressCurrent = 0;
202         break;
203
204     case RPMCALLBACK_REPACKAGE_START:
205         rpmcliHashesCurrent = 0;
206         rpmcliProgressTotal = total;
207         rpmcliProgressCurrent = 0;
208         if (!(flags & INSTALL_LABEL))
209             break;
210         if (flags & INSTALL_HASH)
211             fprintf(stdout, "%-28s\n", _("Repackaging..."));
212         else
213             fprintf(stdout, "%s\n", _("Repackaging erased files..."));
214         (void) fflush(stdout);
215         break;
216
217     case RPMCALLBACK_REPACKAGE_PROGRESS:
218         if (amount && (flags & INSTALL_HASH))
219             printHash(1, 1);    /* Fixes "preparing..." progress bar */
220         break;
221
222     case RPMCALLBACK_REPACKAGE_STOP:
223         rpmcliProgressTotal = total;
224         rpmcliProgressCurrent = total;
225         if (flags & INSTALL_HASH)
226             printHash(1, 1);    /* Fixes "preparing..." progress bar */
227         rpmcliProgressTotal = rpmcliPackagesTotal;
228         rpmcliProgressCurrent = 0;
229         if (!(flags & INSTALL_LABEL))
230             break;
231         if (flags & INSTALL_HASH)
232             fprintf(stdout, "%-28s\n", _("Upgrading..."));
233         else
234             fprintf(stdout, "%s\n", _("Upgrading packages..."));
235         (void) fflush(stdout);
236         break;
237
238     case RPMCALLBACK_UNINST_PROGRESS:
239         break;
240     case RPMCALLBACK_UNINST_START:
241         break;
242     case RPMCALLBACK_UNINST_STOP:
243         break;
244     case RPMCALLBACK_UNPACK_ERROR:
245         break;
246     case RPMCALLBACK_CPIO_ERROR:
247         break;
248     case RPMCALLBACK_UNKNOWN:
249     default:
250         break;
251     }
252
253     return rc;
254 }       
255
256 typedef /*@only@*/ /*@null@*/ const char * str_t;
257
258 struct rpmEIU {
259     Header h;
260     FD_t fd;
261     int numFailed;
262     int numPkgs;
263 /*@only@*/
264     str_t * pkgURL;
265 /*@dependent@*/ /*@null@*/
266     str_t * fnp;
267 /*@only@*/
268     char * pkgState;
269     int prevx;
270     int pkgx;
271     int numRPMS;
272     int numSRPMS;
273 /*@only@*/ /*@null@*/
274     str_t * sourceURL;
275     int isSource;
276     int argc;
277 /*@only@*/ /*@null@*/
278     str_t * argv;
279 /*@dependent@*/
280     rpmRelocation * relocations;
281     rpmRC rpmrc;
282 };
283
284 /** @todo Generalize --freshen policies. */
285 /*@-bounds@*/
286 int rpmInstall(rpmts ts,
287                 struct rpmInstallArguments_s * ia,
288                 const char ** fileArgv)
289 {
290     struct rpmEIU * eiu = memset(alloca(sizeof(*eiu)), 0, sizeof(*eiu));
291     rpmps ps;
292     rpmprobFilterFlags probFilter;
293     rpmRelocation * relocations;
294 /*@only@*/ /*@null@*/ const char * fileURL = NULL;
295     int stopInstall = 0;
296     const char ** av = NULL;
297     rpmVSFlags vsflags, ovsflags, tvsflags;
298     int ac = 0;
299     int rc;
300     int xx;
301     int i;
302
303     if (fileArgv == NULL) goto exit;
304
305     ts->goal = TSM_INSTALL;
306     rpmcliPackagesTotal = 0;
307
308     if (rpmExpandNumeric("%{?_repackage_all_erasures}"))
309         ia->transFlags |= RPMTRANS_FLAG_REPACKAGE;
310
311     /* Initialize security context patterns (if not already done). */
312     if (!(ia->transFlags & RPMTRANS_FLAG_NOCONTEXTS)) {
313         rpmsx sx = rpmtsREContext(ts);
314         if (sx == NULL) {
315             const char *fn = rpmGetPath("%{?_install_file_context_path}", NULL);
316             if (fn != NULL && *fn != '\0') {
317                 sx = rpmsxNew(fn);
318                 (void) rpmtsSetREContext(ts, sx);
319             }
320             fn = _free(fn);
321         }
322         sx = rpmsxFree(sx);
323     }
324     (void) rpmtsSetFlags(ts, ia->transFlags);
325
326     probFilter = ia->probFilter;
327     relocations = ia->relocations;
328
329     if (ia->installInterfaceFlags & INSTALL_UPGRADE)
330         vsflags = rpmExpandNumeric("%{?_vsflags_erase}");
331     else
332         vsflags = rpmExpandNumeric("%{?_vsflags_install}");
333     if (ia->qva_flags & VERIFY_DIGEST)
334         vsflags |= _RPMVSF_NODIGESTS;
335     if (ia->qva_flags & VERIFY_SIGNATURE)
336         vsflags |= _RPMVSF_NOSIGNATURES;
337     if (ia->qva_flags & VERIFY_HDRCHK)
338         vsflags |= RPMVSF_NOHDRCHK;
339     ovsflags = rpmtsSetVSFlags(ts, (vsflags | RPMVSF_NEEDPAYLOAD));
340
341     {   int notifyFlags;
342         notifyFlags = ia->installInterfaceFlags | (rpmIsVerbose() ? INSTALL_LABEL : 0 );
343         xx = rpmtsSetNotifyCallback(ts,
344                         rpmShowProgress, (void *) ((long)notifyFlags));
345     }
346
347     if ((eiu->relocations = relocations) != NULL) {
348         while (eiu->relocations->oldPath)
349             eiu->relocations++;
350         if (eiu->relocations->newPath == NULL)
351             eiu->relocations = NULL;
352     }
353
354     /* Build fully globbed list of arguments in argv[argc]. */
355     /*@-branchstate@*/
356     /*@-temptrans@*/
357     for (eiu->fnp = fileArgv; *eiu->fnp != NULL; eiu->fnp++) {
358     /*@=temptrans@*/
359         av = _free(av); ac = 0;
360         rc = rpmGlob(*eiu->fnp, &ac, &av);
361         if (rc || ac == 0) {
362             rpmError(RPMERR_OPEN, _("File not found by glob: %s\n"), *eiu->fnp);
363             continue;
364         }
365
366         eiu->argv = xrealloc(eiu->argv, (eiu->argc+ac+1) * sizeof(*eiu->argv));
367         memcpy(eiu->argv+eiu->argc, av, ac * sizeof(*av));
368         eiu->argc += ac;
369         eiu->argv[eiu->argc] = NULL;
370     }
371     /*@=branchstate@*/
372     av = _free(av);     ac = 0;
373
374 restart:
375     /* Allocate sufficient storage for next set of args. */
376     if (eiu->pkgx >= eiu->numPkgs) {
377         eiu->numPkgs = eiu->pkgx + eiu->argc;
378         eiu->pkgURL = xrealloc(eiu->pkgURL,
379                         (eiu->numPkgs + 1) * sizeof(*eiu->pkgURL));
380         memset(eiu->pkgURL + eiu->pkgx, 0,
381                         ((eiu->argc + 1) * sizeof(*eiu->pkgURL)));
382         eiu->pkgState = xrealloc(eiu->pkgState,
383                         (eiu->numPkgs + 1) * sizeof(*eiu->pkgState));
384         memset(eiu->pkgState + eiu->pkgx, 0,
385                         ((eiu->argc + 1) * sizeof(*eiu->pkgState)));
386     }
387
388     /* Retrieve next set of args, cache on local storage. */
389     for (i = 0; i < eiu->argc; i++) {
390         fileURL = _free(fileURL);
391         fileURL = eiu->argv[i];
392         eiu->argv[i] = NULL;
393
394 #ifdef  NOTYET
395 if (fileURL[0] == '=') {
396     rpmds this = rpmdsSingle(RPMTAG_REQUIRENAME, fileURL+1, NULL, 0);
397
398     xx = rpmtsSolve(ts, this, NULL);
399     if (ts->suggests && ts->nsuggests > 0) {
400         fileURL = _free(fileURL);
401         fileURL = ts->suggests[0];
402         ts->suggests[0] = NULL;
403         while (ts->nsuggests-- > 0) {
404             if (ts->suggests[ts->nsuggests] == NULL)
405                 continue;
406             ts->suggests[ts->nsuggests] = _free(ts->suggests[ts->nsuggests]);
407         }
408         ts->suggests = _free(ts->suggests);
409         rpmMessage(RPMMESS_DEBUG, _("Adding goal: %s\n"), fileURL);
410         eiu->pkgURL[eiu->pkgx] = fileURL;
411         fileURL = NULL;
412         eiu->pkgx++;
413     }
414     this = rpmdsFree(this);
415 } else
416 #endif
417
418         switch (urlIsURL(fileURL)) {
419         case URL_IS_HTTPS:
420         case URL_IS_HTTP:
421         case URL_IS_FTP:
422         {   const char *tfn;
423
424             if (rpmIsVerbose())
425                 fprintf(stdout, _("Retrieving %s\n"), fileURL);
426
427             {   char tfnbuf[64];
428                 const char * rootDir = rpmtsRootDir(ts);
429                 if (!(rootDir && * rootDir))
430                     rootDir = "";
431                 strcpy(tfnbuf, "rpm-xfer.XXXXXX");
432                 (void) mktemp(tfnbuf);
433                 tfn = rpmGenPath(rootDir, "%{_tmppath}/", tfnbuf);
434             }
435
436             /* XXX undefined %{name}/%{version}/%{release} here */
437             /* XXX %{_tmpdir} does not exist */
438             rpmMessage(RPMMESS_DEBUG, _(" ... as %s\n"), tfn);
439             rc = urlGetFile(fileURL, tfn);
440             if (rc < 0) {
441                 rpmMessage(RPMMESS_ERROR,
442                         _("skipping %s - transfer failed - %s\n"),
443                         fileURL, ftpStrerror(rc));
444                 eiu->numFailed++;
445                 eiu->pkgURL[eiu->pkgx] = NULL;
446                 tfn = _free(tfn);
447                 /*@switchbreak@*/ break;
448             }
449             eiu->pkgState[eiu->pkgx] = 1;
450             eiu->pkgURL[eiu->pkgx] = tfn;
451             eiu->pkgx++;
452         }   /*@switchbreak@*/ break;
453         case URL_IS_PATH:
454         case URL_IS_DASH:       /* WRONG WRONG WRONG */
455         case URL_IS_HKP:        /* WRONG WRONG WRONG */
456         default:
457             eiu->pkgURL[eiu->pkgx] = fileURL;
458             fileURL = NULL;
459             eiu->pkgx++;
460             /*@switchbreak@*/ break;
461         }
462     }
463     fileURL = _free(fileURL);
464
465     if (eiu->numFailed) goto exit;
466
467     /* Continue processing file arguments, building transaction set. */
468     for (eiu->fnp = eiu->pkgURL+eiu->prevx;
469          *eiu->fnp != NULL;
470          eiu->fnp++, eiu->prevx++)
471     {
472         const char * fileName;
473
474         rpmMessage(RPMMESS_DEBUG, "============== %s\n", *eiu->fnp);
475         (void) urlPath(*eiu->fnp, &fileName);
476
477         /* Try to read the header from a package file. */
478         eiu->fd = Fopen(*eiu->fnp, "r.ufdio");
479         if (eiu->fd == NULL || Ferror(eiu->fd)) {
480             rpmError(RPMERR_OPEN, _("open of %s failed: %s\n"), *eiu->fnp,
481                         Fstrerror(eiu->fd));
482             if (eiu->fd != NULL) {
483                 xx = Fclose(eiu->fd);
484                 eiu->fd = NULL;
485             }
486             eiu->numFailed++; *eiu->fnp = NULL;
487             continue;
488         }
489
490         /* Read the header, verifying signatures (if present). */
491         tvsflags = rpmtsSetVSFlags(ts, vsflags);
492         eiu->rpmrc = rpmReadPackageFile(ts, eiu->fd, *eiu->fnp, &eiu->h);
493         tvsflags = rpmtsSetVSFlags(ts, tvsflags);
494         xx = Fclose(eiu->fd);
495         eiu->fd = NULL;
496
497         switch (eiu->rpmrc) {
498         case RPMRC_FAIL:
499             rpmMessage(RPMMESS_ERROR, _("%s cannot be installed\n"), *eiu->fnp);
500             eiu->numFailed++; *eiu->fnp = NULL;
501             continue;
502             /*@notreached@*/ /*@switchbreak@*/ break;
503         case RPMRC_NOTFOUND:
504             goto maybe_manifest;
505             /*@notreached@*/ /*@switchbreak@*/ break;
506         case RPMRC_NOTTRUSTED:
507         case RPMRC_NOKEY:
508         case RPMRC_OK:
509         default:
510             /*@switchbreak@*/ break;
511         }
512
513         eiu->isSource = headerIsEntry(eiu->h, RPMTAG_SOURCEPACKAGE);
514
515         if (eiu->isSource) {
516             rpmMessage(RPMMESS_DEBUG, _("\tadded source package [%d]\n"),
517                 eiu->numSRPMS);
518             eiu->sourceURL = xrealloc(eiu->sourceURL,
519                                 (eiu->numSRPMS + 2) * sizeof(*eiu->sourceURL));
520             eiu->sourceURL[eiu->numSRPMS] = *eiu->fnp;
521             *eiu->fnp = NULL;
522             eiu->numSRPMS++;
523             eiu->sourceURL[eiu->numSRPMS] = NULL;
524             continue;
525         }
526
527         if (eiu->relocations) {
528             const char ** paths;
529             int pft;
530             int c;
531
532             if (headerGetEntry(eiu->h, RPMTAG_PREFIXES, &pft,
533                                        (void **) &paths, &c) && (c == 1))
534             {
535                 eiu->relocations->oldPath = xstrdup(paths[0]);
536                 paths = headerFreeData(paths, pft);
537             } else {
538                 const char * name;
539                 xx = headerNVR(eiu->h, &name, NULL, NULL);
540                 rpmMessage(RPMMESS_ERROR,
541                                _("package %s is not relocatable\n"), name);
542                 eiu->numFailed++;
543                 goto exit;
544                 /*@notreached@*/
545             }
546         }
547
548         /* On --freshen, verify package is installed and newer */
549         if (ia->installInterfaceFlags & INSTALL_FRESHEN) {
550             rpmdbMatchIterator mi;
551             const char * name;
552             Header oldH;
553             int count;
554
555             xx = headerNVR(eiu->h, &name, NULL, NULL);
556             mi = rpmtsInitIterator(ts, RPMTAG_NAME, name, 0);
557             count = rpmdbGetIteratorCount(mi);
558             while ((oldH = rpmdbNextIterator(mi)) != NULL) {
559                 if (rpmVersionCompare(oldH, eiu->h) < 0)
560                     /*@innercontinue@*/ continue;
561                 /* same or newer package already installed */
562                 count = 0;
563                 /*@innerbreak@*/ break;
564             }
565             mi = rpmdbFreeIterator(mi);
566             if (count == 0) {
567                 eiu->h = headerFree(eiu->h);
568                 continue;
569             }
570             /* Package is newer than those currently installed. */
571         }
572
573         /*@-abstract@*/
574         rc = rpmtsAddInstallElement(ts, eiu->h, (fnpyKey)fileName,
575                         (ia->installInterfaceFlags & INSTALL_UPGRADE) != 0,
576                         relocations);
577         /*@=abstract@*/
578
579         /* XXX reference held by transaction set */
580         eiu->h = headerFree(eiu->h);
581         if (eiu->relocations)
582             eiu->relocations->oldPath = _free(eiu->relocations->oldPath);
583
584         switch(rc) {
585         case 0:
586             rpmMessage(RPMMESS_DEBUG, _("\tadded binary package [%d]\n"),
587                         eiu->numRPMS);
588             /*@switchbreak@*/ break;
589         case 1:
590             rpmMessage(RPMMESS_ERROR,
591                             _("error reading from file %s\n"), *eiu->fnp);
592             eiu->numFailed++;
593             goto exit;
594             /*@notreached@*/ /*@switchbreak@*/ break;
595         case 2:
596             rpmMessage(RPMMESS_ERROR,
597                             _("file %s requires a newer version of RPM\n"),
598                             *eiu->fnp);
599             eiu->numFailed++;
600             goto exit;
601             /*@notreached@*/ /*@switchbreak@*/ break;
602         default:
603             eiu->numFailed++;
604             goto exit;
605             /*@notreached@*/ /*@switchbreak@*/ break;
606         }
607
608         eiu->numRPMS++;
609         continue;
610
611 maybe_manifest:
612         /* Try to read a package manifest. */
613         eiu->fd = Fopen(*eiu->fnp, "r.fpio");
614         if (eiu->fd == NULL || Ferror(eiu->fd)) {
615             rpmError(RPMERR_OPEN, _("open of %s failed: %s\n"), *eiu->fnp,
616                         Fstrerror(eiu->fd));
617             if (eiu->fd != NULL) {
618                 xx = Fclose(eiu->fd);
619                 eiu->fd = NULL;
620             }
621             eiu->numFailed++; *eiu->fnp = NULL;
622             break;
623         }
624
625         /* Read list of packages from manifest. */
626 /*@-nullstate@*/ /* FIX: *eiu->argv can be NULL */
627         rc = rpmReadPackageManifest(eiu->fd, &eiu->argc, &eiu->argv);
628 /*@=nullstate@*/
629         if (rc != RPMRC_OK)
630             rpmError(RPMERR_MANIFEST, _("%s: not an rpm package (or package manifest): %s\n"),
631                         *eiu->fnp, Fstrerror(eiu->fd));
632         xx = Fclose(eiu->fd);
633         eiu->fd = NULL;
634
635         /* If successful, restart the query loop. */
636         if (rc == RPMRC_OK) {
637             eiu->prevx++;
638             goto restart;
639         }
640
641         eiu->numFailed++; *eiu->fnp = NULL;
642         break;
643     }
644
645     rpmMessage(RPMMESS_DEBUG, _("found %d source and %d binary packages\n"),
646                 eiu->numSRPMS, eiu->numRPMS);
647
648     if (eiu->numFailed) goto exit;
649
650     if (eiu->numRPMS && !(ia->installInterfaceFlags & INSTALL_NODEPS)) {
651
652         if (rpmtsCheck(ts)) {
653             eiu->numFailed = eiu->numPkgs;
654             stopInstall = 1;
655         }
656
657         ps = rpmtsProblems(ts);
658         if (!stopInstall && rpmpsNumProblems(ps) > 0) {
659             rpmMessage(RPMMESS_ERROR, _("Failed dependencies:\n"));
660             rpmpsPrint(NULL, ps);
661             eiu->numFailed = eiu->numPkgs;
662             stopInstall = 1;
663
664             /*@-branchstate@*/
665             if (ts->suggests != NULL && ts->nsuggests > 0) {
666                 rpmMessage(RPMMESS_NORMAL, _("    Suggested resolutions:\n"));
667                 for (i = 0; i < ts->nsuggests; i++) {
668                     const char * str = ts->suggests[i];
669
670                     if (str == NULL)
671                         break;
672
673                     rpmMessage(RPMMESS_NORMAL, "\t%s\n", str);
674                 
675                     ts->suggests[i] = NULL;
676                     str = _free(str);
677                 }
678                 ts->suggests = _free(ts->suggests);
679             }
680             /*@=branchstate@*/
681         }
682         ps = rpmpsFree(ps);
683     }
684
685     if (eiu->numRPMS && !(ia->installInterfaceFlags & INSTALL_NOORDER)) {
686         if (rpmtsOrder(ts)) {
687             eiu->numFailed = eiu->numPkgs;
688             stopInstall = 1;
689         }
690     }
691
692     if (eiu->numRPMS && !stopInstall) {
693
694         rpmcliPackagesTotal += eiu->numSRPMS;
695
696         rpmMessage(RPMMESS_DEBUG, _("installing binary packages\n"));
697
698         /* Drop added/available package indices and dependency sets. */
699         rpmtsClean(ts);
700
701         rc = rpmtsRun(ts, NULL, probFilter);
702         ps = rpmtsProblems(ts);
703
704         if (rc < 0) {
705             eiu->numFailed += eiu->numRPMS;
706         } else if (rc > 0) {
707             eiu->numFailed += rc;
708             if (rpmpsNumProblems(ps) > 0)
709                 rpmpsPrint(stderr, ps);
710         }
711         ps = rpmpsFree(ps);
712     }
713
714     if (eiu->numSRPMS && !stopInstall) {
715         if (eiu->sourceURL != NULL)
716         for (i = 0; i < eiu->numSRPMS; i++) {
717             if (eiu->sourceURL[i] == NULL) continue;
718             eiu->fd = Fopen(eiu->sourceURL[i], "r.ufdio");
719             if (eiu->fd == NULL || Ferror(eiu->fd)) {
720                 rpmMessage(RPMMESS_ERROR, _("cannot open file %s: %s\n"),
721                            eiu->sourceURL[i], Fstrerror(eiu->fd));
722                 if (eiu->fd != NULL) {
723                     xx = Fclose(eiu->fd);
724                     eiu->fd = NULL;
725                 }
726                 continue;
727             }
728
729             if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_TEST)) {
730                 eiu->rpmrc = rpmInstallSourcePackage(ts, eiu->fd, NULL, NULL);
731                 if (eiu->rpmrc != RPMRC_OK) eiu->numFailed++;
732             }
733
734             xx = Fclose(eiu->fd);
735             eiu->fd = NULL;
736         }
737     }
738
739 exit:
740     if (eiu->pkgURL != NULL)
741     for (i = 0; i < eiu->numPkgs; i++) {
742         if (eiu->pkgURL[i] == NULL) continue;
743         if (eiu->pkgState[i] == 1)
744             (void) Unlink(eiu->pkgURL[i]);
745         eiu->pkgURL[i] = _free(eiu->pkgURL[i]);
746     }
747     eiu->pkgState = _free(eiu->pkgState);
748     eiu->pkgURL = _free(eiu->pkgURL);
749     eiu->argv = _free(eiu->argv);
750
751     rpmtsEmpty(ts);
752
753     return eiu->numFailed;
754 }
755 /*@=bounds@*/
756
757 int rpmErase(rpmts ts, struct rpmInstallArguments_s * ia,
758                 const char ** argv)
759 {
760     int count;
761     const char ** arg;
762     int numFailed = 0;
763     int stopUninstall = 0;
764     int numPackages = 0;
765     rpmVSFlags vsflags, ovsflags;
766     rpmps ps;
767
768     if (argv == NULL) return 0;
769
770     vsflags = rpmExpandNumeric("%{?_vsflags_erase}");
771     if (ia->qva_flags & VERIFY_DIGEST)
772         vsflags |= _RPMVSF_NODIGESTS;
773     if (ia->qva_flags & VERIFY_SIGNATURE)
774         vsflags |= _RPMVSF_NOSIGNATURES;
775     if (ia->qva_flags & VERIFY_HDRCHK)
776         vsflags |= RPMVSF_NOHDRCHK;
777     ovsflags = rpmtsSetVSFlags(ts, vsflags);
778
779     if (rpmExpandNumeric("%{?_repackage_all_erasures}"))
780         ia->transFlags |= RPMTRANS_FLAG_REPACKAGE;
781
782     (void) rpmtsSetFlags(ts, ia->transFlags);
783
784 #ifdef  NOTYET  /* XXX no callbacks on erase yet */
785     {   int notifyFlags;
786         notifyFlags = ia->eraseInterfaceFlags | (rpmIsVerbose() ? INSTALL_LABEL : 0 );
787         xx = rpmtsSetNotifyCallback(ts,
788                         rpmShowProgress, (void *) ((long)notifyFlags)
789     }
790 #endif
791
792     ts->goal = TSM_ERASE;
793
794     for (arg = argv; *arg; arg++) {
795         rpmdbMatchIterator mi;
796
797         /* XXX HACK to get rpmdbFindByLabel out of the API */
798         mi = rpmtsInitIterator(ts, RPMDBI_LABEL, *arg, 0);
799         if (mi == NULL) {
800             rpmMessage(RPMMESS_ERROR, _("package %s is not installed\n"), *arg);
801             numFailed++;
802         } else {
803             Header h;   /* XXX iterator owns the reference */
804             count = 0;
805             while ((h = rpmdbNextIterator(mi)) != NULL) {
806                 unsigned int recOffset = rpmdbGetIteratorOffset(mi);
807
808                 if (!(count++ == 0 || (ia->eraseInterfaceFlags & UNINSTALL_ALLMATCHES))) {
809                     rpmMessage(RPMMESS_ERROR, _("\"%s\" specifies multiple packages\n"),
810                         *arg);
811                     numFailed++;
812                     /*@innerbreak@*/ break;
813                 }
814                 if (recOffset) {
815                     (void) rpmtsAddEraseElement(ts, h, recOffset);
816                     numPackages++;
817                 }
818             }
819         }
820         mi = rpmdbFreeIterator(mi);
821     }
822
823     if (numFailed) goto exit;
824
825     if (!(ia->eraseInterfaceFlags & UNINSTALL_NODEPS)) {
826
827         if (rpmtsCheck(ts)) {
828             numFailed = numPackages;
829             stopUninstall = 1;
830         }
831
832         ps = rpmtsProblems(ts);
833         if (!stopUninstall && rpmpsNumProblems(ps) > 0) {
834             rpmMessage(RPMMESS_ERROR, _("Failed dependencies:\n"));
835             rpmpsPrint(NULL, ps);
836             numFailed += numPackages;
837             stopUninstall = 1;
838         }
839         ps = rpmpsFree(ps);
840     }
841
842 #ifdef  NOTYET
843     if (!stopUninstall && !(ia->installInterfaceFlags & INSTALL_NOORDER)) {
844         if (rpmtsOrder(ts)) {
845             numFailed += numPackages;
846             stopUninstall = 1;
847         }
848     }
849 #endif
850
851     if (numPackages && !stopUninstall) {
852         (void) rpmtsSetFlags(ts, (rpmtsFlags(ts) | RPMTRANS_FLAG_REVERSE));
853
854         /* Drop added/available package indices and dependency sets. */
855         rpmtsClean(ts);
856
857         numPackages = rpmtsRun(ts, NULL, ia->probFilter & (RPMPROB_FILTER_DISKSPACE|RPMPROB_FILTER_DISKNODES));
858         ps = rpmtsProblems(ts);
859         if (rpmpsNumProblems(ps) > 0)
860             rpmpsPrint(NULL, ps);
861         numFailed += numPackages;
862         stopUninstall = 1;
863         ps = rpmpsFree(ps);
864     }
865
866 exit:
867     rpmtsEmpty(ts);
868
869     return numFailed;
870 }
871
872 int rpmInstallSource(rpmts ts, const char * arg,
873                 const char ** specFilePtr, const char ** cookie)
874 {
875     FD_t fd;
876     int rc;
877
878
879     fd = Fopen(arg, "r.ufdio");
880     if (fd == NULL || Ferror(fd)) {
881         rpmMessage(RPMMESS_ERROR, _("cannot open %s: %s\n"), arg, Fstrerror(fd));
882         if (fd != NULL) (void) Fclose(fd);
883         return 1;
884     }
885
886     if (rpmIsVerbose())
887         fprintf(stdout, _("Installing %s\n"), arg);
888
889     {
890         rpmVSFlags ovsflags =
891                 rpmtsSetVSFlags(ts, (rpmtsVSFlags(ts) | RPMVSF_NEEDPAYLOAD));
892         rpmRC rpmrc = rpmInstallSourcePackage(ts, fd, specFilePtr, cookie);
893         rc = (rpmrc == RPMRC_OK ? 0 : 1);
894         ovsflags = rpmtsSetVSFlags(ts, ovsflags);
895     }
896     if (rc != 0) {
897         rpmMessage(RPMMESS_ERROR, _("%s cannot be installed\n"), arg);
898         /*@-unqualifiedtrans@*/
899         if (specFilePtr && *specFilePtr)
900             *specFilePtr = _free(*specFilePtr);
901         if (cookie && *cookie)
902             *cookie = _free(*cookie);
903         /*@=unqualifiedtrans@*/
904     }
905
906     (void) Fclose(fd);
907
908     return rc;
909 }
910
911 /*@unchecked@*/
912 static int reverse = -1;
913
914 /**
915  */
916 static int IDTintcmp(const void * a, const void * b)
917         /*@*/
918 {
919     /*@-castexpose@*/
920     return ( reverse * (((IDT)a)->val.u32 - ((IDT)b)->val.u32) );
921     /*@=castexpose@*/
922 }
923
924 IDTX IDTXfree(IDTX idtx)
925 {
926     if (idtx) {
927         int i;
928         if (idtx->idt)
929         for (i = 0; i < idtx->nidt; i++) {
930             IDT idt = idtx->idt + i;
931             idt->h = headerFree(idt->h);
932             idt->key = _free(idt->key);
933         }
934         idtx->idt = _free(idtx->idt);
935         idtx = _free(idtx);
936     }
937     return NULL;
938 }
939
940 IDTX IDTXnew(void)
941 {
942     IDTX idtx = xcalloc(1, sizeof(*idtx));
943     idtx->delta = 10;
944     idtx->size = sizeof(*((IDT)0));
945     return idtx;
946 }
947
948 IDTX IDTXgrow(IDTX idtx, int need)
949 {
950     if (need < 0) return NULL;
951     if (idtx == NULL)
952         idtx = IDTXnew();
953     if (need == 0) return idtx;
954
955     if ((idtx->nidt + need) > idtx->alloced) {
956         while (need > 0) {
957             idtx->alloced += idtx->delta;
958             need -= idtx->delta;
959         }
960         idtx->idt = xrealloc(idtx->idt, (idtx->alloced * idtx->size) );
961     }
962     return idtx;
963 }
964
965 IDTX IDTXsort(IDTX idtx)
966 {
967     if (idtx != NULL && idtx->idt != NULL && idtx->nidt > 0)
968         qsort(idtx->idt, idtx->nidt, idtx->size, IDTintcmp);
969     return idtx;
970 }
971
972 IDTX IDTXload(rpmts ts, rpmTag tag)
973 {
974     IDTX idtx = NULL;
975     rpmdbMatchIterator mi;
976     HGE_t hge = (HGE_t) headerGetEntry;
977     Header h;
978
979     /*@-branchstate@*/
980     mi = rpmtsInitIterator(ts, tag, NULL, 0);
981 #ifdef  NOTYET
982     (void) rpmdbSetIteratorRE(mi, RPMTAG_NAME, RPMMIRE_DEFAULT, '!gpg-pubkey');
983 #endif
984     while ((h = rpmdbNextIterator(mi)) != NULL) {
985         rpmTagType type = RPM_NULL_TYPE;
986         int_32 count = 0;
987         int_32 * tidp;
988
989         tidp = NULL;
990         if (!hge(h, tag, &type, (void **)&tidp, &count) || tidp == NULL)
991             continue;
992
993         if (type == RPM_INT32_TYPE && (*tidp == 0 || *tidp == -1))
994             continue;
995
996         idtx = IDTXgrow(idtx, 1);
997         if (idtx == NULL)
998             continue;
999         if (idtx->idt == NULL)
1000             continue;
1001
1002         {   IDT idt;
1003             /*@-nullderef@*/
1004             idt = idtx->idt + idtx->nidt;
1005             /*@=nullderef@*/
1006             idt->h = headerLink(h);
1007             idt->key = NULL;
1008             idt->instance = rpmdbGetIteratorOffset(mi);
1009             idt->val.u32 = *tidp;
1010         }
1011         idtx->nidt++;
1012     }
1013     mi = rpmdbFreeIterator(mi);
1014     /*@=branchstate@*/
1015
1016     return IDTXsort(idtx);
1017 }
1018
1019 IDTX IDTXglob(rpmts ts, const char * globstr, rpmTag tag)
1020 {
1021     IDTX idtx = NULL;
1022     HGE_t hge = (HGE_t) headerGetEntry;
1023     Header h;
1024     int_32 * tidp;
1025     FD_t fd;
1026     const char ** av = NULL;
1027     int ac = 0;
1028     rpmRC rpmrc;
1029     int xx;
1030     int i;
1031
1032     av = NULL;  ac = 0;
1033     xx = rpmGlob(globstr, &ac, &av);
1034
1035     if (xx == 0)
1036     for (i = 0; i < ac; i++) {
1037         rpmTagType type;
1038         int_32 count;
1039         int isSource;
1040
1041         fd = Fopen(av[i], "r.ufdio");
1042         if (fd == NULL || Ferror(fd)) {
1043             rpmError(RPMERR_OPEN, _("open of %s failed: %s\n"), av[i],
1044                         Fstrerror(fd));
1045             if (fd != NULL) (void) Fclose(fd);
1046             continue;
1047         }
1048
1049         rpmrc = rpmReadPackageFile(ts, fd, av[i], &h);
1050         (void) Fclose(fd);
1051         switch (rpmrc) {
1052         default:
1053             goto bottom;
1054             /*@notreached@*/ /*@switchbreak@*/ break;
1055         case RPMRC_NOTTRUSTED:
1056         case RPMRC_NOKEY:
1057         case RPMRC_OK:
1058             isSource = headerIsEntry(h, RPMTAG_SOURCEPACKAGE);
1059             if (isSource)
1060                 goto bottom;
1061             /*@switchbreak@*/ break;
1062         }
1063
1064         tidp = NULL;
1065         /*@-branchstate@*/
1066         if (hge(h, tag, &type, (void **) &tidp, &count) && tidp != NULL) {
1067
1068             idtx = IDTXgrow(idtx, 1);
1069             if (idtx == NULL || idtx->idt == NULL)
1070                 goto bottom;
1071
1072             {   IDT idt;
1073                 idt = idtx->idt + idtx->nidt;
1074                 idt->h = headerLink(h);
1075                 idt->key = av[i];
1076                 av[i] = NULL;
1077                 idt->instance = 0;
1078                 idt->val.u32 = *tidp;
1079             }
1080             idtx->nidt++;
1081         }
1082         /*@=branchstate@*/
1083 bottom:
1084         h = headerFree(h);
1085     }
1086
1087     for (i = 0; i < ac; i++)
1088         av[i] = _free(av[i]);
1089     av = _free(av);     ac = 0;
1090
1091     return IDTXsort(idtx);
1092 }
1093
1094 /** @todo Transaction handling, more, needs work. */
1095 int rpmRollback(rpmts ts, struct rpmInstallArguments_s * ia, const char ** argv)
1096 {
1097     int ifmask= (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL|INSTALL_ERASE);
1098     unsigned thistid = 0xffffffff;
1099     unsigned prevtid;
1100     time_t tid;
1101     IDTX itids = NULL;
1102     IDTX rtids = NULL;
1103     IDT rp;
1104     int nrids = 0;
1105     IDT ip;
1106     int niids = 0;
1107     int rc = 0;
1108     int vsflags, ovsflags;
1109     int numAdded;
1110     int numRemoved;
1111     rpmps ps;
1112     int _unsafe_rollbacks = 0;
1113     rpmtransFlags transFlags = ia->transFlags;
1114
1115     if (argv != NULL && *argv != NULL) {
1116         rc = -1;
1117         goto exit;
1118     }
1119
1120     _unsafe_rollbacks = rpmExpandNumeric("%{?_unsafe_rollbacks}");
1121
1122     vsflags = rpmExpandNumeric("%{?_vsflags_erase}");
1123     if (ia->qva_flags & VERIFY_DIGEST)
1124         vsflags |= _RPMVSF_NODIGESTS;
1125     if (ia->qva_flags & VERIFY_SIGNATURE)
1126         vsflags |= _RPMVSF_NOSIGNATURES;
1127     if (ia->qva_flags & VERIFY_HDRCHK)
1128         vsflags |= RPMVSF_NOHDRCHK;
1129     vsflags |= RPMVSF_NEEDPAYLOAD;      /* XXX no legacy signatures */
1130     ovsflags = rpmtsSetVSFlags(ts, vsflags);
1131
1132     (void) rpmtsSetFlags(ts, transFlags);
1133
1134     /*  Make the transaction a rollback transaction.  In a rollback
1135      *  a best effort is what we want 
1136      */
1137     rpmtsSetType(ts, RPMTRANS_TYPE_ROLLBACK);
1138
1139     itids = IDTXload(ts, RPMTAG_INSTALLTID);
1140     if (itids != NULL) {
1141         ip = itids->idt;
1142         niids = itids->nidt;
1143     } else {
1144         ip = NULL;
1145         niids = 0;
1146     }
1147
1148     {   const char * globstr = rpmExpand("%{_repackage_dir}/*.rpm", NULL);
1149         if (globstr == NULL || *globstr == '%') {
1150             globstr = _free(globstr);
1151             rc = -1;
1152             goto exit;
1153         }
1154         rtids = IDTXglob(ts, globstr, RPMTAG_REMOVETID);
1155
1156         if (rtids != NULL) {
1157             rp = rtids->idt;
1158             nrids = rtids->nidt;
1159         } else {
1160             rp = NULL;
1161             nrids = 0;
1162         }
1163         globstr = _free(globstr);
1164     }
1165
1166     {   int notifyFlags, xx;
1167         notifyFlags = ia->installInterfaceFlags | (rpmIsVerbose() ? INSTALL_LABEL : 0 );
1168         xx = rpmtsSetNotifyCallback(ts,
1169                         rpmShowProgress, (void *) ((long)notifyFlags));
1170     }
1171
1172     /* Run transactions until rollback goal is achieved. */
1173     do {
1174         prevtid = thistid;
1175         rc = 0;
1176         rpmcliPackagesTotal = 0;
1177         numAdded = 0;
1178         numRemoved = 0;
1179         ia->installInterfaceFlags &= ~ifmask;
1180
1181         /* Find larger of the remaining install/erase transaction id's. */
1182         thistid = 0;
1183         if (ip != NULL && ip->val.u32 > thistid)
1184             thistid = ip->val.u32;
1185         if (rp != NULL && rp->val.u32 > thistid)
1186             thistid = rp->val.u32;
1187
1188         /* If we've achieved the rollback goal, then we're done. */
1189         if (thistid == 0 || thistid < ia->rbtid)
1190             break;
1191
1192         /* If we've reached the (configured) rollback goal, then we're done. */
1193         if (_unsafe_rollbacks && thistid <= _unsafe_rollbacks)
1194             break;
1195
1196         rpmtsEmpty(ts);
1197         (void) rpmtsSetFlags(ts, transFlags);
1198
1199         /* Install the previously erased packages for this transaction. */
1200         while (rp != NULL && rp->val.u32 == thistid) {
1201
1202             rpmMessage(RPMMESS_DEBUG, "\t+++ install %s\n",
1203                         (rp->key ? rp->key : "???"));
1204
1205 /*@-abstract@*/
1206             rc = rpmtsAddInstallElement(ts, rp->h, (fnpyKey)rp->key,
1207                                0, ia->relocations);
1208 /*@=abstract@*/
1209             if (rc != 0)
1210                 goto exit;
1211
1212             numAdded++;
1213             rpmcliPackagesTotal++;
1214             if (!(ia->installInterfaceFlags & ifmask))
1215                 ia->installInterfaceFlags |= INSTALL_UPGRADE;
1216
1217 #ifdef  NOTYET
1218             rp->h = headerFree(rp->h);
1219 #endif
1220             nrids--;
1221             if (nrids > 0)
1222                 rp++;
1223             else
1224                 rp = NULL;
1225         }
1226
1227         /* Erase the previously installed packages for this transaction. */
1228         while (ip != NULL && ip->val.u32 == thistid) {
1229
1230             rpmMessage(RPMMESS_DEBUG,
1231                         "\t--- erase h#%u\n", ip->instance);
1232
1233             rc = rpmtsAddEraseElement(ts, ip->h, ip->instance);
1234             if (rc != 0)
1235                 goto exit;
1236
1237             numRemoved++;
1238
1239             if (_unsafe_rollbacks)
1240                 rpmcliPackagesTotal++;
1241
1242             if (!(ia->installInterfaceFlags & ifmask)) {
1243                 ia->installInterfaceFlags |= INSTALL_ERASE;
1244                 (void) rpmtsSetFlags(ts, (transFlags | RPMTRANS_FLAG_REVERSE));
1245             }
1246
1247 #ifdef  NOTYET
1248             ip->instance = 0;
1249 #endif
1250             niids--;
1251             if (niids > 0)
1252                 ip++;
1253             else
1254                 ip = NULL;
1255         }
1256
1257         /* Anything to do? */
1258         if (rpmcliPackagesTotal <= 0)
1259             break;
1260
1261         tid = (time_t)thistid;
1262         rpmMessage(RPMMESS_NORMAL,
1263                 _("Rollback packages (+%d/-%d) to %-24.24s (0x%08x):\n"),
1264                         numAdded, numRemoved, ctime(&tid), tid);
1265
1266         rc = rpmtsCheck(ts);
1267         ps = rpmtsProblems(ts);
1268         if (rc != 0 && rpmpsNumProblems(ps) > 0) {
1269             rpmMessage(RPMMESS_ERROR, _("Failed dependencies:\n"));
1270             rpmpsPrint(NULL, ps);
1271             ps = rpmpsFree(ps);
1272             goto exit;
1273         }
1274         ps = rpmpsFree(ps);
1275
1276         rc = rpmtsOrder(ts);
1277         if (rc != 0)
1278             goto exit;
1279
1280         /* Drop added/available package indices and dependency sets. */
1281         rpmtsClean(ts);
1282
1283         rc = rpmtsRun(ts, NULL, (ia->probFilter|RPMPROB_FILTER_OLDPACKAGE));
1284         ps = rpmtsProblems(ts);
1285         if (rc > 0 && rpmpsNumProblems(ps) > 0)
1286             rpmpsPrint(stderr, ps);
1287         ps = rpmpsFree(ps);
1288         if (rc)
1289             goto exit;
1290
1291         /* Clean up after successful rollback. */
1292         if (rtids && !rpmIsDebug()) {
1293             int i;
1294             rpmMessage(RPMMESS_NORMAL, _("Cleaning up repackaged packages:\n"));
1295             if (rtids->idt)
1296             for (i = 0; i < rtids->nidt; i++) {
1297                 IDT rrp = rtids->idt + i;
1298                 if (rrp->val.u32 != thistid)
1299                     /*@innercontinue@*/ continue;
1300                 if (rrp->key) { /* XXX can't happen */
1301                     rpmMessage(RPMMESS_NORMAL, _("\tRemoving %s:\n"), rrp->key);
1302                     (void) unlink(rrp->key);    /* XXX: Should check rc??? */
1303                 }
1304             }
1305         }
1306
1307
1308     } while (1);
1309
1310 exit:
1311     rtids = IDTXfree(rtids);
1312     itids = IDTXfree(itids);
1313
1314     rpmtsEmpty(ts);
1315     (void) rpmtsSetFlags(ts, transFlags);
1316
1317     return rc;
1318 }