From 3f106364fddd50d597c4418a67818309f0f09b42 Mon Sep 17 00:00:00 2001
From: Rakesh Pandit <rakesh@fedoraproject.org>
Date: Thu, 15 Jan 2009 22:31:54 +0530
Subject: [PATCH] -Merged installInterfaceFlags and eraseInterfaceFlags into cliInterfaceFlags.
 -Moved transaction part from rpmInstall and rpmErase to rpmCliTransaction.

---
 lib/poptI.c      |   19 ++++----
 lib/rpmcli.h     |   13 +++++-
 lib/rpminstall.c |  131 ++++++++++++++++++++++--------------------------------
 rpmqv.c          |   14 +++---
 4 files changed, 80 insertions(+), 97 deletions(-)

diff --git a/lib/poptI.c b/lib/poptI.c
index 6d9cdb4..4ee5ece 100644
--- a/lib/poptI.c
+++ b/lib/poptI.c
@@ -12,8 +12,7 @@
 struct rpmInstallArguments_s rpmIArgs = {
     0,			/* transFlags */
     0,			/* probFilter */
-    0,			/* installInterfaceFlags */
-    0,			/* eraseInterfaceFlags */
+    0,			/* cliInterfaceFlags */
     0,			/* qva_flags */
     0,			/* numRelocations */
     0,			/* noDeps */
@@ -46,7 +45,7 @@ static void installArgCallback( poptContext con,
     switch (opt->val) {
 
     case 'i':
-	ia->installInterfaceFlags |= RPMCLI_INSTALL;
+	ia->cliInterfaceFlags |= RPMCLI_INSTALL;
 	break;
 
     case POPT_EXCLUDEPATH:
@@ -131,7 +130,7 @@ struct poptOption rpmInstallPoptTable[] = {
   N_("install all files, even configurations which might otherwise be skipped"),
 	NULL},
  { "allmatches", '\0', POPT_BIT_SET,
-	&rpmIArgs.eraseInterfaceFlags, RPMCLI_ALLMATCHES,
+	&rpmIArgs.cliInterfaceFlags, RPMCLI_ALLMATCHES,
 	N_("remove all packages which match <package> (normally an error is generated if <package> specified multiple packages)"),
 	NULL},
 
@@ -149,7 +148,7 @@ struct poptOption rpmInstallPoptTable[] = {
 	N_("print dependency loops as warning"), NULL},
 
  { "erase", 'e', POPT_BIT_SET,
-	&rpmIArgs.installInterfaceFlags, RPMCLI_ERASE,
+	&rpmIArgs.cliInterfaceFlags, RPMCLI_ERASE,
 	N_("erase (uninstall) package"), N_("<package>+") },
  { "excludeconfigs", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
 	&rpmIArgs.transFlags, RPMTRANS_FLAG_NOCONFIGS,
@@ -167,11 +166,11 @@ struct poptOption rpmInstallPoptTable[] = {
  { "force", '\0', 0, NULL, RPMCLI_POPT_FORCE,
 	N_("short hand for --replacepkgs --replacefiles"), NULL},
 
- { "freshen", 'F', POPT_BIT_SET, &rpmIArgs.installInterfaceFlags,
+ { "freshen", 'F', POPT_BIT_SET, &rpmIArgs.cliInterfaceFlags,
 	(RPMCLI_UPGRADE|RPMCLI_FRESHEN|RPMCLI_INSTALL),
 	N_("upgrade package(s) if already installed"),
 	N_("<packagefile>+") },
- { "hash", 'h', POPT_BIT_SET, &rpmIArgs.installInterfaceFlags, RPMCLI_HASH,
+ { "hash", 'h', POPT_BIT_SET, &rpmIArgs.cliInterfaceFlags, RPMCLI_HASH,
 	N_("print hash marks as package installs (good with -v)"), NULL},
  { "ignorearch", '\0', POPT_BIT_SET,
 	&rpmIArgs.probFilter, RPMPROB_FILTER_IGNOREARCH,
@@ -206,7 +205,7 @@ struct poptOption rpmInstallPoptTable[] = {
 	N_("don't install file security contexts"), NULL},
 
  { "noorder", '\0', POPT_BIT_SET,
-	&rpmIArgs.installInterfaceFlags, RPMCLI_NOORDER,
+	&rpmIArgs.cliInterfaceFlags, RPMCLI_NOORDER,
 	N_("do not reorder package installation to satisfy dependencies"),
 	NULL},
 
@@ -257,7 +256,7 @@ struct poptOption rpmInstallPoptTable[] = {
 	N_("upgrade to an old version of the package (--force on upgrades does this automatically)"),
 	NULL},
  { "percent", '\0', POPT_BIT_SET,
-	&rpmIArgs.installInterfaceFlags, RPMCLI_PERCENT,
+	&rpmIArgs.cliInterfaceFlags, RPMCLI_PERCENT,
 	N_("print percentages as package installs"), NULL},
  { "prefix", '\0', POPT_ARG_STRING, &rpmIArgs.prefix, 0,
 	N_("relocate the package to <dir>, if relocatable"),
@@ -274,7 +273,7 @@ struct poptOption rpmInstallPoptTable[] = {
  { "test", '\0', POPT_BIT_SET, &rpmIArgs.transFlags, RPMTRANS_FLAG_TEST,
 	N_("don't install, but tell if it would work or not"), NULL},
  { "upgrade", 'U', POPT_BIT_SET,
-	&rpmIArgs.installInterfaceFlags, (RPMCLI_UPGRADE|RPMCLI_INSTALL),
+	&rpmIArgs.cliInterfaceFlags, (RPMCLI_UPGRADE|RPMCLI_INSTALL),
 	N_("upgrade package(s)"),
 	N_("<packagefile>+") },
 
diff --git a/lib/rpmcli.h b/lib/rpmcli.h
index 1dab3f7..88ed597 100644
--- a/lib/rpmcli.h
+++ b/lib/rpmcli.h
@@ -407,8 +407,7 @@ int rpmInstallSource(rpmts ts, const char * arg,
 struct rpmInstallArguments_s {
     rpmtransFlags transFlags;
     rpmprobFilterFlags probFilter;
-    rpmCliInterfaceFlags installInterfaceFlags;
-    rpmCliInterfaceFlags eraseInterfaceFlags;
+    rpmCliInterfaceFlags cliInterfaceFlags;
     rpmQueryFlags qva_flags;	/*!< from --nodigest/--nosignature */
     int numRelocations;
     int noDeps;
@@ -440,6 +439,16 @@ int rpmInstall(rpmts ts, struct rpmInstallArguments_s * ia, ARGV_t fileArgv);
 int rpmErase(rpmts ts, struct rpmInstallArguments_s * ia, ARGV_const_t argv);
 
 /** \ingroup rpmcli
+ * Handle the transaction
+ * @param ts		transaction set
+ * @param ia		control args/bits
+ * @param numPackages	number of packages
+ * @return		0 on success
+ */
+
+int rpmCliTransaction(rpmts ts, struct rpmInstallArguments_s * ia, int numPackages);
+
+/** \ingroup rpmcli
  */
 extern struct rpmInstallArguments_s rpmIArgs;
 
diff --git a/lib/rpminstall.c b/lib/rpminstall.c
index 3d65593..e438372 100644
--- a/lib/rpminstall.c
+++ b/lib/rpminstall.c
@@ -209,8 +209,6 @@ struct rpmEIU {
 int rpmInstall(rpmts ts, struct rpmInstallArguments_s * ia, ARGV_t fileArgv)
 {
     struct rpmEIU * eiu = xcalloc(1, sizeof(*eiu));
-    rpmps ps;
-    rpmprobFilterFlags probFilter;
     rpmRelocation * relocations;
     char * fileURL = NULL;
     int stopInstall = 0;
@@ -225,10 +223,9 @@ int rpmInstall(rpmts ts, struct rpmInstallArguments_s * ia, ARGV_t fileArgv)
 
     (void) rpmtsSetFlags(ts, ia->transFlags);
 
-    probFilter = ia->probFilter;
     relocations = ia->relocations;
 
-    if (ia->installInterfaceFlags & RPMCLI_UPGRADE)
+    if (ia->cliInterfaceFlags & RPMCLI_UPGRADE)
 	vsflags = rpmExpandNumeric("%{?_vsflags_erase}");
     else
 	vsflags = rpmExpandNumeric("%{?_vsflags_install}");
@@ -241,7 +238,7 @@ int rpmInstall(rpmts ts, struct rpmInstallArguments_s * ia, ARGV_t fileArgv)
     ovsflags = rpmtsSetVSFlags(ts, (vsflags | RPMVSF_NEEDPAYLOAD));
 
     {	int notifyFlags;
-	notifyFlags = ia->installInterfaceFlags | (rpmIsVerbose() ? RPMCLI_LABEL : 0 );
+	notifyFlags = ia->cliInterfaceFlags | (rpmIsVerbose() ? RPMCLI_LABEL : 0 );
 	xx = rpmtsSetNotifyCallback(ts,
 			rpmShowProgress, (void *) ((long)notifyFlags));
     }
@@ -415,7 +412,7 @@ restart:
 	}
 
 	/* On --freshen, verify package is installed and newer */
-	if (ia->installInterfaceFlags & RPMCLI_FRESHEN) {
+	if (ia->cliInterfaceFlags & RPMCLI_FRESHEN) {
 	    rpmdbMatchIterator mi;
 	    const char * name;
 	    Header oldH;
@@ -440,7 +437,7 @@ restart:
 	}
 
 	rc = rpmtsAddInstallElement(ts, eiu->h, (fnpyKey)fileName,
-			(ia->installInterfaceFlags & RPMCLI_UPGRADE) != 0,
+			(ia->cliInterfaceFlags & RPMCLI_UPGRADE) != 0,
 			relocations);
 
 	/* XXX reference held by transaction set */
@@ -513,54 +510,16 @@ maybe_manifest:
 
     if (eiu->numFailed) goto exit;
 
-    if (eiu->numRPMS && !(ia->installInterfaceFlags & RPMCLI_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;
-	}
-	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 & RPMCLI_NOORDER)) {
-	if (rpmtsOrder(ts)) {
-	    eiu->numFailed = eiu->numPkgs;
-	    stopInstall = 1;
-	}
-    }
-
-    if (eiu->numRPMS && !stopInstall) {
-
+    if ((eiu->numSRPMS && !stopInstall) && eiu->sourceURL != NULL) {
 	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)
 	for (i = 0; i < eiu->numSRPMS; i++) {
 	    rpmdbCheckSignals();
 	    if (eiu->sourceURL[i] == NULL) continue;
@@ -609,10 +568,8 @@ int rpmErase(rpmts ts, struct rpmInstallArguments_s * ia, ARGV_const_t argv)
     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;
 
@@ -632,7 +589,7 @@ int rpmErase(rpmts ts, struct rpmInstallArguments_s * ia, ARGV_const_t argv)
 
 #ifdef	NOTYET	/* XXX no callbacks on erase yet */
     {	int notifyFlags, xx;
-	notifyFlags = ia->eraseInterfaceFlags | (rpmIsVerbose() ? RPMCLI_LABEL : 0 );
+	notifyFlags = ia->cliInterfaceFlags | (rpmIsVerbose() ? RPMCLI_LABEL : 0 );
 	xx = rpmtsSetNotifyCallback(ts,
 			rpmShowProgress, (void *) ((long)notifyFlags));
     }
@@ -658,7 +615,7 @@ int rpmErase(rpmts ts, struct rpmInstallArguments_s * ia, ARGV_const_t argv)
 	    Header h;	/* XXX iterator owns the reference */
 
 	    if (matches > 1 && 
-		!(ia->eraseInterfaceFlags & RPMCLI_ALLMATCHES)) {
+		!(ia->cliInterfaceFlags & RPMCLI_ALLMATCHES)) {
 		rpmlog(RPMLOG_ERR, _("\"%s\" specifies multiple packages:\n"),
 			*arg);
 		numFailed++;
@@ -683,49 +640,67 @@ int rpmErase(rpmts ts, struct rpmInstallArguments_s * ia, ARGV_const_t argv)
 
     if (numFailed) goto exit;
 
-    if (!(ia->eraseInterfaceFlags & RPMCLI_NODEPS)) {
+    numFailed = rpmCliTransaction(ts, ia, numPackages);
+exit:
+    rpmtsEmpty(ts);
+
+    return numFailed;
+}
+
+int rpmCliTransaction(rpmts ts, struct rpmInstallArguments_s * ia,
+		      int numPackages)
+{
+    rpmps ps;
+
+    int rc = 0;
+    int stop = 0;
+
+    int eflags = ia->cliInterfaceFlags & RPMCLI_ERASE;
+
+    if (!(ia->cliInterfaceFlags & RPMCLI_NODEPS)) {
 
 	if (rpmtsCheck(ts)) {
-	    numFailed = numPackages;
-	    stopUninstall = 1;
+	    rc = numPackages;
+	    stop = 1;
 	}
 
 	ps = rpmtsProblems(ts);
-	if (!stopUninstall && rpmpsNumProblems(ps) > 0) {
+	if (!stop && rpmpsNumProblems(ps) > 0) {
 	    rpmlog(RPMLOG_ERR, _("Failed dependencies:\n"));
 	    rpmpsPrint(NULL, ps);
-	    numFailed += numPackages;
-	    stopUninstall = 1;
+	    rc = numPackages;
+	    stop = 1;
 	}
 	ps = rpmpsFree(ps);
     }
 
-    if (!stopUninstall && !(ia->installInterfaceFlags & RPMCLI_NOORDER)) {
+    if ((eflags? 1 : (!stop)) && !(ia->cliInterfaceFlags & RPMCLI_NOORDER)) {
 	if (rpmtsOrder(ts)) {
-	    numFailed += numPackages;
-	    stopUninstall = 1;
+	    rc = numPackages;
+	    stop = 1;
 	}
     }
 
-    if (numPackages && !stopUninstall) {
-	(void) rpmtsSetFlags(ts, (rpmtsFlags(ts) | RPMTRANS_FLAG_REVERSE));
+    if (numPackages && !stop) {
 
-	/* Drop added/available package indices and dependency sets. */
-	rpmtsClean(ts);
+	if (eflags) {
+	    rpmlog(RPMLOG_DEBUG, "erasing packages\n");
+	    rpmtsClean(ts);
+	    rc = rpmtsRun(ts, NULL, ia->probFilter & (RPMPROB_FILTER_DISKSPACE|RPMPROB_FILTER_DISKNODES));
+	} else {
+	    rpmlog(RPMLOG_DEBUG, "installing binary packages\n");
+	    rpmtsClean(ts);
+	    rc = rpmtsRun(ts, NULL, ia->probFilter);
+	}
 
-	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;
+
+	if ((rpmpsNumProblems(ps) > 0) && (eflags? 1 : (rc > 0)))
+	    rpmpsPrint((eflags? NULL : stderr), ps);
 	ps = rpmpsFree(ps);
     }
 
-exit:
-    rpmtsEmpty(ts);
-
-    return numFailed;
+    return rc;
 }
 
 int rpmInstallSource(rpmts ts, const char * arg,
diff --git a/rpmqv.c b/rpmqv.c
index eaa3aee..f73f8fc 100644
--- a/rpmqv.c
+++ b/rpmqv.c
@@ -357,9 +357,9 @@ int main(int argc, char *argv[])
 
 #ifdef	IAM_RPMEIU
   if (bigMode == MODE_UNKNOWN || (bigMode & MODES_IE))
-    {	int iflags = (ia->installInterfaceFlags &
+    {	int iflags = (ia->cliInterfaceFlags &
 		(RPMCLI_UPGRADE|RPMCLI_FRESHEN|RPMCLI_INSTALL));
-	int eflags = (ia->installInterfaceFlags & RPMCLI_ERASE);
+	int eflags = (ia->cliInterfaceFlags & RPMCLI_ERASE);
 
 	if (iflags & eflags)
 	    argerror(_("only one major mode may be specified"));
@@ -410,11 +410,11 @@ int main(int argc, char *argv[])
     if (ia->prefix && ia->prefix[0] != '/') 
 	argerror(_("arguments to --prefix must begin with a /"));
 
-    if (bigMode != MODE_INSTALL && (ia->installInterfaceFlags & RPMCLI_HASH))
+    if (bigMode != MODE_INSTALL && (ia->cliInterfaceFlags & RPMCLI_HASH))
 	argerror(_("--hash (-h) may only be specified during package "
 			"installation"));
 
-    if (bigMode != MODE_INSTALL && (ia->installInterfaceFlags & RPMCLI_PERCENT))
+    if (bigMode != MODE_INSTALL && (ia->cliInterfaceFlags & RPMCLI_PERCENT))
 	argerror(_("--percent may only be specified during package "
 			"installation"));
 
@@ -447,7 +447,7 @@ int main(int argc, char *argv[])
 	argerror(_("--ignoresize may only be specified during package "
 		   "installation"));
 
-    if ((ia->eraseInterfaceFlags & RPMCLI_ALLMATCHES) && bigMode != MODE_ERASE)
+    if ((ia->cliInterfaceFlags & RPMCLI_ALLMATCHES) && bigMode != MODE_ERASE)
 	argerror(_("--allmatches may only be specified during package "
 		   "erasure"));
 
@@ -711,7 +711,7 @@ int main(int argc, char *argv[])
 
 #ifdef	IAM_RPMEIU
     case MODE_ERASE:
-	if (ia->noDeps) ia->eraseInterfaceFlags |= RPMCLI_NODEPS;
+	if (ia->noDeps) ia->cliInterfaceFlags |= RPMCLI_NODEPS;
 
 	if (!poptPeekArg(optCon)) {
 	    argerror(_("no packages given for erase"));
@@ -731,7 +731,7 @@ int main(int argc, char *argv[])
 		ia->transFlags |= RPMTRANS_FLAG_NODOCS;
 	}
 
-	if (ia->noDeps) ia->installInterfaceFlags |= RPMCLI_NODEPS;
+	if (ia->noDeps) ia->cliInterfaceFlags |= RPMCLI_NODEPS;
 
 	/* we've already ensured !(!ia->prefix && !ia->relocations) */
 	if (ia->prefix) {
-- 
1.6.0.6

