RPM Package Manager, CVS Repository
http://rpm5.org/cvs/
____________________________________________________________________________
Server: rpm5.org Name: Jeff Johnson
Root: /v/rpm/cvs Email: jbj@rpm5.org
Module: rpm Date: 18-Aug-2007 18:29:21
Branch: HEAD Handle: 2007081817292001
Modified files:
rpm CHANGES rpmqv.c
rpm/lib librpm.vers rpmcli.h rpminstall.c rpmrollback.c
Log:
- more rpmInstall refactoring.
Summary:
Revision Changes Path
1.1584 +1 -0 rpm/CHANGES
1.8 +5 -1 rpm/lib/librpm.vers
2.70 +53 -4 rpm/lib/rpmcli.h
1.159 +80 -86 rpm/lib/rpminstall.c
1.9 +1 -0 rpm/lib/rpmrollback.c
1.125 +1 -1 rpm/rpmqv.c
____________________________________________________________________________
patch -p0 <<'@@ .'
Index: rpm/CHANGES
============================================================================
$ cvs diff -u -r1.1583 -r1.1584 CHANGES
--- rpm/CHANGES 17 Aug 2007 19:42:10 -0000 1.1583
+++ rpm/CHANGES 18 Aug 2007 16:29:20 -0000 1.1584
@@ -1,4 +1,5 @@
4.5 -> 5.0:
+ - jbj: more rpmInstall refactoring.
- jbj: use rpmgi for --addsign/--checksig arg iteration.
- jbj: repair a minor rpmInstall and major matchpathcon_init() memleaks.
- jbj: unbreak --install/--upgrade/--freshen, memleaks checked.
@@ .
patch -p0 <<'@@ .'
Index: rpm/lib/librpm.vers
============================================================================
$ cvs diff -u -r1.7 -r1.8 librpm.vers
--- rpm/lib/librpm.vers 9 Aug 2007 22:45:30 -0000 1.7
+++ rpm/lib/librpm.vers 18 Aug 2007 16:29:21 -0000 1.8
@@ -77,6 +77,11 @@
rpmcliHashesTotal;
rpmcliImportPubkey;
rpmcliInit;
+ rpmcliInstall;
+ rpmcliInstallCheck;
+ rpmcliInstallOrder;
+ rpmcliInstallProblems;
+ rpmcliInstallSuggests;
rpmcliPackagesTotal;
rpmcliPipeOutput;
rpmcliProgressCurrent;
@@ -218,7 +223,6 @@
rpmgiTs;
rpmHeaderFormats;
rpmIArgs;
- rpmInstall;
rpmInstallPoptTable;
rpmInstallSource;
rpmInstallSourcePackage;
@@ .
patch -p0 <<'@@ .'
Index: rpm/lib/rpmcli.h
============================================================================
$ cvs diff -u -r2.69 -r2.70 rpmcli.h
--- rpm/lib/rpmcli.h 24 Jul 2007 14:36:47 -0000 2.69
+++ rpm/lib/rpmcli.h 18 Aug 2007 16:29:21 -0000 2.70
@@ -433,7 +433,7 @@
/* --- install/upgrade/erase modes */
/** \ingroup rpmcli
- * Bit(s) to control rpmInstall() and rpmErase() operation.
+ * Bit(s) to control rpmcliInstall() and rpmErase() operation.
*/
typedef enum rpmInstallInterfaceFlags_e {
INSTALL_NONE = 0,
@@ -507,14 +507,63 @@
fileSystem, internalState @*/;
/** \ingroup rpmcli
+ * Report package problems (if any).
+ * @param ts transaction set
+ * @param msg problem context string to display
+ * @param rc result of a tranbsaction operation
+ * @return no. of (added) packages
+ */
+int rpmcliInstallProblems(rpmts ts, /*@null@*/ const char * msg, int rc)
+ /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
+ /*@modifies ts, rpmGlobalMacroContext, fileSystem, internalState @*/;
+
+/** \ingroup rpmcli
+ * Report packages(if any) that satisfy unresolved dependencies.
+ * @param ts transaction set
+ * @return 0 always
+ */
+int rpmcliInstallSuggests(rpmts ts)
+ /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
+ /*@modifies ts, rpmGlobalMacroContext, fileSystem, internalState @*/;
+
+/** \ingroup rpmcli
+ * Check package element dependencies in a transaction set, reporting problems.
+ * @param ts transaction set
+ * @return no. of (added) packages
+ */
+int rpmcliInstallCheck(rpmts ts)
+ /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
+ /*@modifies ts, rpmGlobalMacroContext, fileSystem, internalState @*/;
+
+/** \ingroup rpmcli
+ * Order package elements in a transaction set, reporting problems.
+ * @param ts transaction set
+ * @return no. of (added) packages
+ */
+int rpmcliInstallOrder(rpmts ts)
+ /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
+ /*@modifies ts, rpmGlobalMacroContext, fileSystem, internalState @*/;
+
+/** \ingroup rpmcli
+ * Install/erase package elements in a transaction set, reporting problems.
+ * @param ts transaction set
+ * @param okProbs previously known problems (or NULL)
+ * @param ignoreSet bits to filter problem types
+ * @return 0 on success, -1 on error, >0 no, of failed elements
+ */
+int rpmcliInstallRun(rpmts ts, rpmps okProbs, rpmprobFilterFlags ignoreSet)
+ /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
+ /*@modifies ts, rpmGlobalMacroContext, fileSystem, internalState @*/;
+
+/** \ingroup rpmcli
* Install/upgrade/freshen binary rpm package.
* @todo Use rpmdsCompare rather than rpmVersionCompare.
* @param ts transaction set
* @param ia mode flags and parameters
- * @param fileArgv array of package file names (NULL terminated)
+ * @param argv array of package file names (NULL terminated)
* @return 0 on success
*/
-int rpmInstall(rpmts ts, QVA_t ia, /*@null@*/ const char ** fileArgv)
+int rpmcliInstall(rpmts ts, QVA_t ia, /*@null@*/ const char ** argv)
/*@globals rpmcliPackagesTotal, rpmGlobalMacroContext, h_errno,
fileSystem, internalState@*/
/*@modifies ts, ia, rpmcliPackagesTotal, rpmGlobalMacroContext,
@@ -524,7 +573,7 @@
* Erase binary rpm package.
* @param ts transaction set
* @param ia control args/bits
- * @param argv array of package file names (NULL terminated)
+ * @param argv array of package names (NULL terminated)
* @return 0 on success
*/
int rpmErase(rpmts ts, QVA_t ia, /*@null@*/ const char ** argv)
@@ .
patch -p0 <<'@@ .'
Index: rpm/lib/rpminstall.c
============================================================================
$ cvs diff -u -r1.158 -r1.159 rpminstall.c
--- rpm/lib/rpminstall.c 17 Aug 2007 19:42:11 -0000 1.158
+++ rpm/lib/rpminstall.c 18 Aug 2007 16:29:21 -0000 1.159
@@ -255,28 +255,70 @@
return rc;
}
-typedef /*@only@*/ /*@null@*/ const char * str_t;
+int rpmcliInstallProblems(rpmts ts, const char * msg, int rc)
+ /*@globals fileSystem @*/
+ /*@modifies ts, fileSystem @*/
+{
+ rpmps ps = rpmtsProblems(ts);
+
+ if (rc && rpmpsNumProblems(ps) > 0) {
+ if (msg)
+ rpmMessage(RPMMESS_ERROR, "%s:\n", msg);
+ rpmpsPrint(NULL, ps);
+ }
+ ps = rpmpsFree(ps);
+ return rc;
+}
+
+int rpmcliInstallSuggests(rpmts ts)
+{
+ if (ts->suggests != NULL && ts->nsuggests > 0) {
+ const char * s;
+ int i;
+
+ rpmMessage(RPMMESS_NORMAL, _(" Suggested resolutions:\n"));
+ for (i = 0; i < ts->nsuggests && (s = ts->suggests[i]) != NULL;
+ ts->suggests[i++] = s = _free(s))
+ {
+ rpmMessage(RPMMESS_NORMAL, "\t%s\n", s);
+ }
+ ts->suggests = _free(ts->suggests);
+ }
+ return 0;
+}
+
+int rpmcliInstallCheck(rpmts ts)
+{
+ return rpmcliInstallProblems(ts, _("Failed dependencies"), rpmtsCheck(ts));
+}
+
+int rpmcliInstallOrder(rpmts ts)
+{
+ return rpmcliInstallProblems(ts, _("Ordering problems"), rpmtsOrder(ts));
+}
+
+int rpmcliInstallRun(rpmts ts, rpmps okProbs, rpmprobFilterFlags ignoreSet)
+{
+ return rpmcliInstallProblems(ts, _("Install/Erase problems"),
+ rpmtsRun(ts, okProbs, ignoreSet));
+}
+
/** @todo Generalize --freshen policies. */
/*@-bounds@*/
-int rpmInstall(rpmts ts, QVA_t ia, const char ** fileArgv)
+int rpmcliInstall(rpmts ts, QVA_t ia, const char ** argv)
{
int numFailed = 0;
- int numPkgs = 0;
int numRPMS = 0;
- int numSRPMS = 0;
- str_t * sourceURL = NULL;
+ ARGV_t sourceURL = NULL;
rpmRelocation relocations = NULL;
rpmRC rpmrc = RPMRC_OK;
-
- rpmps ps;
- int stopInstall = 0;
rpmVSFlags vsflags, ovsflags;
int rc;
int xx;
int i;
- if (fileArgv == NULL) goto exit;
+ if (argv == NULL) goto exit;
ts->goal = TSM_INSTALL;
rpmcliPackagesTotal = 0;
@@ -359,28 +401,24 @@
int _ftsOpts = 0;
rpmgiFlags _giFlags = RPMGI_NONE;
- rc = rpmgiSetArgs(gi, fileArgv, _ftsOpts, _giFlags);
+ rc = rpmgiSetArgs(gi, argv, _ftsOpts, _giFlags);
while (rpmgiNext(gi) == RPMRC_OK) {
Header h = rpmgiHeader(gi);
- const char * fileName;
+ const char * fn;
int isSource;
if (h == NULL) {
numFailed++;
continue;
}
- fileName = rpmgiHdrPath(gi);
+ fn = rpmgiHdrPath(gi);
/* === Check for source package, saving for delayed installs. */
isSource = (headerIsEntry(h, RPMTAG_SOURCERPM) == 0);
if (isSource) {
rpmMessage(RPMMESS_DEBUG, D_("\tadded source package [%d]: %s\n"),
- numSRPMS, fileName);
- sourceURL = xrealloc(sourceURL,
- (numSRPMS + 2) * sizeof(*sourceURL));
- sourceURL[numSRPMS] = xstrdup(fileName);;
- numSRPMS++;
- sourceURL[numSRPMS] = NULL;
+ argvCount(sourceURL), fn);
+ argvAdd(&sourceURL, fn);
continue;
}
@@ -406,7 +444,7 @@
}
}
- /* === On --freshen, verify package is installed and newer */
+ /* === On --freshen, verify package is installed and newer. */
if (ia->installInterfaceFlags & INSTALL_FRESHEN) {
rpmdbMatchIterator mi;
const char * name;
@@ -430,7 +468,7 @@
}
/* === Add binary package to transaction set. */
- rc = rpmtsAddInstallElement(ts, h, (fnpyKey)fileName,
+ rc = rpmtsAddInstallElement(ts, h, (fnpyKey)fn,
(ia->installInterfaceFlags & INSTALL_UPGRADE) != 0,
ia->relocations);
@@ -438,7 +476,7 @@
relocations->oldPath = _free(relocations->oldPath);
rpmMessage(RPMMESS_DEBUG, D_("\tadded binary package [%d]: %s\n"),
- numRPMS, fileName);
+ numRPMS, fn);
numRPMS++;
}
@@ -448,78 +486,38 @@
} /* end-of-transaction-build */
rpmMessage(RPMMESS_DEBUG, D_("found %d source and %d binary packages\n"),
- numSRPMS, numRPMS);
+ argvCount(sourceURL), numRPMS);
if (numFailed) goto exit;
- if (numRPMS && !(ia->installInterfaceFlags & INSTALL_NODEPS)) {
+ rpmcliPackagesTotal += argvCount(sourceURL);
- if (rpmtsCheck(ts)) {
- numFailed = numPkgs;
- stopInstall = 1;
+ if (numRPMS) {
+ if (!(ia->installInterfaceFlags & INSTALL_NODEPS)
+ && (rc = rpmcliInstallCheck(ts)) != 0) {
+ numFailed = (numRPMS + argvCount(sourceURL));
+ (void) rpmcliInstallSuggests(ts);
}
- ps = rpmtsProblems(ts);
- if (!stopInstall && rpmpsNumProblems(ps) > 0) {
- rpmMessage(RPMMESS_ERROR, _("Failed dependencies:\n"));
- rpmpsPrint(NULL, ps);
- numFailed = numPkgs;
- stopInstall = 1;
-
- /*@-branchstate@*/
- if (ts->suggests != NULL && ts->nsuggests > 0) {
- rpmMessage(RPMMESS_NORMAL, _(" Suggested resolutions:\n"));
- for (i = 0; i < ts->nsuggests; i++) {
- const char * str = ts->suggests[i];
-
- if (str == NULL)
- break;
-
- rpmMessage(RPMMESS_NORMAL, "\t%s\n", str);
-
- ts->suggests[i] = NULL;
- str = _free(str);
- }
- ts->suggests = _free(ts->suggests);
- }
- /*@=branchstate@*/
- }
- ps = rpmpsFree(ps);
- }
-
- if (numRPMS && !(ia->installInterfaceFlags & INSTALL_NOORDER)) {
- if (rpmtsOrder(ts)) {
- numFailed = numPkgs;
- stopInstall = 1;
- }
- }
-
- if (numRPMS && !stopInstall) {
-
- rpmcliPackagesTotal += numSRPMS;
-
- rpmMessage(RPMMESS_DEBUG, D_("installing binary packages\n"));
+ if (!(ia->installInterfaceFlags & INSTALL_NOORDER)
+ && (rc = rpmcliInstallOrder(ts)) != 0)
+ numFailed = (numRPMS + argvCount(sourceURL));
/* Drop added/available package indices and dependency sets. */
rpmtsClean(ts);
- rc = rpmtsRun(ts, NULL, ia->probFilter);
- ps = rpmtsProblems(ts);
-
- if (rc < 0) {
- numFailed += numRPMS;
- } else if (rc > 0) {
- numFailed += rc;
- if (rpmpsNumProblems(ps) > 0)
- rpmpsPrint(stderr, ps);
- }
- ps = rpmpsFree(ps);
+ if (numFailed == 0
+ && (rc = rpmcliInstallRun(ts, NULL, ia->probFilter)) != 0)
+ numFailed += (rc < 0 ? numRPMS : rc) + argvCount(sourceURL);
}
- if (numSRPMS && !stopInstall) {
- if (sourceURL != NULL)
+ if (numFailed) goto exit;
+
+ if (sourceURL) {
+ int numSRPMS = argvCount(sourceURL);
+ FD_t fd;
+
for (i = 0; i < numSRPMS; i++) {
- FD_t fd;
if (sourceURL[i] == NULL) continue;
fd = Fopen(sourceURL[i], "r.fdio");
if (fd == NULL || Ferror(fd)) {
@@ -543,14 +541,10 @@
}
exit:
- if (sourceURL != NULL)
- for (i = 0; i < numSRPMS; i++)
- sourceURL[i] = _free(sourceURL[i]);
- sourceURL = _free(sourceURL);
+ sourceURL = argvFree(sourceURL);
- if (!(ia->transFlags & RPMTRANS_FLAG_NOCONTEXTS)) {
+ if (!(ia->transFlags & RPMTRANS_FLAG_NOCONTEXTS))
matchpathcon_fini();
- }
rpmtsEmpty(ts);
@@ .
patch -p0 <<'@@ .'
Index: rpm/lib/rpmrollback.c
============================================================================
$ cvs diff -u -r1.8 -r1.9 rpmrollback.c
--- rpm/lib/rpmrollback.c 30 Jul 2007 01:40:35 -0000 1.8
+++ rpm/lib/rpmrollback.c 18 Aug 2007 16:29:21 -0000 1.9
@@ -397,6 +397,7 @@
return rpmrbProblems(ts, N_("Ordering problems"), rpmtsOrder(ts));
}
+/** @todo Use rpmInstallRun instead. */
int rpmrbRun(rpmts ts, rpmps okProbs, rpmprobFilterFlags ignoreSet)
{
return rpmrbProblems(ts, N_("Rollback problems"),
@@ .
patch -p0 <<'@@ .'
Index: rpm/rpmqv.c
============================================================================
$ cvs diff -u -r1.124 -r1.125 rpmqv.c
--- rpm/rpmqv.c 16 Aug 2007 18:30:51 -0000 1.124
+++ rpm/rpmqv.c 18 Aug 2007 16:29:20 -0000 1.125
@@ -712,7 +712,7 @@
/*@i@*/ ec += rpmRollback(ts, ia, NULL);
} else {
/*@-compdef -compmempass@*/ /* FIX: ia->relocations[0].newPath undefined */
- ec += rpmInstall(ts, ia, (const char **)poptGetArgs(optCon));
+ ec += rpmcliInstall(ts, ia, (const char **)poptGetArgs(optCon));
/*@=compdef =compmempass@*/
}
break;
@@ .
Received on Sat Aug 18 18:29:21 2007