Flush changes from rpm-4_3 branch.
[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_FTP:
420         case URL_IS_HTTP:
421         {   const char *tfn;
422
423             if (rpmIsVerbose())
424                 fprintf(stdout, _("Retrieving %s\n"), fileURL);
425
426             {   char tfnbuf[64];
427                 const char * rootDir = rpmtsRootDir(ts);
428                 if (!(rootDir && * rootDir))
429                     rootDir = "";
430                 strcpy(tfnbuf, "rpm-xfer.XXXXXX");
431                 (void) mktemp(tfnbuf);
432                 tfn = rpmGenPath(rootDir, "%{_tmppath}/", tfnbuf);
433             }
434
435             /* XXX undefined %{name}/%{version}/%{release} here */
436             /* XXX %{_tmpdir} does not exist */
437             rpmMessage(RPMMESS_DEBUG, _(" ... as %s\n"), tfn);
438             rc = urlGetFile(fileURL, tfn);
439             if (rc < 0) {
440                 rpmMessage(RPMMESS_ERROR,
441                         _("skipping %s - transfer failed - %s\n"),
442                         fileURL, ftpStrerror(rc));
443                 eiu->numFailed++;
444                 eiu->pkgURL[eiu->pkgx] = NULL;
445                 tfn = _free(tfn);
446                 /*@switchbreak@*/ break;
447             }
448             eiu->pkgState[eiu->pkgx] = 1;
449             eiu->pkgURL[eiu->pkgx] = tfn;
450             eiu->pkgx++;
451         }   /*@switchbreak@*/ break;
452         case URL_IS_PATH:
453         default:
454             eiu->pkgURL[eiu->pkgx] = fileURL;
455             fileURL = NULL;
456             eiu->pkgx++;
457             /*@switchbreak@*/ break;
458         }
459     }
460     fileURL = _free(fileURL);
461
462     if (eiu->numFailed) goto exit;
463
464     /* Continue processing file arguments, building transaction set. */
465     for (eiu->fnp = eiu->pkgURL+eiu->prevx;
466          *eiu->fnp != NULL;
467          eiu->fnp++, eiu->prevx++)
468     {
469         const char * fileName;
470
471         rpmMessage(RPMMESS_DEBUG, "============== %s\n", *eiu->fnp);
472         (void) urlPath(*eiu->fnp, &fileName);
473
474         /* Try to read the header from a package file. */
475         eiu->fd = Fopen(*eiu->fnp, "r.ufdio");
476         if (eiu->fd == NULL || Ferror(eiu->fd)) {
477             rpmError(RPMERR_OPEN, _("open of %s failed: %s\n"), *eiu->fnp,
478                         Fstrerror(eiu->fd));
479             if (eiu->fd != NULL) {
480                 xx = Fclose(eiu->fd);
481                 eiu->fd = NULL;
482             }
483             eiu->numFailed++; *eiu->fnp = NULL;
484             continue;
485         }
486
487         /* Read the header, verifying signatures (if present). */
488         tvsflags = rpmtsSetVSFlags(ts, vsflags);
489         eiu->rpmrc = rpmReadPackageFile(ts, eiu->fd, *eiu->fnp, &eiu->h);
490         tvsflags = rpmtsSetVSFlags(ts, tvsflags);
491         xx = Fclose(eiu->fd);
492         eiu->fd = NULL;
493
494         switch (eiu->rpmrc) {
495         case RPMRC_FAIL:
496             rpmMessage(RPMMESS_ERROR, _("%s cannot be installed\n"), *eiu->fnp);
497             eiu->numFailed++; *eiu->fnp = NULL;
498             continue;
499             /*@notreached@*/ /*@switchbreak@*/ break;
500         case RPMRC_NOTFOUND:
501             goto maybe_manifest;
502             /*@notreached@*/ /*@switchbreak@*/ break;
503         case RPMRC_NOTTRUSTED:
504         case RPMRC_NOKEY:
505         case RPMRC_OK:
506         default:
507             /*@switchbreak@*/ break;
508         }
509
510         eiu->isSource = headerIsEntry(eiu->h, RPMTAG_SOURCEPACKAGE);
511
512         if (eiu->isSource) {
513             rpmMessage(RPMMESS_DEBUG, _("\tadded source package [%d]\n"),
514                 eiu->numSRPMS);
515             eiu->sourceURL = xrealloc(eiu->sourceURL,
516                                 (eiu->numSRPMS + 2) * sizeof(*eiu->sourceURL));
517             eiu->sourceURL[eiu->numSRPMS] = *eiu->fnp;
518             *eiu->fnp = NULL;
519             eiu->numSRPMS++;
520             eiu->sourceURL[eiu->numSRPMS] = NULL;
521             continue;
522         }
523
524         if (eiu->relocations) {
525             const char ** paths;
526             int pft;
527             int c;
528
529             if (headerGetEntry(eiu->h, RPMTAG_PREFIXES, &pft,
530                                        (void **) &paths, &c) && (c == 1))
531             {
532                 eiu->relocations->oldPath = xstrdup(paths[0]);
533                 paths = headerFreeData(paths, pft);
534             } else {
535                 const char * name;
536                 xx = headerNVR(eiu->h, &name, NULL, NULL);
537                 rpmMessage(RPMMESS_ERROR,
538                                _("package %s is not relocatable\n"), name);
539                 eiu->numFailed++;
540                 goto exit;
541                 /*@notreached@*/
542             }
543         }
544
545         /* On --freshen, verify package is installed and newer */
546         if (ia->installInterfaceFlags & INSTALL_FRESHEN) {
547             rpmdbMatchIterator mi;
548             const char * name;
549             Header oldH;
550             int count;
551
552             xx = headerNVR(eiu->h, &name, NULL, NULL);
553             mi = rpmtsInitIterator(ts, RPMTAG_NAME, name, 0);
554             count = rpmdbGetIteratorCount(mi);
555             while ((oldH = rpmdbNextIterator(mi)) != NULL) {
556                 if (rpmVersionCompare(oldH, eiu->h) < 0)
557                     /*@innercontinue@*/ continue;
558                 /* same or newer package already installed */
559                 count = 0;
560                 /*@innerbreak@*/ break;
561             }
562             mi = rpmdbFreeIterator(mi);
563             if (count == 0) {
564                 eiu->h = headerFree(eiu->h);
565                 continue;
566             }
567             /* Package is newer than those currently installed. */
568         }
569
570         /*@-abstract@*/
571         rc = rpmtsAddInstallElement(ts, eiu->h, (fnpyKey)fileName,
572                         (ia->installInterfaceFlags & INSTALL_UPGRADE) != 0,
573                         relocations);
574         /*@=abstract@*/
575
576         /* XXX reference held by transaction set */
577         eiu->h = headerFree(eiu->h);
578         if (eiu->relocations)
579             eiu->relocations->oldPath = _free(eiu->relocations->oldPath);
580
581         switch(rc) {
582         case 0:
583             rpmMessage(RPMMESS_DEBUG, _("\tadded binary package [%d]\n"),
584                         eiu->numRPMS);
585             /*@switchbreak@*/ break;
586         case 1:
587             rpmMessage(RPMMESS_ERROR,
588                             _("error reading from file %s\n"), *eiu->fnp);
589             eiu->numFailed++;
590             goto exit;
591             /*@notreached@*/ /*@switchbreak@*/ break;
592         case 2:
593             rpmMessage(RPMMESS_ERROR,
594                             _("file %s requires a newer version of RPM\n"),
595                             *eiu->fnp);
596             eiu->numFailed++;
597             goto exit;
598             /*@notreached@*/ /*@switchbreak@*/ break;
599         }
600
601         eiu->numRPMS++;
602         continue;
603
604 maybe_manifest:
605         /* Try to read a package manifest. */
606         eiu->fd = Fopen(*eiu->fnp, "r.fpio");
607         if (eiu->fd == NULL || Ferror(eiu->fd)) {
608             rpmError(RPMERR_OPEN, _("open of %s failed: %s\n"), *eiu->fnp,
609                         Fstrerror(eiu->fd));
610             if (eiu->fd != NULL) {
611                 xx = Fclose(eiu->fd);
612                 eiu->fd = NULL;
613             }
614             eiu->numFailed++; *eiu->fnp = NULL;
615             break;
616         }
617
618         /* Read list of packages from manifest. */
619 /*@-nullstate@*/ /* FIX: *eiu->argv can be NULL */
620         rc = rpmReadPackageManifest(eiu->fd, &eiu->argc, &eiu->argv);
621 /*@=nullstate@*/
622         if (rc != RPMRC_OK)
623             rpmError(RPMERR_MANIFEST, _("%s: not an rpm package (or package manifest): %s\n"),
624                         *eiu->fnp, Fstrerror(eiu->fd));
625         xx = Fclose(eiu->fd);
626         eiu->fd = NULL;
627
628         /* If successful, restart the query loop. */
629         if (rc == RPMRC_OK) {
630             eiu->prevx++;
631             goto restart;
632         }
633
634         eiu->numFailed++; *eiu->fnp = NULL;
635         break;
636     }
637
638     rpmMessage(RPMMESS_DEBUG, _("found %d source and %d binary packages\n"),
639                 eiu->numSRPMS, eiu->numRPMS);
640
641     if (eiu->numFailed) goto exit;
642
643     if (eiu->numRPMS && !(ia->installInterfaceFlags & INSTALL_NODEPS)) {
644
645         if (rpmtsCheck(ts)) {
646             eiu->numFailed = eiu->numPkgs;
647             stopInstall = 1;
648         }
649
650         ps = rpmtsProblems(ts);
651         if (!stopInstall && rpmpsNumProblems(ps) > 0) {
652             rpmMessage(RPMMESS_ERROR, _("Failed dependencies:\n"));
653             rpmpsPrint(NULL, ps);
654             eiu->numFailed = eiu->numPkgs;
655             stopInstall = 1;
656
657             /*@-branchstate@*/
658             if (ts->suggests != NULL && ts->nsuggests > 0) {
659                 rpmMessage(RPMMESS_NORMAL, _("    Suggested resolutions:\n"));
660                 for (i = 0; i < ts->nsuggests; i++) {
661                     const char * str = ts->suggests[i];
662
663                     if (str == NULL)
664                         break;
665
666                     rpmMessage(RPMMESS_NORMAL, "\t%s\n", str);
667                 
668                     ts->suggests[i] = NULL;
669                     str = _free(str);
670                 }
671                 ts->suggests = _free(ts->suggests);
672             }
673             /*@=branchstate@*/
674         }
675         ps = rpmpsFree(ps);
676     }
677
678     if (eiu->numRPMS && !(ia->installInterfaceFlags & INSTALL_NOORDER)) {
679         if (rpmtsOrder(ts)) {
680             eiu->numFailed = eiu->numPkgs;
681             stopInstall = 1;
682         }
683     }
684
685     if (eiu->numRPMS && !stopInstall) {
686
687         rpmcliPackagesTotal += eiu->numSRPMS;
688
689         rpmMessage(RPMMESS_DEBUG, _("installing binary packages\n"));
690
691         /* Drop added/available package indices and dependency sets. */
692         rpmtsClean(ts);
693
694         rc = rpmtsRun(ts, NULL, probFilter);
695         ps = rpmtsProblems(ts);
696
697         if (rc < 0) {
698             eiu->numFailed += eiu->numRPMS;
699         } else if (rc > 0) {
700             eiu->numFailed += rc;
701             if (rpmpsNumProblems(ps) > 0)
702                 rpmpsPrint(stderr, ps);
703         }
704         ps = rpmpsFree(ps);
705     }
706
707     if (eiu->numSRPMS && !stopInstall) {
708         if (eiu->sourceURL != NULL)
709         for (i = 0; i < eiu->numSRPMS; i++) {
710             if (eiu->sourceURL[i] == NULL) continue;
711             eiu->fd = Fopen(eiu->sourceURL[i], "r.ufdio");
712             if (eiu->fd == NULL || Ferror(eiu->fd)) {
713                 rpmMessage(RPMMESS_ERROR, _("cannot open file %s: %s\n"),
714                            eiu->sourceURL[i], Fstrerror(eiu->fd));
715                 if (eiu->fd != NULL) {
716                     xx = Fclose(eiu->fd);
717                     eiu->fd = NULL;
718                 }
719                 continue;
720             }
721
722             if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_TEST)) {
723                 eiu->rpmrc = rpmInstallSourcePackage(ts, eiu->fd, NULL, NULL);
724                 if (eiu->rpmrc != RPMRC_OK) eiu->numFailed++;
725             }
726
727             xx = Fclose(eiu->fd);
728             eiu->fd = NULL;
729         }
730     }
731
732 exit:
733     if (eiu->pkgURL != NULL)
734     for (i = 0; i < eiu->numPkgs; i++) {
735         if (eiu->pkgURL[i] == NULL) continue;
736         if (eiu->pkgState[i] == 1)
737             (void) Unlink(eiu->pkgURL[i]);
738         eiu->pkgURL[i] = _free(eiu->pkgURL[i]);
739     }
740     eiu->pkgState = _free(eiu->pkgState);
741     eiu->pkgURL = _free(eiu->pkgURL);
742     eiu->argv = _free(eiu->argv);
743
744     rpmtsEmpty(ts);
745
746     return eiu->numFailed;
747 }
748 /*@=bounds@*/
749
750 int rpmErase(rpmts ts, struct rpmInstallArguments_s * ia,
751                 const char ** argv)
752 {
753     int count;
754     const char ** arg;
755     int numFailed = 0;
756     int stopUninstall = 0;
757     int numPackages = 0;
758     rpmVSFlags vsflags, ovsflags;
759     rpmps ps;
760
761     if (argv == NULL) return 0;
762
763     vsflags = rpmExpandNumeric("%{?_vsflags_erase}");
764     if (ia->qva_flags & VERIFY_DIGEST)
765         vsflags |= _RPMVSF_NODIGESTS;
766     if (ia->qva_flags & VERIFY_SIGNATURE)
767         vsflags |= _RPMVSF_NOSIGNATURES;
768     if (ia->qva_flags & VERIFY_HDRCHK)
769         vsflags |= RPMVSF_NOHDRCHK;
770     ovsflags = rpmtsSetVSFlags(ts, vsflags);
771
772     if (rpmExpandNumeric("%{?_repackage_all_erasures}"))
773         ia->transFlags |= RPMTRANS_FLAG_REPACKAGE;
774
775     (void) rpmtsSetFlags(ts, ia->transFlags);
776
777 #ifdef  NOTYET  /* XXX no callbacks on erase yet */
778     {   int notifyFlags;
779         notifyFlags = ia->eraseInterfaceFlags | (rpmIsVerbose() ? INSTALL_LABEL : 0 );
780         xx = rpmtsSetNotifyCallback(ts,
781                         rpmShowProgress, (void *) ((long)notifyFlags)
782     }
783 #endif
784
785     ts->goal = TSM_ERASE;
786
787     for (arg = argv; *arg; arg++) {
788         rpmdbMatchIterator mi;
789
790         /* XXX HACK to get rpmdbFindByLabel out of the API */
791         mi = rpmtsInitIterator(ts, RPMDBI_LABEL, *arg, 0);
792         if (mi == NULL) {
793             rpmMessage(RPMMESS_ERROR, _("package %s is not installed\n"), *arg);
794             numFailed++;
795         } else {
796             Header h;   /* XXX iterator owns the reference */
797             count = 0;
798             while ((h = rpmdbNextIterator(mi)) != NULL) {
799                 unsigned int recOffset = rpmdbGetIteratorOffset(mi);
800
801                 if (!(count++ == 0 || (ia->eraseInterfaceFlags & UNINSTALL_ALLMATCHES))) {
802                     rpmMessage(RPMMESS_ERROR, _("\"%s\" specifies multiple packages\n"),
803                         *arg);
804                     numFailed++;
805                     /*@innerbreak@*/ break;
806                 }
807                 if (recOffset) {
808                     (void) rpmtsAddEraseElement(ts, h, recOffset);
809                     numPackages++;
810                 }
811             }
812         }
813         mi = rpmdbFreeIterator(mi);
814     }
815
816     if (numFailed) goto exit;
817
818     if (!(ia->eraseInterfaceFlags & UNINSTALL_NODEPS)) {
819
820         if (rpmtsCheck(ts)) {
821             numFailed = numPackages;
822             stopUninstall = 1;
823         }
824
825         ps = rpmtsProblems(ts);
826         if (!stopUninstall && rpmpsNumProblems(ps) > 0) {
827             rpmMessage(RPMMESS_ERROR, _("Failed dependencies:\n"));
828             rpmpsPrint(NULL, ps);
829             numFailed += numPackages;
830             stopUninstall = 1;
831         }
832         ps = rpmpsFree(ps);
833     }
834
835 #ifdef  NOTYET
836     if (!stopUninstall && !(ia->installInterfaceFlags & INSTALL_NOORDER)) {
837         if (rpmtsOrder(ts)) {
838             numFailed += numPackages;
839             stopUninstall = 1;
840         }
841     }
842 #endif
843
844     if (!stopUninstall) {
845         (void) rpmtsSetFlags(ts, (rpmtsFlags(ts) | RPMTRANS_FLAG_REVERSE));
846
847         /* Drop added/available package indices and dependency sets. */
848         rpmtsClean(ts);
849
850         numPackages = rpmtsRun(ts, NULL, 0);
851         ps = rpmtsProblems(ts);
852         if (rpmpsNumProblems(ps) > 0)
853             rpmpsPrint(NULL, ps);
854         numFailed += numPackages;
855         stopUninstall = 1;
856         ps = rpmpsFree(ps);
857     }
858
859 exit:
860     rpmtsEmpty(ts);
861
862     return numFailed;
863 }
864
865 int rpmInstallSource(rpmts ts, const char * arg,
866                 const char ** specFilePtr, const char ** cookie)
867 {
868     FD_t fd;
869     int rc;
870
871
872     fd = Fopen(arg, "r.ufdio");
873     if (fd == NULL || Ferror(fd)) {
874         rpmMessage(RPMMESS_ERROR, _("cannot open %s: %s\n"), arg, Fstrerror(fd));
875         if (fd != NULL) (void) Fclose(fd);
876         return 1;
877     }
878
879     if (rpmIsVerbose())
880         fprintf(stdout, _("Installing %s\n"), arg);
881
882     {
883         rpmVSFlags ovsflags =
884                 rpmtsSetVSFlags(ts, (rpmtsVSFlags(ts) | RPMVSF_NEEDPAYLOAD));
885         rpmRC rpmrc = rpmInstallSourcePackage(ts, fd, specFilePtr, cookie);
886         rc = (rpmrc == RPMRC_OK ? 0 : 1);
887         ovsflags = rpmtsSetVSFlags(ts, ovsflags);
888     }
889     if (rc != 0) {
890         rpmMessage(RPMMESS_ERROR, _("%s cannot be installed\n"), arg);
891         /*@-unqualifiedtrans@*/
892         if (specFilePtr && *specFilePtr)
893             *specFilePtr = _free(*specFilePtr);
894         if (cookie && *cookie)
895             *cookie = _free(*cookie);
896         /*@=unqualifiedtrans@*/
897     }
898
899     (void) Fclose(fd);
900
901     return rc;
902 }
903
904 /*@unchecked@*/
905 static int reverse = -1;
906
907 /**
908  */
909 static int IDTintcmp(const void * a, const void * b)
910         /*@*/
911 {
912     /*@-castexpose@*/
913     return ( reverse * (((IDT)a)->val.u32 - ((IDT)b)->val.u32) );
914     /*@=castexpose@*/
915 }
916
917 IDTX IDTXfree(IDTX idtx)
918 {
919     if (idtx) {
920         int i;
921         if (idtx->idt)
922         for (i = 0; i < idtx->nidt; i++) {
923             IDT idt = idtx->idt + i;
924             idt->h = headerFree(idt->h);
925             idt->key = _free(idt->key);
926         }
927         idtx->idt = _free(idtx->idt);
928         idtx = _free(idtx);
929     }
930     return NULL;
931 }
932
933 IDTX IDTXnew(void)
934 {
935     IDTX idtx = xcalloc(1, sizeof(*idtx));
936     idtx->delta = 10;
937     idtx->size = sizeof(*((IDT)0));
938     return idtx;
939 }
940
941 IDTX IDTXgrow(IDTX idtx, int need)
942 {
943     if (need < 0) return NULL;
944     if (idtx == NULL)
945         idtx = IDTXnew();
946     if (need == 0) return idtx;
947
948     if ((idtx->nidt + need) > idtx->alloced) {
949         while (need > 0) {
950             idtx->alloced += idtx->delta;
951             need -= idtx->delta;
952         }
953         idtx->idt = xrealloc(idtx->idt, (idtx->alloced * idtx->size) );
954     }
955     return idtx;
956 }
957
958 IDTX IDTXsort(IDTX idtx)
959 {
960     if (idtx != NULL && idtx->idt != NULL && idtx->nidt > 0)
961         qsort(idtx->idt, idtx->nidt, idtx->size, IDTintcmp);
962     return idtx;
963 }
964
965 IDTX IDTXload(rpmts ts, rpmTag tag)
966 {
967     IDTX idtx = NULL;
968     rpmdbMatchIterator mi;
969     HGE_t hge = (HGE_t) headerGetEntry;
970     Header h;
971
972     /*@-branchstate@*/
973     mi = rpmtsInitIterator(ts, tag, NULL, 0);
974 #ifdef  NOTYET
975     (void) rpmdbSetIteratorRE(mi, RPMTAG_NAME, RPMMIRE_DEFAULT, '!gpg-pubkey');
976 #endif
977     while ((h = rpmdbNextIterator(mi)) != NULL) {
978         rpmTagType type = RPM_NULL_TYPE;
979         int_32 count = 0;
980         int_32 * tidp;
981
982         tidp = NULL;
983         if (!hge(h, tag, &type, (void **)&tidp, &count) || tidp == NULL)
984             continue;
985
986         if (type == RPM_INT32_TYPE && (*tidp == 0 || *tidp == -1))
987             continue;
988
989         idtx = IDTXgrow(idtx, 1);
990         if (idtx == NULL)
991             continue;
992         if (idtx->idt == NULL)
993             continue;
994
995         {   IDT idt;
996             /*@-nullderef@*/
997             idt = idtx->idt + idtx->nidt;
998             /*@=nullderef@*/
999             idt->h = headerLink(h);
1000             idt->key = NULL;
1001             idt->instance = rpmdbGetIteratorOffset(mi);
1002             idt->val.u32 = *tidp;
1003         }
1004         idtx->nidt++;
1005     }
1006     mi = rpmdbFreeIterator(mi);
1007     /*@=branchstate@*/
1008
1009     return IDTXsort(idtx);
1010 }
1011
1012 IDTX IDTXglob(rpmts ts, const char * globstr, rpmTag tag)
1013 {
1014     IDTX idtx = NULL;
1015     HGE_t hge = (HGE_t) headerGetEntry;
1016     Header h;
1017     int_32 * tidp;
1018     FD_t fd;
1019     const char ** av = NULL;
1020     int ac = 0;
1021     rpmRC rpmrc;
1022     int xx;
1023     int i;
1024
1025     av = NULL;  ac = 0;
1026     xx = rpmGlob(globstr, &ac, &av);
1027
1028     if (xx == 0)
1029     for (i = 0; i < ac; i++) {
1030         rpmTagType type;
1031         int_32 count;
1032         int isSource;
1033
1034         fd = Fopen(av[i], "r.ufdio");
1035         if (fd == NULL || Ferror(fd)) {
1036             rpmError(RPMERR_OPEN, _("open of %s failed: %s\n"), av[i],
1037                         Fstrerror(fd));
1038             if (fd != NULL) (void) Fclose(fd);
1039             continue;
1040         }
1041
1042         rpmrc = rpmReadPackageFile(ts, fd, av[i], &h);
1043         (void) Fclose(fd);
1044         switch (rpmrc) {
1045         default:
1046             goto bottom;
1047             /*@notreached@*/ /*@switchbreak@*/ break;
1048         case RPMRC_NOTTRUSTED:
1049         case RPMRC_NOKEY:
1050         case RPMRC_OK:
1051             isSource = headerIsEntry(h, RPMTAG_SOURCEPACKAGE);
1052             if (isSource)
1053                 goto bottom;
1054             /*@switchbreak@*/ break;
1055         }
1056
1057         tidp = NULL;
1058         /*@-branchstate@*/
1059         if (hge(h, tag, &type, (void **) &tidp, &count) && tidp != NULL) {
1060
1061             idtx = IDTXgrow(idtx, 1);
1062             if (idtx == NULL || idtx->idt == NULL)
1063                 goto bottom;
1064
1065             {   IDT idt;
1066                 idt = idtx->idt + idtx->nidt;
1067                 idt->h = headerLink(h);
1068                 idt->key = av[i];
1069                 av[i] = NULL;
1070                 idt->instance = 0;
1071                 idt->val.u32 = *tidp;
1072             }
1073             idtx->nidt++;
1074         }
1075         /*@=branchstate@*/
1076 bottom:
1077         h = headerFree(h);
1078     }
1079
1080     for (i = 0; i < ac; i++)
1081         av[i] = _free(av[i]);
1082     av = _free(av);     ac = 0;
1083
1084     return IDTXsort(idtx);
1085 }
1086
1087 /** @todo Transaction handling, more, needs work. */
1088 int rpmRollback(rpmts ts, struct rpmInstallArguments_s * ia, const char ** argv)
1089 {
1090     int ifmask= (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL|INSTALL_ERASE);
1091     unsigned thistid = 0xffffffff;
1092     unsigned prevtid;
1093     time_t tid;
1094     IDTX itids = NULL;
1095     IDTX rtids = NULL;
1096     IDT rp;
1097     int nrids = 0;
1098     IDT ip;
1099     int niids = 0;
1100     int rc = 0;
1101     int vsflags, ovsflags;
1102     int numAdded;
1103     int numRemoved;
1104     rpmps ps;
1105     int _unsafe_rollbacks = 0;
1106     rpmtransFlags transFlags = ia->transFlags;
1107
1108     if (argv != NULL && *argv != NULL) {
1109         rc = -1;
1110         goto exit;
1111     }
1112
1113     _unsafe_rollbacks = rpmExpandNumeric("%{?_unsafe_rollbacks}");
1114
1115     vsflags = rpmExpandNumeric("%{?_vsflags_erase}");
1116     if (ia->qva_flags & VERIFY_DIGEST)
1117         vsflags |= _RPMVSF_NODIGESTS;
1118     if (ia->qva_flags & VERIFY_SIGNATURE)
1119         vsflags |= _RPMVSF_NOSIGNATURES;
1120     if (ia->qva_flags & VERIFY_HDRCHK)
1121         vsflags |= RPMVSF_NOHDRCHK;
1122     vsflags |= RPMVSF_NEEDPAYLOAD;      /* XXX no legacy signatures */
1123     ovsflags = rpmtsSetVSFlags(ts, vsflags);
1124
1125     (void) rpmtsSetFlags(ts, transFlags);
1126
1127     /*  Make the transaction a rollback transaction.  In a rollback
1128      *  a best effort is what we want 
1129      */
1130     rpmtsSetType(ts, RPMTRANS_TYPE_ROLLBACK);
1131
1132     itids = IDTXload(ts, RPMTAG_INSTALLTID);
1133     if (itids != NULL) {
1134         ip = itids->idt;
1135         niids = itids->nidt;
1136     } else {
1137         ip = NULL;
1138         niids = 0;
1139     }
1140
1141     {   const char * globstr = rpmExpand("%{_repackage_dir}/*.rpm", NULL);
1142         if (globstr == NULL || *globstr == '%') {
1143             globstr = _free(globstr);
1144             rc = -1;
1145             goto exit;
1146         }
1147         rtids = IDTXglob(ts, globstr, RPMTAG_REMOVETID);
1148
1149         if (rtids != NULL) {
1150             rp = rtids->idt;
1151             nrids = rtids->nidt;
1152         } else {
1153             rp = NULL;
1154             nrids = 0;
1155         }
1156         globstr = _free(globstr);
1157     }
1158
1159     {   int notifyFlags, xx;
1160         notifyFlags = ia->installInterfaceFlags | (rpmIsVerbose() ? INSTALL_LABEL : 0 );
1161         xx = rpmtsSetNotifyCallback(ts,
1162                         rpmShowProgress, (void *) ((long)notifyFlags));
1163     }
1164
1165     /* Run transactions until rollback goal is achieved. */
1166     do {
1167         prevtid = thistid;
1168         rc = 0;
1169         rpmcliPackagesTotal = 0;
1170         numAdded = 0;
1171         numRemoved = 0;
1172         ia->installInterfaceFlags &= ~ifmask;
1173
1174         /* Find larger of the remaining install/erase transaction id's. */
1175         thistid = 0;
1176         if (ip != NULL && ip->val.u32 > thistid)
1177             thistid = ip->val.u32;
1178         if (rp != NULL && rp->val.u32 > thistid)
1179             thistid = rp->val.u32;
1180
1181         /* If we've achieved the rollback goal, then we're done. */
1182         if (thistid == 0 || thistid < ia->rbtid)
1183             break;
1184
1185         /* If we've reached the (configured) rollback goal, then we're done. */
1186         if (_unsafe_rollbacks && thistid <= _unsafe_rollbacks)
1187             break;
1188
1189         rpmtsEmpty(ts);
1190         (void) rpmtsSetFlags(ts, transFlags);
1191
1192         /* Install the previously erased packages for this transaction. */
1193         while (rp != NULL && rp->val.u32 == thistid) {
1194
1195             rpmMessage(RPMMESS_DEBUG, "\t+++ install %s\n",
1196                         (rp->key ? rp->key : "???"));
1197
1198 /*@-abstract@*/
1199             rc = rpmtsAddInstallElement(ts, rp->h, (fnpyKey)rp->key,
1200                                0, ia->relocations);
1201 /*@=abstract@*/
1202             if (rc != 0)
1203                 goto exit;
1204
1205             numAdded++;
1206             rpmcliPackagesTotal++;
1207             if (!(ia->installInterfaceFlags & ifmask))
1208                 ia->installInterfaceFlags |= INSTALL_UPGRADE;
1209
1210 #ifdef  NOTYET
1211             rp->h = headerFree(rp->h);
1212 #endif
1213             nrids--;
1214             if (nrids > 0)
1215                 rp++;
1216             else
1217                 rp = NULL;
1218         }
1219
1220         /* Erase the previously installed packages for this transaction. */
1221         while (ip != NULL && ip->val.u32 == thistid) {
1222
1223             rpmMessage(RPMMESS_DEBUG,
1224                         "\t--- erase h#%u\n", ip->instance);
1225
1226             rc = rpmtsAddEraseElement(ts, ip->h, ip->instance);
1227             if (rc != 0)
1228                 goto exit;
1229
1230             numRemoved++;
1231
1232             if (_unsafe_rollbacks)
1233                 rpmcliPackagesTotal++;
1234
1235             if (!(ia->installInterfaceFlags & ifmask)) {
1236                 ia->installInterfaceFlags |= INSTALL_ERASE;
1237                 (void) rpmtsSetFlags(ts, (transFlags | RPMTRANS_FLAG_REVERSE));
1238             }
1239
1240 #ifdef  NOTYET
1241             ip->instance = 0;
1242 #endif
1243             niids--;
1244             if (niids > 0)
1245                 ip++;
1246             else
1247                 ip = NULL;
1248         }
1249
1250         /* Anything to do? */
1251         if (rpmcliPackagesTotal <= 0)
1252             break;
1253
1254         tid = (time_t)thistid;
1255         rpmMessage(RPMMESS_NORMAL,
1256                 _("Rollback packages (+%d/-%d) to %-24.24s (0x%08x):\n"),
1257                         numAdded, numRemoved, ctime(&tid), tid);
1258
1259         rc = rpmtsCheck(ts);
1260         ps = rpmtsProblems(ts);
1261         if (rc != 0 && rpmpsNumProblems(ps) > 0) {
1262             rpmMessage(RPMMESS_ERROR, _("Failed dependencies:\n"));
1263             rpmpsPrint(NULL, ps);
1264             ps = rpmpsFree(ps);
1265             goto exit;
1266         }
1267         ps = rpmpsFree(ps);
1268
1269         rc = rpmtsOrder(ts);
1270         if (rc != 0)
1271             goto exit;
1272
1273         /* Drop added/available package indices and dependency sets. */
1274         rpmtsClean(ts);
1275
1276         rc = rpmtsRun(ts, NULL, (ia->probFilter|RPMPROB_FILTER_OLDPACKAGE));
1277         ps = rpmtsProblems(ts);
1278         if (rc > 0 && rpmpsNumProblems(ps) > 0)
1279             rpmpsPrint(stderr, ps);
1280         ps = rpmpsFree(ps);
1281         if (rc)
1282             goto exit;
1283
1284         /* Clean up after successful rollback. */
1285         if (rtids && !rpmIsDebug()) {
1286             int i;
1287             rpmMessage(RPMMESS_NORMAL, _("Cleaning up repackaged packages:\n"));
1288             if (rtids->idt)
1289             for (i = 0; i < rtids->nidt; i++) {
1290                 IDT rrp = rtids->idt + i;
1291                 if (rrp->val.u32 != thistid)
1292                     /*@innercontinue@*/ continue;
1293                 if (rrp->key) { /* XXX can't happen */
1294                     rpmMessage(RPMMESS_NORMAL, _("\tRemoving %s:\n"), rrp->key);
1295                     (void) unlink(rrp->key);    /* XXX: Should check rc??? */
1296                 }
1297             }
1298         }
1299
1300
1301     } while (1);
1302
1303 exit:
1304     rtids = IDTXfree(rtids);
1305     itids = IDTXfree(itids);
1306
1307     rpmtsEmpty(ts);
1308     (void) rpmtsSetFlags(ts, transFlags);
1309
1310     return rc;
1311 }