Fix rpmErase() exit code when arch is specified (rhbz#462631)
authorPanu Matilainen <pmatilai@redhat.com>
Thu, 18 Sep 2008 07:04:51 +0000 (10:04 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Thu, 18 Sep 2008 07:04:51 +0000 (10:04 +0300)
- essentially the same bug as rhbz#124016 but for erase code
- rpmdbIteratorCount() isn't realiable on RPMDBI_LABEL, we need to walk
  the iterator to know if there were actual matches

lib/rpminstall.c

index 8ea9a83..fb6a693 100644 (file)
@@ -606,7 +606,6 @@ exit:
 
 int rpmErase(rpmts ts, struct rpmInstallArguments_s * ia, ARGV_const_t argv)
 {
-    int count;
     char * const * arg;
     int numFailed = 0;
     int stopUninstall = 0;
@@ -640,19 +639,25 @@ int rpmErase(rpmts ts, struct rpmInstallArguments_s * ia, ARGV_const_t argv)
 
     for (arg = argv; *arg; arg++) {
        rpmdbMatchIterator mi;
+       int matches = 0;
 
-       /* XXX HACK to get rpmdbFindByLabel out of the API */
+       /* Iterator count isn't reliable with labels, count manually... */
        mi = rpmtsInitIterator(ts, RPMDBI_LABEL, *arg, 0);
-       if (mi == NULL) {
+       while (rpmdbNextIterator(mi) != NULL) {
+           matches++;
+       }
+       rpmdbFreeIterator(mi);
+
+       if (! matches) {
            rpmlog(RPMLOG_ERR, _("package %s is not installed\n"), *arg);
            numFailed++;
        } else {
            Header h;   /* XXX iterator owns the reference */
-           count = 0;
+           mi = rpmtsInitIterator(ts, RPMDBI_LABEL, *arg, 0);
            while ((h = rpmdbNextIterator(mi)) != NULL) {
                unsigned int recOffset = rpmdbGetIteratorOffset(mi);
 
-               if (!(count++ == 0 || (ia->eraseInterfaceFlags & UNINSTALL_ALLMATCHES))) {
+               if (matches > 1 || (ia->eraseInterfaceFlags & UNINSTALL_ALLMATCHES)) {
                    rpmlog(RPMLOG_ERR, _("\"%s\" specifies multiple packages\n"),
                        *arg);
                    numFailed++;
@@ -663,8 +668,8 @@ int rpmErase(rpmts ts, struct rpmInstallArguments_s * ia, ARGV_const_t argv)
                    numPackages++;
                }
            }
+           mi = rpmdbFreeIterator(mi);
        }
-       mi = rpmdbFreeIterator(mi);
     }
 
     if (numFailed) goto exit;