[Rpm-maint] [PATCH] Move header reading part from rpminstall to tryReadHeader function.

Rakesh Pandit rakesh.pandit at gmail.com
Wed Mar 11 06:52:50 UTC 2009


Is tryReadHeader a good name ?

- Move header reading part from rpminstall to tryReadHeader function.

Patch: http://rakesh.fedorapeople.org/rpm/0001--Move-header-reading-part-from-rpminstall-to-tryRea.patch

*Patch also involves removal of "-#include "lib/misc.h"		/* XXX
rpmMkdirPath */" I could not find anything with rpmMkdirPath.

--
Regards,
Rakesh Pandit

>From 571d30a74998fc855ae5e0c53cbc7adaccca58ac Mon Sep 17 00:00:00 2001
From: Rakesh Pandit <rakesh at fedoraproject.org>
Date: Wed, 11 Mar 2009 12:11:40 +0530
Subject: [PATCH] - Move header reading part from rpminstall to
tryReadHeader function.

---
 lib/psm.c        |    1 -
 lib/rpminstall.c |   78 ++++++++++++++++++++++++++++-------------------------
 2 files changed, 41 insertions(+), 38 deletions(-)

diff --git a/lib/psm.c b/lib/psm.c
index b493b33..f7e4457 100644
--- a/lib/psm.c
+++ b/lib/psm.c
@@ -24,7 +24,6 @@
 #include "lib/rpmte_internal.h"	/* XXX internal apis */
 #include "lib/rpmlead.h"		/* writeLead proto */
 #include "lib/signature.h"		/* signature constants */
-#include "lib/misc.h"		/* XXX rpmMkdirPath */

 #include "debug.h"

diff --git a/lib/rpminstall.c b/lib/rpminstall.c
index 9fb4767..b1f558c 100644
--- a/lib/rpminstall.c
+++ b/lib/rpminstall.c
@@ -322,6 +322,43 @@ static int tryReadManifest(struct rpmEIU * eiu)
     return rc;
 }

+static int tryReadHeader(rpmts ts, struct rpmEIU * eiu, rpmVSFlags vsflags)
+{
+
+   int rc, xx;
+   rpmVSFlags tvsflags;
+
+   /* Try to read the header from a package file. */
+   eiu->fd = Fopen(*eiu->fnp, "r.ufdio");
+   if (eiu->fd == NULL || Ferror(eiu->fd)) {
+       rpmlog(RPMLOG_ERR, _("open of %s failed: %s\n"), *eiu->fnp,
+	      Fstrerror(eiu->fd));
+       if (eiu->fd != NULL) {
+           xx = Fclose(eiu->fd);
+	   eiu->fd = NULL;
+       }
+       eiu->numFailed++; *eiu->fnp = NULL;
+       return RPMRC_FAIL;
+   }
+
+   /* Read the header, verifying signatures (if present). */
+   tvsflags = rpmtsSetVSFlags(ts, vsflags);
+   eiu->rpmrc = rpmReadPackageFile(ts, eiu->fd, *eiu->fnp, &eiu->h);
+   tvsflags = rpmtsSetVSFlags(ts, tvsflags);
+   xx = Fclose(eiu->fd);
+   eiu->fd = NULL;
+
+   /* Honor --nomanifest */
+   if (eiu->rpmrc == RPMRC_NOTFOUND && (giFlags & RPMGI_NOMANIFEST))
+       eiu->rpmrc = RPMRC_FAIL;
+
+   if(eiu->rpmrc == RPMRC_FAIL) {
+       rpmlog(RPMLOG_ERR, _("%s cannot be installed\n"), *eiu->fnp);
+       eiu->numFailed++; *eiu->fnp = NULL;
+   }
+
+   return RPMRC_OK;
+}

 /** @todo Generalize --freshen policies. */
 int rpmInstall(rpmts ts, struct rpmInstallArguments_s * ia, ARGV_t fileArgv)
@@ -329,7 +366,7 @@ int rpmInstall(rpmts ts, struct
rpmInstallArguments_s * ia, ARGV_t fileArgv)
     struct rpmEIU * eiu = xcalloc(1, sizeof(*eiu));
     rpmRelocation * relocations;
     char * fileURL = NULL;
-    rpmVSFlags vsflags, ovsflags, tvsflags;
+    rpmVSFlags vsflags, ovsflags;
     int rc;
     int xx;
     int i;
@@ -448,48 +485,15 @@ restart:
 	rpmlog(RPMLOG_DEBUG, "============== %s\n", *eiu->fnp);
 	(void) urlPath(*eiu->fnp, &fileName);

-	/* Try to read the header from a package file. */
-	eiu->fd = Fopen(*eiu->fnp, "r.ufdio");
-	if (eiu->fd == NULL || Ferror(eiu->fd)) {
-	    rpmlog(RPMLOG_ERR, _("open of %s failed: %s\n"), *eiu->fnp,
-			Fstrerror(eiu->fd));
-	    if (eiu->fd != NULL) {
-		xx = Fclose(eiu->fd);
-		eiu->fd = NULL;
-	    }
-	    eiu->numFailed++; *eiu->fnp = NULL;
+	if (tryReadHeader(ts, eiu, vsflags) == RPMRC_FAIL)
 	    continue;
-	}

-	/* Read the header, verifying signatures (if present). */
-	tvsflags = rpmtsSetVSFlags(ts, vsflags);
-	eiu->rpmrc = rpmReadPackageFile(ts, eiu->fd, *eiu->fnp, &eiu->h);
-	tvsflags = rpmtsSetVSFlags(ts, tvsflags);
-	xx = Fclose(eiu->fd);
-	eiu->fd = NULL;
-
-	/* Honor --nomanifest */
-	if (eiu->rpmrc == RPMRC_NOTFOUND && (giFlags & RPMGI_NOMANIFEST))
-	    eiu->rpmrc = RPMRC_FAIL;
-
-	switch (eiu->rpmrc) {
-	case RPMRC_FAIL:
-	    rpmlog(RPMLOG_ERR, _("%s cannot be installed\n"), *eiu->fnp);
-	    eiu->numFailed++; *eiu->fnp = NULL;
-	    continue;
-	    break;
-	case RPMRC_NOTFOUND:
+	if (eiu->rpmrc == RPMRC_NOTFOUND) {
 	    rc = tryReadManifest(eiu);
 	    if (rc == RPMRC_OK) {
 	        eiu->prevx++;
-		goto restart;
+	        goto restart;
 	    }
-	    break;
-	case RPMRC_NOTTRUSTED:
-	case RPMRC_NOKEY:
-	case RPMRC_OK:
-	default:
-	    break;
 	}

 	eiu->isSource = headerIsSource(eiu->h);
-- 
1.6.0.6


More information about the Rpm-maint mailing list