Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/pkgviews]: src/usr.sbin/pkg_install Consistently use _pkgdb_getPKGDB_DIR...



details:   https://anonhg.NetBSD.org/src/rev/40af066edc4e
branches:  pkgviews
changeset: 534256:40af066edc4e
user:      jlam <jlam%NetBSD.org@localhost>
date:      Wed Aug 20 01:52:38 2003 +0000

description:
Consistently use _pkgdb_getPKGDB_DIR() to return the location of the
package registry instead of using the following idiom over and over and
over again:

        char *dbdir, *tmp;
        dbdir = (tmp = getenv(PKG_DBDIR)) ? tmp : DEF_LOG_DIR;

This is faster anyway -- _pkgdb_getPKGDB_DIR() caches the value instead of
doing the lookup every time.

diffstat:

 usr.sbin/pkg_install/add/perform.c    |   9 ++++-----
 usr.sbin/pkg_install/delete/main.c    |   7 +++----
 usr.sbin/pkg_install/delete/perform.c |  34 +++++++++++++---------------------
 usr.sbin/pkg_install/info/main.c      |   7 +++----
 usr.sbin/pkg_install/info/perform.c   |  21 +++++++++------------
 5 files changed, 32 insertions(+), 46 deletions(-)

diffs (truncated from 315 to 300 lines):

diff -r c33b7c38cd20 -r 40af066edc4e usr.sbin/pkg_install/add/perform.c
--- a/usr.sbin/pkg_install/add/perform.c        Mon Aug 18 20:44:26 2003 +0000
+++ b/usr.sbin/pkg_install/add/perform.c        Wed Aug 20 01:52:38 2003 +0000
@@ -1,11 +1,11 @@
-/*     $NetBSD: perform.c,v 1.70.2.5 2003/08/18 04:58:07 jlam Exp $    */
+/*     $NetBSD: perform.c,v 1.70.2.6 2003/08/20 01:52:38 jlam Exp $    */
 
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static const char *rcsid = "from FreeBSD Id: perform.c,v 1.44 1997/10/13 15:03:46 jkh Exp";
 #else
-__RCSID("$NetBSD: perform.c,v 1.70.2.5 2003/08/18 04:58:07 jlam Exp $");
+__RCSID("$NetBSD: perform.c,v 1.70.2.6 2003/08/20 01:52:38 jlam Exp $");
 #endif
 #endif
 
@@ -67,7 +67,6 @@
 static int
 installprereq(const char *name, int *errc)
 {
-       char    *tmp;
        int     ret;
        ret = 0;
 
@@ -111,7 +110,7 @@
        char    replace_via[FILENAME_MAX];
        char    replace_to[FILENAME_MAX];
        int     replacing = 0;
-       char   *where_to, *tmp, *extract;
+       char   *where_to, *extract;
        char   *dbdir;
        const char *exact;
        FILE   *cfile;
@@ -127,7 +126,7 @@
        LogDir[0] = '\0';
        strlcpy(playpen, FirstPen, sizeof(playpen));
        inPlace = 0;
-       dbdir = (tmp = getenv(PKG_DBDIR)) ? tmp : DEF_LOG_DIR;
+       dbdir = _pkgdb_getPKGDB_DIR();
 
        /* make sure dbdir actually exists! */
        if (!(isdir(dbdir) || islinktodir(dbdir))) {
diff -r c33b7c38cd20 -r 40af066edc4e usr.sbin/pkg_install/delete/main.c
--- a/usr.sbin/pkg_install/delete/main.c        Mon Aug 18 20:44:26 2003 +0000
+++ b/usr.sbin/pkg_install/delete/main.c        Wed Aug 20 01:52:38 2003 +0000
@@ -1,11 +1,11 @@
-/*     $NetBSD: main.c,v 1.20.2.1 2003/07/13 09:45:23 jlam Exp $       */
+/*     $NetBSD: main.c,v 1.20.2.2 2003/08/20 01:52:39 jlam Exp $       */
 
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char *rcsid = "from FreeBSD Id: main.c,v 1.11 1997/10/08 07:46:48 charnier Exp";
 #else
-__RCSID("$NetBSD: main.c,v 1.20.2.1 2003/07/13 09:45:23 jlam Exp $");
+__RCSID("$NetBSD: main.c,v 1.20.2.2 2003/08/20 01:52:39 jlam Exp $");
 #endif
 #endif
 
@@ -151,9 +151,8 @@
                        }
                } else {
                        char   *dbdir;
-                       char   *tmp;
 
-                       dbdir = (tmp = getenv(PKG_DBDIR)) ? tmp : DEF_LOG_DIR;
+                       dbdir = _pkgdb_getPKGDB_DIR();
                        if (**argv == '/' && strncmp(*argv, dbdir, strlen(dbdir)) == 0) {
                                *argv += strlen(dbdir) + 1;
                                if ((*argv)[strlen(*argv) - 1] == '/') {
diff -r c33b7c38cd20 -r 40af066edc4e usr.sbin/pkg_install/delete/perform.c
--- a/usr.sbin/pkg_install/delete/perform.c     Mon Aug 18 20:44:26 2003 +0000
+++ b/usr.sbin/pkg_install/delete/perform.c     Wed Aug 20 01:52:38 2003 +0000
@@ -1,11 +1,11 @@
-/*     $NetBSD: perform.c,v 1.36.2.8 2003/08/17 22:02:20 jlam Exp $    */
+/*     $NetBSD: perform.c,v 1.36.2.9 2003/08/20 01:52:40 jlam Exp $    */
 
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static const char *rcsid = "from FreeBSD Id: perform.c,v 1.15 1997/10/13 15:03:52 jkh Exp";
 #else
-__RCSID("$NetBSD: perform.c,v 1.36.2.8 2003/08/17 22:02:20 jlam Exp $");
+__RCSID("$NetBSD: perform.c,v 1.36.2.9 2003/08/20 01:52:40 jlam Exp $");
 #endif
 #endif
 
@@ -114,12 +114,10 @@
        char    fname[FILENAME_MAX], ftmp[FILENAME_MAX];
        char    fbuf[FILENAME_MAX];
        FILE   *fp, *fpwr;
-       char   *tmp;
        int     s;
 
        (void) snprintf(fname, sizeof(fname), "%s/%s/%s",
-           (tmp = getenv(PKG_DBDIR)) ? tmp : DEF_LOG_DIR,
-           deppkgname, REQUIRED_BY_FNAME);
+           _pkgdb_getPKGDB_DIR(), deppkgname, REQUIRED_BY_FNAME);
        fp = fopen(fname, "r");
        if (fp == NULL) {
                warnx("couldn't open dependency file `%s'", fname);
@@ -166,7 +164,7 @@
 }
 
 /*
- * Remove the current view's PKG_DBDIR from the +VIEWS file of the
+ * Remove the current view's package dbdir from the +VIEWS file of the
  * depoted package named by pkgname.
  */
 static int
@@ -176,12 +174,10 @@
        char  fbuf[FILENAME_MAX];
        char  dbdir[FILENAME_MAX];
        FILE *fp, *fpwr;
-       char *tmp;
        int  s;
        int  cc;
 
-       (void) snprintf(dbdir, sizeof(dbdir), "%s",
-           (tmp = getenv(PKG_DBDIR)) ? tmp : DEF_LOG_DIR);
+       (void) snprintf(dbdir, sizeof(dbdir), "%s", _pkgdb_getPKGDB_DIR());
 
        /* Get the depot directory. */
        (void) snprintf(fname, sizeof(fname), "%s/%s/%s",
@@ -202,7 +198,7 @@
 
        /*
         * Copy the contents of the +VIEWS file into a temp file, but
-        * skip copying the name of the current view's PKG_DBDIR.
+        * skip copying the name of the current view's package dbdir.
         */
        (void) snprintf(fname, sizeof(fname), "%s/%s", fbuf, VIEWS_FNAME);
        if ((fp = fopen(fname, "r")) == NULL) {
@@ -262,7 +258,6 @@
 {
        lpkg_t *lpp;
        int     rv, fail;
-       char   *tmp;
        int     oldcwd;
 
        /* save cwd */
@@ -270,8 +265,7 @@
        if (oldcwd == -1)
                err(EXIT_FAILURE, "cannot open \".\"");
 
-       (void) snprintf(pkgdir, sizeof(pkgdir), "%s",
-           (tmp = getenv(PKG_DBDIR)) ? tmp : DEF_LOG_DIR);
+       (void) snprintf(pkgdir, sizeof(pkgdir), "%s", _pkgdb_getPKGDB_DIR());
 
        /* walk list of things to delete */
        fail = 0;
@@ -363,7 +357,7 @@
        lpkg_head_t reqq;
        lpkg_t *lpp = NULL;
        FILE   *cfile;
-       char   *nl, *tmp;
+       char   *nl;
 
        /* see if we are on the find queue -- circular dependency */
        if ((lpp = find_on_queue(&lpfindq, thislpp->lp_name))) {
@@ -374,7 +368,7 @@
        TAILQ_INIT(&reqq);
 
        (void) snprintf(pkgdir, sizeof(pkgdir), "%s/%s",
-           (tmp = getenv(PKG_DBDIR)) ? tmp : DEF_LOG_DIR, thislpp->lp_name);
+           _pkgdb_getPKGDB_DIR(), thislpp->lp_name);
 
        /* change to package's dir */
        if (chdir(pkgdir) == FAIL) {
@@ -478,7 +472,6 @@
        while ((lpp = TAILQ_FIRST(&reqq))) {
                FILE   *cfile;
                package_t rPlist;
-               char   *tmp;
 
                /* remove a direct req from our queue */
                TAILQ_REMOVE(&reqq, lpp, lp_link);
@@ -488,7 +481,7 @@
                rPlist.tail = NULL;
 
                /* prepare for recursion */
-               chdir ((tmp = getenv(PKG_DBDIR)) ? tmp : DEF_LOG_DIR);
+               chdir(_pkgdb_getPKGDB_DIR());
                if (ispkgpattern(lpp->lp_name)) {
                        char installed[FILENAME_MAX];
                        if (findmatchingname(".", lpp->lp_name, note_whats_installed, installed) != 1) {
@@ -605,7 +598,6 @@
        FILE           *fp;
        char            home[FILENAME_MAX];
        char            view[FILENAME_MAX];
-       char           *tmp;
        int             cc;
        Boolean         is_depoted_pkg = FALSE;
 
@@ -613,8 +605,8 @@
        if (Plist.head)
                free_plist(&Plist);
 
-       (void) snprintf(LogDir, sizeof(LogDir), "%s/%s", (tmp = getenv(PKG_DBDIR)) ? tmp : DEF_LOG_DIR,
-           pkg);
+       (void) snprintf(LogDir, sizeof(LogDir), "%s/%s",
+           _pkgdb_getPKGDB_DIR(), pkg);
        if (!fexists(LogDir) || !isdir(LogDir)) {
                {
                        /* Check if the given package name matches something
@@ -774,7 +766,7 @@
                        if (Verbose)
                                printf("Attempting to remove dependency on package `%s'\n", p->name);
                        if (!Fake)
-                               findmatchingname((tmp = getenv(PKG_DBDIR)) ? tmp : DEF_LOG_DIR,
+                               findmatchingname(_pkgdb_getPKGDB_DIR(),
                                    p->name, undepend, pkg);
                }
        }
diff -r c33b7c38cd20 -r 40af066edc4e usr.sbin/pkg_install/info/main.c
--- a/usr.sbin/pkg_install/info/main.c  Mon Aug 18 20:44:26 2003 +0000
+++ b/usr.sbin/pkg_install/info/main.c  Wed Aug 20 01:52:38 2003 +0000
@@ -1,11 +1,11 @@
-/*     $NetBSD: main.c,v 1.30.2.2 2003/08/08 10:19:01 jlam Exp $       */
+/*     $NetBSD: main.c,v 1.30.2.3 2003/08/20 01:52:40 jlam Exp $       */
 
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char *rcsid = "from FreeBSD Id: main.c,v 1.14 1997/10/08 07:47:26 charnier Exp";
 #else
-__RCSID("$NetBSD: main.c,v 1.30.2.2 2003/08/08 10:19:01 jlam Exp $");
+__RCSID("$NetBSD: main.c,v 1.30.2.3 2003/08/20 01:52:40 jlam Exp $");
 #endif
 #endif
 
@@ -248,9 +248,8 @@
                                        errx(EXIT_FAILURE, "No matching pkg for %s.", *argv);
                        } else {
                                char   *dbdir;
-                               char   *tmp;
 
-                               dbdir = (tmp = getenv(PKG_DBDIR)) ? tmp : DEF_LOG_DIR;
+                               dbdir = _pkgdb_getPKGDB_DIR();
                                if (**argv == '/' && strncmp(*argv, dbdir, strlen(dbdir)) == 0) {
                                        *argv += strlen(dbdir) + 1;
                                        if ((*argv)[strlen(*argv) - 1] == '/') {
diff -r c33b7c38cd20 -r 40af066edc4e usr.sbin/pkg_install/info/perform.c
--- a/usr.sbin/pkg_install/info/perform.c       Mon Aug 18 20:44:26 2003 +0000
+++ b/usr.sbin/pkg_install/info/perform.c       Wed Aug 20 01:52:38 2003 +0000
@@ -1,11 +1,11 @@
-/*     $NetBSD: perform.c,v 1.40.2.3 2003/08/08 10:19:01 jlam Exp $    */
+/*     $NetBSD: perform.c,v 1.40.2.4 2003/08/20 01:52:40 jlam Exp $    */
 
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static const char *rcsid = "from FreeBSD Id: perform.c,v 1.23 1997/10/13 15:03:53 jkh Exp";
 #else
-__RCSID("$NetBSD: perform.c,v 1.40.2.3 2003/08/08 10:19:01 jlam Exp $");
+__RCSID("$NetBSD: perform.c,v 1.40.2.4 2003/08/20 01:52:40 jlam Exp $");
 #endif
 #endif
 
@@ -118,11 +118,8 @@
                 * It's not an uninstalled package, try and find it among the
                 * installed
                 */
-               char   *tmp;
-
                (void) snprintf(log_dir, sizeof(log_dir), "%s/%s",
-                   (tmp = getenv(PKG_DBDIR)) ? tmp : DEF_LOG_DIR,
-                   pkg);
+                   _pkgdb_getPKGDB_DIR(), pkg);
                if (!fexists(log_dir) || !isdir(log_dir)) {
                        {
                                /* Check if the given package name matches
@@ -316,19 +313,19 @@
 pkg_perform(lpkg_head_t *pkghead)
 {
        struct dirent *dp;
-       char   *tmp;
+       char   *dbdir;
        DIR    *dirp;
        int     err_cnt = 0;
 
        signal(SIGINT, cleanup);
 
-       tmp = _pkgdb_getPKGDB_DIR();
+       dbdir = _pkgdb_getPKGDB_DIR();
 
        /* Overriding action? */
        if (CheckPkg) {
-               err_cnt += CheckForPkg(CheckPkg, tmp);
+               err_cnt += CheckForPkg(CheckPkg, dbdir);
        } else if (AllInstalled) {
-               if (!(isdir(tmp) || islinktodir(tmp)))
+               if (!(isdir(dbdir) || islinktodir(dbdir)))
                        return 1;
 
                if (File2Pkg) {
@@ -338,7 +335,7 @@
 
                } else {



Home | Main Index | Thread Index | Old Index