[Rpm-maint] PATCH:re-factoring rpmInstall & rpmErase - merging similar rpmInstall rpmErase transaction part
Rakesh Pandit
rakesh.pandit at gmail.com
Tue Dec 2 19:18:05 UTC 2008
Hello list
Second patch[1]:
Moved transaction part from rpmInstall and rpmErase to rpmCliTransaction.
[1] http://rakesh.fedorapeople.org/misc/second.patch
Review ?
--
Regards,
rakesh
commit fe17d655c5c45a164be2f3802007837b8724a93e
Author: =Rakesh Pandit <rakesh at fedoraproject.org>
Date: Tue Dec 2 11:17:43 2008 +0530
Moved transaction part from rpmInstall and rpmErase to rpmCliTransaction.
diff --git a/lib/rpmcli.h b/lib/rpmcli.h
index 1dab3f7..841f516 100644
--- a/lib/rpmcli.h
+++ b/lib/rpmcli.h
@@ -440,6 +440,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..fbed2bc 100644
--- a/lib/rpminstall.c
+++ b/lib/rpminstall.c
@@ -209,7 +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;
@@ -394,6 +393,7 @@ restart:
*eiu->fnp = NULL;
eiu->numSRPMS++;
eiu->sourceURL[eiu->numSRPMS] = NULL;
+ rpmcliPackagesTotal += eiu->numSRPMS;
continue;
}
@@ -513,50 +513,10 @@ 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 && !(ia->installInterfaceFlags & RPMCLI_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->numRPMS) {
+ eiu->numFailed = rpmCliTransaction(ts, ia, eiu->numPkgs);
+ if (eiu->numFailed < 0)
+ eiu->numFailed += eiu->numRPMS;
}
if (eiu->numSRPMS && !stopInstall) {
@@ -609,10 +569,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;
@@ -683,49 +641,66 @@ int rpmErase(rpmts ts, struct
rpmInstallArguments_s * ia, ARGV_const_t argv)
if (numFailed) goto exit;
+ 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->installInterfaceFlags & RPMCLI_ERASE;
+
if (!(ia->eraseInterfaceFlags & 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->installInterfaceFlags &
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) {
+
+ if (eflags) {
+ rpmlog(RPMLOG_DEBUG, "erasing packages\n");
+ } else {
+ rpmlog(RPMLOG_DEBUG, "installing binary packages\n");
+ }
- /* Drop added/available package indices and dependency sets. */
rpmtsClean(ts);
- numPackages = rpmtsRun(ts, NULL, ia->probFilter &
(RPMPROB_FILTER_DISKSPACE|RPMPROB_FILTER_DISKNODES));
+ rc = 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,
More information about the Rpm-maint
mailing list