Modify eu-strip option to perform strip in post script of rpm package & add option...
[platform/upstream/rpm.git] / lib / rpminstall.c
index af38ca5..a3623fd 100644 (file)
@@ -4,22 +4,24 @@
 
 #include "system.h"
 
-#include "rpmcli.h"
-
-#include "rpmdb.h"
-#include "rpmds.h"
-
-#include "rpmts.h"
-
-#include "manifest.h"
-#include "rpmerr.h"
+#include <rpm/rpmcli.h>
+#include <rpm/rpmtag.h>
+#include <rpm/rpmlib.h>                /* rpmReadPackageFile, vercmp etc */
+#include <rpm/rpmdb.h>
+#include <rpm/rpmds.h>
+#include <rpm/rpmts.h>
+#include <rpm/rpmlog.h>
+#include <rpm/rpmfileutil.h>
+
+#include "lib/rpmgi.h"
+#include "lib/manifest.h"
 #include "debug.h"
 
-int rpmcliPackagesTotal = 0;
-int rpmcliHashesCurrent = 0;
-int rpmcliHashesTotal = 0;
-int rpmcliProgressCurrent = 0;
-int rpmcliProgressTotal = 0;
+static int rpmcliPackagesTotal = 0;
+static int rpmcliHashesCurrent = 0;
+static int rpmcliHashesTotal = 0;
+static int rpmcliProgressCurrent = 0;
+static int rpmcliProgressTotal = 0;
 
 /**
  * Print a CLI progress bar.
@@ -27,11 +29,11 @@ int rpmcliProgressTotal = 0;
  * @param amount       current
  * @param total                final
  */
-static void printHash(const unsigned long amount, const unsigned long total)
+static void printHash(const rpm_loff_t amount, const rpm_loff_t total)
 {
     int hashesNeeded;
 
-    rpmcliHashesTotal = (isatty (STDOUT_FILENO) ? 44 : 50);
+    rpmcliHashesTotal = (isatty (STDOUT_FILENO) ? 34 : 40);
 
     if (rpmcliHashesCurrent != rpmcliHashesTotal) {
        float pct = (total ? (((float) amount) / total) : 1.0);
@@ -70,20 +72,38 @@ static void printHash(const unsigned long amount, const unsigned long total)
     }
 }
 
+static rpmVSFlags setvsFlags(struct rpmInstallArguments_s * ia)
+{
+    rpmVSFlags vsflags;
+
+    if (ia->installInterfaceFlags & (INSTALL_UPGRADE | INSTALL_ERASE))
+       vsflags = rpmExpandNumeric("%{?_vsflags_erase}");
+    else
+       vsflags = rpmExpandNumeric("%{?_vsflags_install}");
+
+    if (rpmcliQueryFlags & VERIFY_DIGEST)
+       vsflags |= _RPMVSF_NODIGESTS;
+    if (rpmcliQueryFlags & VERIFY_SIGNATURE)
+       vsflags |= _RPMVSF_NOSIGNATURES;
+    if (rpmcliQueryFlags & VERIFY_HDRCHK)
+       vsflags |= RPMVSF_NOHDRCHK;
+
+    return vsflags;
+}
+
 void * rpmShowProgress(const void * arg,
                        const rpmCallbackType what,
-                       const unsigned long amount,
-                       const unsigned long total,
+                       const rpm_loff_t amount,
+                       const rpm_loff_t total,
                        fnpyKey key,
                        void * data)
 {
     Header h = (Header) arg;
-    char * s;
     int flags = (int) ((long)data);
     void * rc = NULL;
     const char * filename = (const char *)key;
     static FD_t fd = NULL;
-    int xx;
+    static int state = -1;
 
     switch (what) {
     case RPMCALLBACK_INST_OPEN_FILE:
@@ -92,51 +112,65 @@ void * rpmShowProgress(const void * arg,
        fd = Fopen(filename, "r.ufdio");
        /* FIX: still necessary? */
        if (fd == NULL || Ferror(fd)) {
-           rpmlog(RPMERR_OPEN, _("open of %s failed: %s\n"), filename,
+           rpmlog(RPMLOG_ERR, _("open of %s failed: %s\n"), filename,
                        Fstrerror(fd));
            if (fd != NULL) {
-               xx = Fclose(fd);
+               Fclose(fd);
                fd = NULL;
            }
        } else
-           fd = fdLink(fd, "persist (showProgress)");
+           fd = fdLink(fd);
        return (void *)fd;
        break;
 
     case RPMCALLBACK_INST_CLOSE_FILE:
        /* FIX: still necessary? */
-       fd = fdFree(fd, "persist (showProgress)");
+       fd = fdFree(fd);
        if (fd != NULL) {
-           xx = Fclose(fd);
+           Fclose(fd);
            fd = NULL;
        }
        break;
 
     case RPMCALLBACK_INST_START:
+    case RPMCALLBACK_UNINST_START:
+       if (state != what) {
+           state = what;
+           if (flags & INSTALL_HASH) {
+               if (what == RPMCALLBACK_INST_START) {
+                   fprintf(stdout, _("Updating / installing...\n"));
+               } else {
+                   fprintf(stdout, _("Cleaning up / removing...\n"));
+               }
+               fflush(stdout);
+           }
+       }
+               
        rpmcliHashesCurrent = 0;
        if (h == NULL || !(flags & INSTALL_LABEL))
            break;
-       /* @todo Remove headerSprintf() on a progress callback. */
        if (flags & INSTALL_HASH) {
-           s = headerSprintf(h, "%{NAME}",
-                               rpmTagTable, rpmHeaderFormats, NULL);
+           char *s = headerGetAsString(h, RPMTAG_NEVR);
            if (isatty (STDOUT_FILENO))
-               fprintf(stdout, "%4d:%-23.23s", rpmcliProgressCurrent + 1, s);
+               fprintf(stdout, "%4d:%-33.33s", rpmcliProgressCurrent + 1, s);
            else
-               fprintf(stdout, "%-28.28s", s);
+               fprintf(stdout, "%-38.38s", s);
            (void) fflush(stdout);
-           s = _free(s);
+           free(s);
        } else {
-           s = headerSprintf(h, "%{NAME}-%{VERSION}-%{RELEASE}",
-                                 rpmTagTable, rpmHeaderFormats, NULL);
+           char *s = headerGetAsString(h, RPMTAG_NEVRA);
            fprintf(stdout, "%s\n", s);
            (void) fflush(stdout);
-           s = _free(s);
+           free(s);
        }
        break;
 
+    case RPMCALLBACK_INST_STOP:
+       break;
+
     case RPMCALLBACK_TRANS_PROGRESS:
     case RPMCALLBACK_INST_PROGRESS:
+    case RPMCALLBACK_UNINST_PROGRESS:
        if (flags & INSTALL_PERCENT)
            fprintf(stdout, "%%%% %f\n", (double) (total
                                ? ((((float) amount) / total) * 100)
@@ -150,12 +184,14 @@ void * rpmShowProgress(const void * arg,
        rpmcliHashesCurrent = 0;
        rpmcliProgressTotal = 1;
        rpmcliProgressCurrent = 0;
+       rpmcliPackagesTotal = total;
+       state = what;
        if (!(flags & INSTALL_LABEL))
            break;
        if (flags & INSTALL_HASH)
-           fprintf(stdout, "%-28s", _("Preparing..."));
+           fprintf(stdout, "%-38s", _("Preparing..."));
        else
-           fprintf(stdout, "%s\n", _("Preparing packages for installation..."));
+           fprintf(stdout, "%s\n", _("Preparing packages..."));
        (void) fflush(stdout);
        break;
 
@@ -166,50 +202,18 @@ void * rpmShowProgress(const void * arg,
        rpmcliProgressCurrent = 0;
        break;
 
-    case RPMCALLBACK_REPACKAGE_START:
-       rpmcliHashesCurrent = 0;
-       rpmcliProgressTotal = total;
-       rpmcliProgressCurrent = 0;
-       if (!(flags & INSTALL_LABEL))
-           break;
-       if (flags & INSTALL_HASH)
-           fprintf(stdout, "%-28s\n", _("Repackaging..."));
-       else
-           fprintf(stdout, "%s\n", _("Repackaging erased files..."));
-       (void) fflush(stdout);
-       break;
-
-    case RPMCALLBACK_REPACKAGE_PROGRESS:
-       if (amount && (flags & INSTALL_HASH))
-           printHash(1, 1);    /* Fixes "preparing..." progress bar */
-       break;
-
-    case RPMCALLBACK_REPACKAGE_STOP:
-       rpmcliProgressTotal = total;
-       rpmcliProgressCurrent = total;
-       if (flags & INSTALL_HASH)
-           printHash(1, 1);    /* Fixes "preparing..." progress bar */
-       rpmcliProgressTotal = rpmcliPackagesTotal;
-       rpmcliProgressCurrent = 0;
-       if (!(flags & INSTALL_LABEL))
-           break;
-       if (flags & INSTALL_HASH)
-           fprintf(stdout, "%-28s\n", _("Upgrading..."));
-       else
-           fprintf(stdout, "%s\n", _("Upgrading packages..."));
-       (void) fflush(stdout);
-       break;
-
-    case RPMCALLBACK_UNINST_PROGRESS:
-       break;
-    case RPMCALLBACK_UNINST_START:
-       break;
     case RPMCALLBACK_UNINST_STOP:
        break;
     case RPMCALLBACK_UNPACK_ERROR:
        break;
     case RPMCALLBACK_CPIO_ERROR:
        break;
+    case RPMCALLBACK_SCRIPT_ERROR:
+       break;
+    case RPMCALLBACK_SCRIPT_START:
+       break;
+    case RPMCALLBACK_SCRIPT_STOP:
+       break;
     case RPMCALLBACK_UNKNOWN:
     default:
        break;
@@ -218,75 +222,189 @@ void * rpmShowProgress(const void * arg,
     return rc;
 }      
 
-typedef const char * str_t;
+static void setNotifyFlag(struct rpmInstallArguments_s * ia,
+                         rpmts ts)
+{
+    int notifyFlags;
+
+    notifyFlags = ia->installInterfaceFlags | (rpmIsVerbose() ? INSTALL_LABEL : 0 );
+    rpmtsSetNotifyCallback(ts, rpmShowProgress, (void *) ((long)notifyFlags));
+}
 
 struct rpmEIU {
-    Header h;
-    FD_t fd;
     int numFailed;
     int numPkgs;
-    str_t * pkgURL;
-    str_t * fnp;
+    char ** pkgURL;
+    char ** fnp;
     char * pkgState;
     int prevx;
     int pkgx;
     int numRPMS;
     int numSRPMS;
-    str_t * sourceURL;
-    int isSource;
+    char ** sourceURL;
     int argc;
-    str_t * argv;
+    char ** argv;
     rpmRelocation * relocations;
     rpmRC rpmrc;
 };
 
-/** @todo Generalize --freshen policies. */
-int rpmInstall(rpmts ts,
-               struct rpmInstallArguments_s * ia,
-               const char ** fileArgv)
+static int rpmcliTransaction(rpmts ts, struct rpmInstallArguments_s * ia,
+                     int numPackages)
 {
-    struct rpmEIU * eiu = memset(alloca(sizeof(*eiu)), 0, sizeof(*eiu));
     rpmps ps;
-    rpmprobFilterFlags probFilter;
+
+    int rc = 0;
+    int stop = 0;
+
+    int eflags = ia->installInterfaceFlags & INSTALL_ERASE;
+
+    if (!(ia->installInterfaceFlags & INSTALL_NODEPS)) {
+
+       if (rpmtsCheck(ts)) {
+           rc = numPackages;
+           stop = 1;
+       }
+
+       ps = rpmtsProblems(ts);
+       if (!stop && rpmpsNumProblems(ps) > 0) {
+           rpmlog(RPMLOG_ERR, _("Failed dependencies:\n"));
+           rpmpsPrint(NULL, ps);
+           rc = numPackages;
+           stop = 1;
+       }
+       ps = rpmpsFree(ps);
+    }
+
+    if (!stop && !(ia->installInterfaceFlags & INSTALL_NOORDER)) {
+       if (rpmtsOrder(ts)) {
+           rc = numPackages;
+           stop = 1;
+       }
+    }
+
+    if (numPackages && !stop) {
+       rpmlog(RPMLOG_DEBUG, eflags ? "erasing packages\n" :
+                                     "installing binary packages\n");
+       rpmtsClean(ts);
+       rc = rpmtsRun(ts, NULL, ia->probFilter);
+
+       ps = rpmtsProblems(ts);
+
+       if ((rpmpsNumProblems(ps) > 0) && (eflags? 1 : (rc > 0)))
+           rpmpsPrint((eflags? NULL : stderr), ps);
+       ps = rpmpsFree(ps);
+    }
+
+    return rc;
+}
+
+static int tryReadManifest(struct rpmEIU * eiu)
+{
+    int rc;
+
+    /* Try to read a package manifest. */
+    FD_t fd = Fopen(*eiu->fnp, "r.ufdio");
+    if (fd == NULL || Ferror(fd)) {
+        rpmlog(RPMLOG_ERR, _("open of %s failed: %s\n"), *eiu->fnp,
+              Fstrerror(fd));
+       if (fd != NULL) {
+           Fclose(fd);
+           fd = NULL;
+       }
+       eiu->numFailed++; *eiu->fnp = NULL;
+       return RPMRC_FAIL;
+    }
+
+    /* Read list of packages from manifest. */
+    rc = rpmReadPackageManifest(fd, &eiu->argc, &eiu->argv);
+    if (rc != RPMRC_OK)
+        rpmlog(RPMLOG_ERR, _("%s: not an rpm package (or package manifest): %s\n"),
+              *eiu->fnp, Fstrerror(fd));
+    Fclose(fd);
+    fd = NULL;
+
+    if (rc != RPMRC_OK)
+        eiu->numFailed++; *eiu->fnp = NULL;
+
+    return rc;
+}
+
+static int tryReadHeader(rpmts ts, struct rpmEIU * eiu, Header * hdrp)
+{
+   /* Try to read the header from a package file. */
+   FD_t fd = Fopen(*eiu->fnp, "r.ufdio");
+   if (fd == NULL || Ferror(fd)) {
+       rpmlog(RPMLOG_ERR, _("open of %s failed: %s\n"), *eiu->fnp,
+             Fstrerror(fd));
+       if (fd != NULL) {
+           Fclose(fd);
+          fd = NULL;
+       }
+       eiu->numFailed++; *eiu->fnp = NULL;
+       return RPMRC_FAIL;
+   }
+
+   /* Read the header, verifying signatures (if present). */
+   eiu->rpmrc = rpmReadPackageFile(ts, fd, *eiu->fnp, hdrp);
+   Fclose(fd);
+   fd = NULL;
+   
+   /* Honor --nomanifest */
+   if (eiu->rpmrc == RPMRC_NOTFOUND && (giFlags & RPMGI_NOMANIFEST))
+       eiu->rpmrc = RPMRC_FAIL;
+
+   if(eiu->rpmrc == RPMRC_FAIL) {
+       rpmlog(RPMLOG_ERR, _("%s cannot be installed\n"), *eiu->fnp);
+       eiu->numFailed++; *eiu->fnp = NULL;
+   }
+
+   return RPMRC_OK;
+}
+
+
+/* On --freshen, verify package is installed and newer */
+static int checkFreshenStatus(rpmts ts, Header h)
+{
+    rpmdbMatchIterator mi = NULL;
+    const char * name = headerGetString(h, RPMTAG_NAME);
+    const char *arch = headerGetString(h, RPMTAG_ARCH);
+    Header oldH = NULL;
+
+    if (name != NULL)
+        mi = rpmtsInitIterator(ts, RPMDBI_NAME, name, 0);
+    if (rpmtsColor(ts) && arch)
+       rpmdbSetIteratorRE(mi, RPMTAG_ARCH, RPMMIRE_DEFAULT, arch);
+
+    while ((oldH = rpmdbNextIterator(mi)) != NULL) {
+       /* Package is newer than those currently installed. */
+        if (rpmVersionCompare(oldH, h) < 0)
+           break;
+    }
+
+    rpmdbFreeIterator(mi);
+    return (oldH != NULL);
+}
+
+/** @todo Generalize --freshen policies. */
+int rpmInstall(rpmts ts, struct rpmInstallArguments_s * ia, ARGV_t fileArgv)
+{
+    struct rpmEIU * eiu = xcalloc(1, sizeof(*eiu));
     rpmRelocation * relocations;
-const char * fileURL = NULL;
-    int stopInstall = 0;
-    const char ** av = NULL;
-    rpmVSFlags vsflags, ovsflags, tvsflags;
-    int ac = 0;
+    char * fileURL = NULL;
+    rpmVSFlags vsflags, ovsflags;
     int rc;
-    int xx;
     int i;
 
-    if (fileArgv == NULL) goto exit;
-
-    rpmcliPackagesTotal = 0;
+    vsflags = setvsFlags(ia);
+    ovsflags = rpmtsSetVSFlags(ts, (vsflags | RPMVSF_NEEDPAYLOAD));
 
-    if (rpmExpandNumeric("%{?_repackage_all_erasures}"))
-       ia->transFlags |= RPMTRANS_FLAG_REPACKAGE;
+    if (fileArgv == NULL) goto exit;
 
     (void) rpmtsSetFlags(ts, ia->transFlags);
 
-    probFilter = ia->probFilter;
     relocations = ia->relocations;
 
-    if (ia->installInterfaceFlags & INSTALL_UPGRADE)
-       vsflags = rpmExpandNumeric("%{?_vsflags_erase}");
-    else
-       vsflags = rpmExpandNumeric("%{?_vsflags_install}");
-    if (ia->qva_flags & VERIFY_DIGEST)
-       vsflags |= _RPMVSF_NODIGESTS;
-    if (ia->qva_flags & VERIFY_SIGNATURE)
-       vsflags |= _RPMVSF_NOSIGNATURES;
-    if (ia->qva_flags & VERIFY_HDRCHK)
-       vsflags |= RPMVSF_NOHDRCHK;
-    ovsflags = rpmtsSetVSFlags(ts, (vsflags | RPMVSF_NEEDPAYLOAD));
-
-    {  int notifyFlags;
-       notifyFlags = ia->installInterfaceFlags | (rpmIsVerbose() ? INSTALL_LABEL : 0 );
-       xx = rpmtsSetNotifyCallback(ts,
-                       rpmShowProgress, (void *) ((long)notifyFlags));
-    }
+    setNotifyFlag(ia, ts); 
 
     if ((eiu->relocations = relocations) != NULL) {
        while (eiu->relocations->oldPath)
@@ -297,19 +415,23 @@ const char * fileURL = NULL;
 
     /* Build fully globbed list of arguments in argv[argc]. */
     for (eiu->fnp = fileArgv; *eiu->fnp != NULL; eiu->fnp++) {
-       av = _free(av); ac = 0;
-       rc = rpmGlob(*eiu->fnp, &ac, &av);
+       ARGV_t av = NULL;
+       int ac = 0;
+       char * fn;
+
+       fn = rpmEscapeSpaces(*eiu->fnp);
+       rc = rpmGlob(fn, &ac, &av);
+       fn = _free(fn);
        if (rc || ac == 0) {
-           rpmlog(RPMERR_OPEN, _("File not found by glob: %s\n"), *eiu->fnp);
+           rpmlog(RPMLOG_ERR, _("File not found by glob: %s\n"), *eiu->fnp);
+           eiu->numFailed++;
            continue;
        }
 
-       eiu->argv = xrealloc(eiu->argv, (eiu->argc+ac+1) * sizeof(*eiu->argv));
-       memcpy(eiu->argv+eiu->argc, av, ac * sizeof(*av));
+       argvAppend(&(eiu->argv), av);
+       argvFree(av);
        eiu->argc += ac;
-       eiu->argv[eiu->argc] = NULL;
     }
-    av = _free(av);    ac = 0;
 
 restart:
     /* Allocate sufficient storage for next set of args. */
@@ -331,60 +453,27 @@ restart:
        fileURL = eiu->argv[i];
        eiu->argv[i] = NULL;
 
-#ifdef NOTYET
-if (fileURL[0] == '=') {
-    rpmds this = rpmdsSingle(RPMTAG_REQUIRENAME, fileURL+1, NULL, 0);
-
-    xx = rpmtsSolve(ts, this, NULL);
-    if (ts->suggests && ts->nsuggests > 0) {
-       fileURL = _free(fileURL);
-       fileURL = ts->suggests[0];
-       ts->suggests[0] = NULL;
-       while (ts->nsuggests-- > 0) {
-           if (ts->suggests[ts->nsuggests] == NULL)
-               continue;
-           ts->suggests[ts->nsuggests] = _free(ts->suggests[ts->nsuggests]);
-       }
-       ts->suggests = _free(ts->suggests);
-       rpmlog(RPMLOG_DEBUG, _("Adding goal: %s\n"), fileURL);
-       eiu->pkgURL[eiu->pkgx] = fileURL;
-       fileURL = NULL;
-       eiu->pkgx++;
-    }
-    this = rpmdsFree(this);
-} else
-#endif
-
        switch (urlIsURL(fileURL)) {
        case URL_IS_HTTPS:
        case URL_IS_HTTP:
        case URL_IS_FTP:
-       {   const char *tfn;
+       {   char *tfn = NULL;
+           FD_t tfd;
 
            if (rpmIsVerbose())
                fprintf(stdout, _("Retrieving %s\n"), fileURL);
 
-           {   char tfnbuf[64];
-               const char * rootDir = rpmtsRootDir(ts);
-               if (!(rootDir && * rootDir))
-                   rootDir = "";
-               strcpy(tfnbuf, "rpm-xfer.XXXXXX");
-#if defined(HAVE_MKSTEMP)
-               (void) close(mkstemp(tfnbuf));
-#else
-               (void) mktemp(tfnbuf);
-#endif
-               tfn = rpmGenPath(rootDir, "%{_tmppath}/", tfnbuf);
+           tfd = rpmMkTempFile(rpmtsRootDir(ts), &tfn);
+           if (tfd && tfn) {
+               Fclose(tfd);
+               rc = urlGetFile(fileURL, tfn);
+           } else {
+               rc = -1;
            }
 
-           /* XXX undefined %{name}/%{version}/%{release} here */
-           /* XXX %{_tmpdir} does not exist */
-           rpmlog(RPMLOG_DEBUG, _(" ... as %s\n"), tfn);
-           rc = urlGetFile(fileURL, tfn);
-           if (rc < 0) {
+           if (rc != 0) {
                rpmlog(RPMLOG_ERR,
-                       _("skipping %s - transfer failed - %s\n"),
-                       fileURL, ftpStrerror(rc));
+                       _("skipping %s - transfer failed\n"), fileURL);
                eiu->numFailed++;
                eiu->pkgURL[eiu->pkgx] = NULL;
                tfn = _free(tfn);
@@ -413,51 +502,25 @@ if (fileURL[0] == '=') {
         *eiu->fnp != NULL;
         eiu->fnp++, eiu->prevx++)
     {
+       Header h = NULL;
        const char * fileName;
 
        rpmlog(RPMLOG_DEBUG, "============== %s\n", *eiu->fnp);
        (void) urlPath(*eiu->fnp, &fileName);
 
-       /* Try to read the header from a package file. */
-       eiu->fd = Fopen(*eiu->fnp, "r.ufdio");
-       if (eiu->fd == NULL || Ferror(eiu->fd)) {
-           rpmlog(RPMERR_OPEN, _("open of %s failed: %s\n"), *eiu->fnp,
-                       Fstrerror(eiu->fd));
-           if (eiu->fd != NULL) {
-               xx = Fclose(eiu->fd);
-               eiu->fd = NULL;
-           }
-           eiu->numFailed++; *eiu->fnp = NULL;
+       if (tryReadHeader(ts, eiu, &h) == RPMRC_FAIL)
            continue;
-       }
 
-       /* Read the header, verifying signatures (if present). */
-       tvsflags = rpmtsSetVSFlags(ts, vsflags);
-       eiu->rpmrc = rpmReadPackageFile(ts, eiu->fd, *eiu->fnp, &eiu->h);
-       tvsflags = rpmtsSetVSFlags(ts, tvsflags);
-       xx = Fclose(eiu->fd);
-       eiu->fd = NULL;
-
-       switch (eiu->rpmrc) {
-       case RPMRC_FAIL:
-           rpmlog(RPMLOG_ERR, _("%s cannot be installed\n"), *eiu->fnp);
-           eiu->numFailed++; *eiu->fnp = NULL;
-           continue;
-           break;
-       case RPMRC_NOTFOUND:
-           goto maybe_manifest;
-           break;
-       case RPMRC_NOTTRUSTED:
-       case RPMRC_NOKEY:
-       case RPMRC_OK:
-       default:
-           break;
+       if (eiu->rpmrc == RPMRC_NOTFOUND) {
+           rc = tryReadManifest(eiu);
+           if (rc == RPMRC_OK) {
+               eiu->prevx++;
+               goto restart;
+           }
        }
 
-       eiu->isSource = headerIsEntry(eiu->h, RPMTAG_SOURCEPACKAGE);
-
-       if (eiu->isSource) {
-           rpmlog(RPMLOG_DEBUG, _("\tadded source package [%d]\n"),
+       if (headerIsSource(h)) {
+           rpmlog(RPMLOG_DEBUG, "\tadded source package [%d]\n",
                eiu->numSRPMS);
            eiu->sourceURL = xrealloc(eiu->sourceURL,
                                (eiu->numSRPMS + 2) * sizeof(*eiu->sourceURL));
@@ -469,62 +532,37 @@ if (fileURL[0] == '=') {
        }
 
        if (eiu->relocations) {
-           const char ** paths;
-           int pft;
-           int c;
-
-           if (headerGetEntry(eiu->h, RPMTAG_PREFIXES, &pft,
-                                      (void **) &paths, &c) && (c == 1))
-           {
-               eiu->relocations->oldPath = xstrdup(paths[0]);
-               paths = headerFreeData(paths, pft);
+           struct rpmtd_s prefixes;
+
+           headerGet(h, RPMTAG_PREFIXES, &prefixes, HEADERGET_DEFAULT);
+           if (rpmtdCount(&prefixes) == 1) {
+               eiu->relocations->oldPath = xstrdup(rpmtdGetString(&prefixes));
+               rpmtdFreeData(&prefixes);
            } else {
-               const char * name;
-               xx = headerNVR(eiu->h, &name, NULL, NULL);
-               rpmlog(RPMLOG_ERR,
-                              _("package %s is not relocatable\n"), name);
+               rpmlog(RPMLOG_ERR, _("package %s is not relocatable\n"),
+                      headerGetString(h, RPMTAG_NAME));
                eiu->numFailed++;
                goto exit;
            }
        }
 
-       /* On --freshen, verify package is installed and newer */
-       if (ia->installInterfaceFlags & INSTALL_FRESHEN) {
-           rpmdbMatchIterator mi;
-           const char * name;
-           Header oldH;
-           int count;
-
-           xx = headerNVR(eiu->h, &name, NULL, NULL);
-           mi = rpmtsInitIterator(ts, RPMTAG_NAME, name, 0);
-           count = rpmdbGetIteratorCount(mi);
-           while ((oldH = rpmdbNextIterator(mi)) != NULL) {
-               if (rpmVersionCompare(oldH, eiu->h) < 0)
-                   continue;
-               /* same or newer package already installed */
-               count = 0;
-               break;
-           }
-           mi = rpmdbFreeIterator(mi);
-           if (count == 0) {
-               eiu->h = headerFree(eiu->h);
-               continue;
+       if (ia->installInterfaceFlags & INSTALL_FRESHEN)
+           if (checkFreshenStatus(ts, h) != 1) {
+               headerFree(h);
+               continue;
            }
-           /* Package is newer than those currently installed. */
-       }
 
-       rc = rpmtsAddInstallElement(ts, eiu->h, (fnpyKey)fileName,
+       rc = rpmtsAddInstallElement(ts, h, (fnpyKey)fileName,
                        (ia->installInterfaceFlags & INSTALL_UPGRADE) != 0,
                        relocations);
 
-       /* XXX reference held by transaction set */
-       eiu->h = headerFree(eiu->h);
+       headerFree(h);
        if (eiu->relocations)
            eiu->relocations->oldPath = _free(eiu->relocations->oldPath);
 
        switch(rc) {
        case 0:
-           rpmlog(RPMLOG_DEBUG, _("\tadded binary package [%d]\n"),
+           rpmlog(RPMLOG_DEBUG, "\tadded binary package [%d]\n",
                        eiu->numRPMS);
            break;
        case 1:
@@ -533,13 +571,6 @@ if (fileURL[0] == '=') {
            eiu->numFailed++;
            goto exit;
            break;
-       case 2:
-           rpmlog(RPMLOG_ERR,
-                           _("file %s requires a newer version of RPM\n"),
-                           *eiu->fnp);
-           eiu->numFailed++;
-           goto exit;
-           break;
        default:
            eiu->numFailed++;
            goto exit;
@@ -547,255 +578,118 @@ if (fileURL[0] == '=') {
        }
 
        eiu->numRPMS++;
-       continue;
-
-maybe_manifest:
-       /* Try to read a package manifest. */
-       eiu->fd = Fopen(*eiu->fnp, "r.fpio");
-       if (eiu->fd == NULL || Ferror(eiu->fd)) {
-           rpmlog(RPMERR_OPEN, _("open of %s failed: %s\n"), *eiu->fnp,
-                       Fstrerror(eiu->fd));
-           if (eiu->fd != NULL) {
-               xx = Fclose(eiu->fd);
-               eiu->fd = NULL;
-           }
-           eiu->numFailed++; *eiu->fnp = NULL;
-           break;
-       }
-
-       /* Read list of packages from manifest. */
-/* FIX: *eiu->argv can be NULL */
-       rc = rpmReadPackageManifest(eiu->fd, &eiu->argc, &eiu->argv);
-       if (rc != RPMRC_OK)
-           rpmlog(RPMERR_MANIFEST, _("%s: not an rpm package (or package manifest): %s\n"),
-                       *eiu->fnp, Fstrerror(eiu->fd));
-       xx = Fclose(eiu->fd);
-       eiu->fd = NULL;
-
-       /* If successful, restart the query loop. */
-       if (rc == RPMRC_OK) {
-           eiu->prevx++;
-           goto restart;
-       }
-
-       eiu->numFailed++; *eiu->fnp = NULL;
-       break;
     }
 
-    rpmlog(RPMLOG_DEBUG, _("found %d source and %d binary packages\n"),
+    rpmlog(RPMLOG_DEBUG, "found %d source and %d binary packages\n",
                eiu->numSRPMS, eiu->numRPMS);
 
     if (eiu->numFailed) goto exit;
 
-    if (eiu->numRPMS && !(ia->installInterfaceFlags & INSTALL_NODEPS)) {
-
-       if (rpmtsCheck(ts)) {
-           eiu->numFailed = eiu->numPkgs;
-           stopInstall = 1;
-       }
-
-       ps = rpmtsProblems(ts);
-       if (!stopInstall && rpmpsNumProblems(ps) > 0) {
-           rpmlog(RPMLOG_ERR, _("Failed dependencies:\n"));
-           rpmpsPrint(NULL, ps);
-           eiu->numFailed = eiu->numPkgs;
-           stopInstall = 1;
-
-           if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_NOSUGGEST))
-               rpmtsPrintSuggests(ts);
-
-       }
-       ps = rpmpsFree(ps);
+    if (eiu->numRPMS) {
+        int rc = rpmcliTransaction(ts, ia, eiu->numPkgs);
+        if (rc < 0)
+            eiu->numFailed += eiu->numRPMS;
+       else if (rc > 0)
+            eiu->numFailed += rc;
     }
 
-    if (eiu->numRPMS && !(ia->installInterfaceFlags & INSTALL_NOORDER)) {
-       if (rpmtsOrder(ts)) {
-           eiu->numFailed = eiu->numPkgs;
-           stopInstall = 1;
-       }
-    }
-
-    if (eiu->numRPMS && !stopInstall) {
-
-       rpmcliPackagesTotal += eiu->numSRPMS;
-
-       rpmlog(RPMLOG_DEBUG, _("installing binary packages\n"));
-
-       /* Drop added/available package indices and dependency sets. */
-       rpmtsClean(ts);
-
-       rc = rpmtsRun(ts, NULL, probFilter);
-       ps = rpmtsProblems(ts);
-
-       if (rc < 0) {
-           eiu->numFailed += eiu->numRPMS;
-       } else if (rc > 0) {
-           eiu->numFailed += rc;
-           if (rpmpsNumProblems(ps) > 0)
-               rpmpsPrint(stderr, ps);
-       }
-       ps = rpmpsFree(ps);
-    }
-
-    if (eiu->numSRPMS && !stopInstall) {
-       if (eiu->sourceURL != NULL)
+    if (eiu->numSRPMS && (eiu->sourceURL != NULL)) {
        for (i = 0; i < eiu->numSRPMS; i++) {
            rpmdbCheckSignals();
-           if (eiu->sourceURL[i] == NULL) continue;
-           eiu->fd = Fopen(eiu->sourceURL[i], "r.ufdio");
-           if (eiu->fd == NULL || Ferror(eiu->fd)) {
-               rpmlog(RPMLOG_ERR, _("cannot open file %s: %s\n"),
-                          eiu->sourceURL[i], Fstrerror(eiu->fd));
-               if (eiu->fd != NULL) {
-                   xx = Fclose(eiu->fd);
-                   eiu->fd = NULL;
-               }
-               continue;
+           if (eiu->sourceURL[i] != NULL) {
+               rc = RPMRC_OK;
+               if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_TEST))
+                   rc = rpmInstallSource(ts, eiu->sourceURL[i], NULL, NULL);
+               if (rc != 0)
+                   eiu->numFailed++;
            }
-
-           if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_TEST)) {
-               eiu->rpmrc = rpmInstallSourcePackage(ts, eiu->fd, NULL, NULL);
-               if (eiu->rpmrc != RPMRC_OK) eiu->numFailed++;
-           }
-
-           xx = Fclose(eiu->fd);
-           eiu->fd = NULL;
        }
     }
 
 exit:
-    if (eiu->pkgURL != NULL)
-    for (i = 0; i < eiu->numPkgs; i++) {
-       if (eiu->pkgURL[i] == NULL) continue;
-       if (eiu->pkgState[i] == 1)
-           (void) Unlink(eiu->pkgURL[i]);
-       eiu->pkgURL[i] = _free(eiu->pkgURL[i]);
+    if (eiu->pkgURL != NULL) {
+        for (i = 0; i < eiu->numPkgs; i++) {
+           if (eiu->pkgURL[i] == NULL) continue;
+           if (eiu->pkgState[i] == 1)
+               (void) unlink(eiu->pkgURL[i]);
+           eiu->pkgURL[i] = _free(eiu->pkgURL[i]);
+       }
     }
     eiu->pkgState = _free(eiu->pkgState);
     eiu->pkgURL = _free(eiu->pkgURL);
     eiu->argv = _free(eiu->argv);
+    rc = eiu->numFailed;
+    free(eiu);
 
     rpmtsEmpty(ts);
+    rpmtsSetVSFlags(ts, ovsflags);
 
-    return eiu->numFailed;
+    return rc;
 }
 
-int rpmErase(rpmts ts, struct rpmInstallArguments_s * ia,
-               const char ** argv)
+int rpmErase(rpmts ts, struct rpmInstallArguments_s * ia, ARGV_const_t argv)
 {
-    int count;
-    const char ** arg;
+    char * const * arg;
+    char *qfmt = NULL;
     int numFailed = 0;
-    int stopUninstall = 0;
     int numPackages = 0;
     rpmVSFlags vsflags, ovsflags;
-    rpmps ps;
 
     if (argv == NULL) return 0;
 
-    vsflags = rpmExpandNumeric("%{?_vsflags_erase}");
-    if (ia->qva_flags & VERIFY_DIGEST)
-       vsflags |= _RPMVSF_NODIGESTS;
-    if (ia->qva_flags & VERIFY_SIGNATURE)
-       vsflags |= _RPMVSF_NOSIGNATURES;
-    if (ia->qva_flags & VERIFY_HDRCHK)
-       vsflags |= RPMVSF_NOHDRCHK;
+    vsflags = setvsFlags(ia);
     ovsflags = rpmtsSetVSFlags(ts, vsflags);
 
-    if (rpmExpandNumeric("%{?_repackage_all_erasures}"))
-       ia->transFlags |= RPMTRANS_FLAG_REPACKAGE;
-
-    /* XXX suggest mechanism only meaningful when installing */
-    ia->transFlags |= RPMTRANS_FLAG_NOSUGGEST;
-
     (void) rpmtsSetFlags(ts, ia->transFlags);
 
-#ifdef NOTYET  /* XXX no callbacks on erase yet */
-    {  int notifyFlags, xx;
-       notifyFlags = ia->eraseInterfaceFlags | (rpmIsVerbose() ? INSTALL_LABEL : 0 );
-       xx = rpmtsSetNotifyCallback(ts,
-                       rpmShowProgress, (void *) ((long)notifyFlags));
-    }
-#endif
+    setNotifyFlag(ia, ts);
 
+    qfmt = rpmExpand("%{?_query_all_fmt}\n", NULL);
     for (arg = argv; *arg; arg++) {
-       rpmdbMatchIterator mi;
+       rpmdbMatchIterator mi = rpmtsInitIterator(ts, RPMDBI_LABEL, *arg, 0);
+       int matches = rpmdbGetIteratorCount(mi);
+       int erasing = 1;
 
-       /* XXX HACK to get rpmdbFindByLabel out of the API */
-       mi = rpmtsInitIterator(ts, RPMDBI_LABEL, *arg, 0);
-       if (mi == NULL) {
+       if (! matches) {
            rpmlog(RPMLOG_ERR, _("package %s is not installed\n"), *arg);
            numFailed++;
        } else {
            Header h;   /* XXX iterator owns the reference */
-           count = 0;
-           while ((h = rpmdbNextIterator(mi)) != NULL) {
-               unsigned int recOffset = rpmdbGetIteratorOffset(mi);
 
-               if (!(count++ == 0 || (ia->eraseInterfaceFlags & UNINSTALL_ALLMATCHES))) {
-                   rpmlog(RPMLOG_ERR, _("\"%s\" specifies multiple packages\n"),
+           if (matches > 1 && 
+               !(ia->installInterfaceFlags & UNINSTALL_ALLMATCHES)) {
+               rpmlog(RPMLOG_ERR, _("\"%s\" specifies multiple packages:\n"),
                        *arg);
-                   numFailed++;
-                   break;
-               }
-               if (recOffset) {
-                   (void) rpmtsAddEraseElement(ts, h, recOffset);
+               numFailed++;
+               erasing = 0;
+           }
+
+           while ((h = rpmdbNextIterator(mi)) != NULL) {
+               if (erasing) {
+                   (void) rpmtsAddEraseElement(ts, h, -1);
                    numPackages++;
+               } else {
+                   char *nevra = headerFormat(h, qfmt, NULL);
+                   rpmlog(RPMLOG_NOTICE, "  %s", nevra);
+                   free(nevra);
                }
            }
        }
-       mi = rpmdbFreeIterator(mi);
+       rpmdbFreeIterator(mi);
     }
+    free(qfmt);
 
     if (numFailed) goto exit;
-
-    if (!(ia->eraseInterfaceFlags & UNINSTALL_NODEPS)) {
-
-       if (rpmtsCheck(ts)) {
-           numFailed = numPackages;
-           stopUninstall = 1;
-       }
-
-       ps = rpmtsProblems(ts);
-       if (!stopUninstall && rpmpsNumProblems(ps) > 0) {
-           rpmlog(RPMLOG_ERR, _("Failed dependencies:\n"));
-           rpmpsPrint(NULL, ps);
-           numFailed += numPackages;
-           stopUninstall = 1;
-       }
-       ps = rpmpsFree(ps);
-    }
-
-    if (!stopUninstall && !(ia->installInterfaceFlags & INSTALL_NOORDER)) {
-       if (rpmtsOrder(ts)) {
-           numFailed += numPackages;
-           stopUninstall = 1;
-       }
-    }
-
-    if (numPackages && !stopUninstall) {
-       (void) rpmtsSetFlags(ts, (rpmtsFlags(ts) | RPMTRANS_FLAG_REVERSE));
-
-       /* Drop added/available package indices and dependency sets. */
-       rpmtsClean(ts);
-
-       numPackages = rpmtsRun(ts, NULL, ia->probFilter & (RPMPROB_FILTER_DISKSPACE|RPMPROB_FILTER_DISKNODES));
-       ps = rpmtsProblems(ts);
-       if (rpmpsNumProblems(ps) > 0)
-           rpmpsPrint(NULL, ps);
-       numFailed += numPackages;
-       stopUninstall = 1;
-       ps = rpmpsFree(ps);
-    }
-
+    numFailed = rpmcliTransaction(ts, ia, numPackages);
 exit:
     rpmtsEmpty(ts);
+    rpmtsSetVSFlags(ts, ovsflags);
 
     return numFailed;
 }
 
 int rpmInstallSource(rpmts ts, const char * arg,
-               const char ** specFilePtr, const char ** cookie)
+               char ** specFilePtr, char ** cookie)
 {
     FD_t fd;
     int rc;
@@ -808,15 +702,15 @@ int rpmInstallSource(rpmts ts, const char * arg,
        return 1;
     }
 
-    if (rpmIsVerbose())
+    if (rpmIsVerbose() && specFilePtr != NULL)
        fprintf(stdout, _("Installing %s\n"), arg);
 
     {
        rpmVSFlags ovsflags =
-               rpmtsSetVSFlags(ts, (rpmtsVSFlags(ts) | RPMVSF_NEEDPAYLOAD));
+               rpmtsSetVSFlags(ts, (specFilePtr) ? (rpmtsVSFlags(ts) | RPMVSF_NEEDPAYLOAD) : rpmtsVSFlags(ts));
        rpmRC rpmrc = rpmInstallSourcePackage(ts, fd, specFilePtr, cookie);
        rc = (rpmrc == RPMRC_OK ? 0 : 1);
-       ovsflags = rpmtsSetVSFlags(ts, ovsflags);
+       rpmtsSetVSFlags(ts, ovsflags);
     }
     if (rc != 0) {
        rpmlog(RPMLOG_ERR, _("%s cannot be installed\n"), arg);
@@ -831,226 +725,3 @@ int rpmInstallSource(rpmts ts, const char * arg,
     return rc;
 }
 
-/** @todo Transaction handling, more, needs work. */
-int rpmRollback(rpmts ts, struct rpmInstallArguments_s * ia, const char ** argv)
-{
-    int ifmask= (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL|INSTALL_ERASE);
-    unsigned thistid = 0xffffffff;
-    unsigned prevtid;
-    time_t tid;
-    IDTX itids = NULL;
-    IDTX rtids = NULL;
-    IDT rp;
-    int nrids = 0;
-    IDT ip;
-    int niids = 0;
-    int rc = 0;
-    int vsflags, ovsflags;
-    int numAdded;
-    int numRemoved;
-    rpmps ps;
-    int _unsafe_rollbacks = 0;
-    rpmtransFlags transFlags = ia->transFlags;
-
-    if (argv != NULL && *argv != NULL) {
-       rc = -1;
-       goto exit;
-    }
-
-    _unsafe_rollbacks = rpmExpandNumeric("%{?_unsafe_rollbacks}");
-
-    vsflags = rpmExpandNumeric("%{?_vsflags_erase}");
-    if (ia->qva_flags & VERIFY_DIGEST)
-       vsflags |= _RPMVSF_NODIGESTS;
-    if (ia->qva_flags & VERIFY_SIGNATURE)
-       vsflags |= _RPMVSF_NOSIGNATURES;
-    if (ia->qva_flags & VERIFY_HDRCHK)
-       vsflags |= RPMVSF_NOHDRCHK;
-    vsflags |= RPMVSF_NEEDPAYLOAD;     /* XXX no legacy signatures */
-    ovsflags = rpmtsSetVSFlags(ts, vsflags);
-
-    (void) rpmtsSetFlags(ts, transFlags);
-
-    /*  Make the transaction a rollback transaction.  In a rollback
-     *  a best effort is what we want 
-     */
-    rpmtsSetType(ts, RPMTRANS_TYPE_ROLLBACK);
-
-    itids = IDTXload(ts, RPMTAG_INSTALLTID);
-    if (itids != NULL) {
-       ip = itids->idt;
-       niids = itids->nidt;
-    } else {
-       ip = NULL;
-       niids = 0;
-    }
-
-    {  const char * globstr = rpmExpand("%{_repackage_dir}/*.rpm", NULL);
-       if (globstr == NULL || *globstr == '%') {
-           globstr = _free(globstr);
-           rc = -1;
-           goto exit;
-       }
-       rtids = IDTXglob(ts, globstr, RPMTAG_REMOVETID);
-
-       if (rtids != NULL) {
-           rp = rtids->idt;
-           nrids = rtids->nidt;
-       } else {
-           rp = NULL;
-           nrids = 0;
-       }
-       globstr = _free(globstr);
-    }
-
-    {  int notifyFlags, xx;
-       notifyFlags = ia->installInterfaceFlags | (rpmIsVerbose() ? INSTALL_LABEL : 0 );
-       xx = rpmtsSetNotifyCallback(ts,
-                       rpmShowProgress, (void *) ((long)notifyFlags));
-    }
-
-    /* Run transactions until rollback goal is achieved. */
-    do {
-       prevtid = thistid;
-       rc = 0;
-       rpmcliPackagesTotal = 0;
-       numAdded = 0;
-       numRemoved = 0;
-       ia->installInterfaceFlags &= ~ifmask;
-
-       /* Find larger of the remaining install/erase transaction id's. */
-       thistid = 0;
-       if (ip != NULL && ip->val.u32 > thistid)
-           thistid = ip->val.u32;
-       if (rp != NULL && rp->val.u32 > thistid)
-           thistid = rp->val.u32;
-
-       /* If we've achieved the rollback goal, then we're done. */
-       if (thistid == 0 || thistid < ia->rbtid)
-           break;
-
-       /* If we've reached the (configured) rollback goal, then we're done. */
-       if (_unsafe_rollbacks && thistid <= _unsafe_rollbacks)
-           break;
-
-       rpmtsEmpty(ts);
-       (void) rpmtsSetFlags(ts, transFlags);
-
-       /* Install the previously erased packages for this transaction. */
-       while (rp != NULL && rp->val.u32 == thistid) {
-
-           rpmlog(RPMLOG_DEBUG, "\t+++ install %s\n",
-                       (rp->key ? rp->key : "???"));
-
-           rc = rpmtsAddInstallElement(ts, rp->h, (fnpyKey)rp->key,
-                              0, ia->relocations);
-           if (rc != 0)
-               goto exit;
-
-           numAdded++;
-           rpmcliPackagesTotal++;
-           if (!(ia->installInterfaceFlags & ifmask))
-               ia->installInterfaceFlags |= INSTALL_UPGRADE;
-
-#ifdef NOTYET
-           rp->h = headerFree(rp->h);
-#endif
-           nrids--;
-           if (nrids > 0)
-               rp++;
-           else
-               rp = NULL;
-       }
-
-       /* Erase the previously installed packages for this transaction. */
-       while (ip != NULL && ip->val.u32 == thistid) {
-
-           rpmlog(RPMLOG_DEBUG,
-                       "\t--- erase h#%u\n", ip->instance);
-
-           rc = rpmtsAddEraseElement(ts, ip->h, ip->instance);
-           if (rc != 0)
-               goto exit;
-
-           numRemoved++;
-
-           if (_unsafe_rollbacks)
-               rpmcliPackagesTotal++;
-
-           if (!(ia->installInterfaceFlags & ifmask)) {
-               ia->installInterfaceFlags |= INSTALL_ERASE;
-               (void) rpmtsSetFlags(ts, (transFlags | RPMTRANS_FLAG_REVERSE));
-           }
-
-#ifdef NOTYET
-           ip->instance = 0;
-#endif
-           niids--;
-           if (niids > 0)
-               ip++;
-           else
-               ip = NULL;
-       }
-
-       /* Anything to do? */
-       if (rpmcliPackagesTotal <= 0)
-           break;
-
-       tid = (time_t)thistid;
-       rpmlog(RPMLOG_NOTICE,
-               _("Rollback packages (+%d/-%d) to %-24.24s (0x%08x):\n"),
-                       numAdded, numRemoved, ctime(&tid), tid);
-
-       rc = rpmtsCheck(ts);
-       ps = rpmtsProblems(ts);
-       if (rc != 0 && rpmpsNumProblems(ps) > 0) {
-           rpmlog(RPMLOG_ERR, _("Failed dependencies:\n"));
-           rpmpsPrint(NULL, ps);
-           ps = rpmpsFree(ps);
-           goto exit;
-       }
-       ps = rpmpsFree(ps);
-
-       rc = rpmtsOrder(ts);
-       if (rc != 0)
-           goto exit;
-
-       /* Drop added/available package indices and dependency sets. */
-       rpmtsClean(ts);
-
-       rc = rpmtsRun(ts, NULL, (ia->probFilter|RPMPROB_FILTER_OLDPACKAGE));
-       ps = rpmtsProblems(ts);
-       if (rc > 0 && rpmpsNumProblems(ps) > 0)
-           rpmpsPrint(stderr, ps);
-       ps = rpmpsFree(ps);
-       if (rc)
-           goto exit;
-
-       /* Clean up after successful rollback. */
-       if (rtids && !rpmIsDebug()) {
-           int i;
-           rpmlog(RPMLOG_NOTICE, _("Cleaning up repackaged packages:\n"));
-           if (rtids->idt)
-           for (i = 0; i < rtids->nidt; i++) {
-               IDT rrp = rtids->idt + i;
-               if (rrp->val.u32 != thistid)
-                   continue;
-               if (rrp->key) { /* XXX can't happen */
-                   rpmlog(RPMLOG_NOTICE, _("\tRemoving %s:\n"), rrp->key);
-                   (void) unlink(rrp->key);    /* XXX: Should check rc??? */
-               }
-           }
-       }
-
-
-    } while (1);
-
-exit:
-    rtids = IDTXfree(rtids);
-    itids = IDTXfree(itids);
-
-    rpmtsEmpty(ts);
-    (void) rpmtsSetFlags(ts, transFlags);
-
-    return rc;
-}