Modify eu-strip option to perform strip in post script of rpm package & add option...
[platform/upstream/rpm.git] / lib / rpminstall.c
index df4d8a3..a3623fd 100644 (file)
 #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.
@@ -33,7 +33,7 @@ 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);
@@ -99,11 +99,11 @@ void * rpmShowProgress(const void * arg,
                        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;
+    static int state = -1;
 
     switch (what) {
     case RPMCALLBACK_INST_OPEN_FILE:
@@ -133,28 +133,44 @@ void * rpmShowProgress(const void * arg,
        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 headerFormat() on a progress callback. */
        if (flags & INSTALL_HASH) {
-           s = headerFormat(h, "%{NAME}", 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 = headerFormat(h, "%{NAME}-%{VERSION}-%{RELEASE}", 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)
@@ -168,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;
 
@@ -184,10 +202,6 @@ void * rpmShowProgress(const void * arg,
        rpmcliProgressCurrent = 0;
        break;
 
-    case RPMCALLBACK_UNINST_PROGRESS:
-       break;
-    case RPMCALLBACK_UNINST_START:
-       break;
     case RPMCALLBACK_UNINST_STOP:
        break;
     case RPMCALLBACK_UNPACK_ERROR:
@@ -196,6 +210,10 @@ void * rpmShowProgress(const void * arg,
        break;
     case RPMCALLBACK_SCRIPT_ERROR:
        break;
+    case RPMCALLBACK_SCRIPT_START:
+       break;
+    case RPMCALLBACK_SCRIPT_STOP:
+       break;
     case RPMCALLBACK_UNKNOWN:
     default:
        break;
@@ -224,7 +242,6 @@ struct rpmEIU {
     int numRPMS;
     int numSRPMS;
     char ** sourceURL;
-    int isSource;
     int argc;
     char ** argv;
     rpmRelocation * relocations;
@@ -286,7 +303,7 @@ static int tryReadManifest(struct rpmEIU * eiu)
     int rc;
 
     /* Try to read a package manifest. */
-    FD_t fd = Fopen(*eiu->fnp, "r.fpio");
+    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));
@@ -364,7 +381,7 @@ static int checkFreshenStatus(rpmts ts, Header h)
            break;
     }
 
-    mi = rpmdbFreeIterator(mi);
+    rpmdbFreeIterator(mi);
     return (oldH != NULL);
 }
 
@@ -378,17 +395,15 @@ int rpmInstall(rpmts ts, struct rpmInstallArguments_s * ia, ARGV_t fileArgv)
     int rc;
     int i;
 
-    if (fileArgv == NULL) goto exit;
+    vsflags = setvsFlags(ia);
+    ovsflags = rpmtsSetVSFlags(ts, (vsflags | RPMVSF_NEEDPAYLOAD));
 
-    rpmcliPackagesTotal = 0;
+    if (fileArgv == NULL) goto exit;
 
     (void) rpmtsSetFlags(ts, ia->transFlags);
 
     relocations = ia->relocations;
 
-    vsflags = setvsFlags(ia);
-    ovsflags = rpmtsSetVSFlags(ts, (vsflags | RPMVSF_NEEDPAYLOAD));
-
     setNotifyFlag(ia, ts); 
 
     if ((eiu->relocations = relocations) != NULL) {
@@ -504,9 +519,7 @@ restart:
            }
        }
 
-       eiu->isSource = headerIsSource(h);
-
-       if (eiu->isSource) {
+       if (headerIsSource(h)) {
            rpmlog(RPMLOG_DEBUG, "\tadded source package [%d]\n",
                eiu->numSRPMS);
            eiu->sourceURL = xrealloc(eiu->sourceURL,
@@ -609,6 +622,7 @@ exit:
     free(eiu);
 
     rpmtsEmpty(ts);
+    rpmtsSetVSFlags(ts, ovsflags);
 
     return rc;
 }
@@ -628,23 +642,14 @@ int rpmErase(rpmts ts, struct rpmInstallArguments_s * ia, ARGV_const_t argv)
 
     (void) rpmtsSetFlags(ts, ia->transFlags);
 
-#ifdef NOTYET  /* XXX no callbacks on erase yet */
     setNotifyFlag(ia, ts);
-#endif
 
     qfmt = rpmExpand("%{?_query_all_fmt}\n", NULL);
     for (arg = argv; *arg; arg++) {
-       rpmdbMatchIterator mi;
-       int matches = 0;
+       rpmdbMatchIterator mi = rpmtsInitIterator(ts, RPMDBI_LABEL, *arg, 0);
+       int matches = rpmdbGetIteratorCount(mi);
        int erasing = 1;
 
-       /* Iterator count isn't reliable with labels, count manually... */
-       mi = rpmtsInitIterator(ts, RPMDBI_LABEL, *arg, 0);
-       while (rpmdbNextIterator(mi) != NULL) {
-           matches++;
-       }
-       rpmdbFreeIterator(mi);
-
        if (! matches) {
            rpmlog(RPMLOG_ERR, _("package %s is not installed\n"), *arg);
            numFailed++;
@@ -659,7 +664,6 @@ int rpmErase(rpmts ts, struct rpmInstallArguments_s * ia, ARGV_const_t argv)
                erasing = 0;
            }
 
-           mi = rpmtsInitIterator(ts, RPMDBI_LABEL, *arg, 0);
            while ((h = rpmdbNextIterator(mi)) != NULL) {
                if (erasing) {
                    (void) rpmtsAddEraseElement(ts, h, -1);
@@ -670,8 +674,8 @@ int rpmErase(rpmts ts, struct rpmInstallArguments_s * ia, ARGV_const_t argv)
                    free(nevra);
                }
            }
-           mi = rpmdbFreeIterator(mi);
        }
+       rpmdbFreeIterator(mi);
     }
     free(qfmt);
 
@@ -679,6 +683,7 @@ int rpmErase(rpmts ts, struct rpmInstallArguments_s * ia, ARGV_const_t argv)
     numFailed = rpmcliTransaction(ts, ia, numPackages);
 exit:
     rpmtsEmpty(ts);
+    rpmtsSetVSFlags(ts, ovsflags);
 
     return numFailed;
 }
@@ -705,7 +710,7 @@ int rpmInstallSource(rpmts ts, const char * arg,
                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);