pkgsrc-Changes-HG archive

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

[pkgsrc/trunk]: pkgsrc/pkgtools/pkg_install/files Change interface of is_auto...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/a08015de0ad1
branches:  trunk
changeset: 532011:a08015de0ad1
user:      joerg <joerg%pkgsrc.org@localhost>
date:      Thu Aug 09 23:18:30 2007 +0000

description:
Change interface of is_automatic_installed and
mark_as_automatic_installed to take a package name and not a full path.
Add assertions to test for this.

Drop a few islinktodir checks.

Change pkg_info to use iterate_pkg_db instead of scanning the directory
by hand. As a side effect don't try to check for the pkgdb dir first,
let pkgdb_dump and iterate_pkg_db handle that.

Make pkgdb_dump return failure if it can't open the package db.

diffstat:

 pkgtools/pkg_install/files/add/perform.c   |  12 +++---
 pkgtools/pkg_install/files/info/perform.c  |  48 ++++++++++-------------------
 pkgtools/pkg_install/files/lib/automatic.c |  23 +++++++++-----
 pkgtools/pkg_install/files/lib/lib.h       |   4 +-
 pkgtools/pkg_install/files/lib/pkgdb.c     |  13 ++++---
 5 files changed, 47 insertions(+), 53 deletions(-)

diffs (252 lines):

diff -r c8c455413868 -r a08015de0ad1 pkgtools/pkg_install/files/add/perform.c
--- a/pkgtools/pkg_install/files/add/perform.c  Thu Aug 09 23:06:42 2007 +0000
+++ b/pkgtools/pkg_install/files/add/perform.c  Thu Aug 09 23:18:30 2007 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: perform.c,v 1.52 2007/08/08 22:33:38 joerg Exp $       */
+/*     $NetBSD: perform.c,v 1.53 2007/08/09 23:18:30 joerg Exp $       */
 
 #if HAVE_CONFIG_H
 #include "config.h"
@@ -14,7 +14,7 @@
 #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.52 2007/08/08 22:33:38 joerg Exp $");
+__RCSID("$NetBSD: perform.c,v 1.53 2007/08/09 23:18:30 joerg Exp $");
 #endif
 #endif
 
@@ -505,9 +505,9 @@
        }
 
        /* See if this package (exact version) is already registered */
-       if ((isdir(LogDir) || islinktodir(LogDir)) && !Force) {
-               if (!Automatic && is_automatic_installed(LogDir)) {
-                       if (mark_as_automatic_installed(LogDir, 0) == 0)
+       if (isdir(LogDir) && !Force) {
+               if (!Automatic && is_automatic_installed(PkgName)) {
+                       if (mark_as_automatic_installed(PkgName, 0) == 0)
                                warnx("package `%s' was already installed as "
                                      "dependency, now marked as installed "
                                      "manually", PkgName);
@@ -946,7 +946,7 @@
                        }
                }
                if (Automatic)
-                       mark_as_automatic_installed(LogDir, 1);
+                       mark_as_automatic_installed(PkgName, 1);
                if (Verbose)
                        printf("Package %s registered in %s\n", PkgName, LogDir);
        }
diff -r c8c455413868 -r a08015de0ad1 pkgtools/pkg_install/files/info/perform.c
--- a/pkgtools/pkg_install/files/info/perform.c Thu Aug 09 23:06:42 2007 +0000
+++ b/pkgtools/pkg_install/files/info/perform.c Thu Aug 09 23:18:30 2007 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: perform.c,v 1.35 2007/08/09 23:06:42 joerg Exp $       */
+/*     $NetBSD: perform.c,v 1.36 2007/08/09 23:18:30 joerg Exp $       */
 
 #if HAVE_CONFIG_H
 #include "config.h"
@@ -14,7 +14,7 @@
 #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.35 2007/08/09 23:06:42 joerg Exp $");
+__RCSID("$NetBSD: perform.c,v 1.36 2007/08/09 23:18:30 joerg Exp $");
 #endif
 #endif
 
@@ -354,51 +354,37 @@
        exit(1);
 }
 
+static int
+perform_single_pkg(const char *pkg, void *cookie)
+{
+       int *err_cnt = cookie;
+
+       if (Which == WHICH_ALL || !is_automatic_installed(pkg))
+               *err_cnt += pkg_do(pkg);
+
+       return 0;
+}
+
 int
 pkg_perform(lpkg_head_t *pkghead)
 {
-       struct dirent *dp;
-       char   *dbdir;
-       DIR    *dirp;
        int     err_cnt = 0;
 
        signal(SIGINT, cleanup);
 
        TAILQ_INIT(&files);
 
-       dbdir = _pkgdb_getPKGDB_DIR();
-
        /* Overriding action? */
        if (CheckPkg) {
                err_cnt += CheckForPkg(CheckPkg);
        } else if (Which != WHICH_LIST) {
-               if (!(isdir(dbdir) || islinktodir(dbdir)))
-                       return 1;
-
                if (File2Pkg) {
                        /* Show all files with the package they belong to */
-                       pkgdb_dump();
+                       if (pkgdb_dump() == -1)
+                               err_cnt = 1;
                } else {
-                       /* Show all packages with description */
-                       if ((dirp = opendir(dbdir)) != (DIR *) NULL) {
-                               while ((dp = readdir(dirp)) != (struct dirent *) NULL) {
-                                       char    tmp2[MaxPathSize];
-
-                                       if (strcmp(dp->d_name, ".") == 0 ||
-                                           strcmp(dp->d_name, "..") == 0)
-                                               continue;
-
-                                       (void) snprintf(tmp2, sizeof(tmp2), "%s/%s",
-                                           dbdir, dp->d_name);
-                                       if (isfile(tmp2))
-                                               continue;
-
-                                       if (Which == WHICH_ALL
-                                           || !is_automatic_installed(tmp2))
-                                               err_cnt += pkg_do(dp->d_name);
-                               }
-                               (void) closedir(dirp);
-                       }
+                       if (iterate_pkg_db(perform_single_pkg, &err_cnt) == -1)
+                               err_cnt = 1;
                }
        } else {
                /* Show info on individual pkg(s) */
diff -r c8c455413868 -r a08015de0ad1 pkgtools/pkg_install/files/lib/automatic.c
--- a/pkgtools/pkg_install/files/lib/automatic.c        Thu Aug 09 23:06:42 2007 +0000
+++ b/pkgtools/pkg_install/files/lib/automatic.c        Thu Aug 09 23:18:30 2007 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: automatic.c,v 1.2 2005/11/06 12:37:43 wiz Exp $        */
+/*     $NetBSD: automatic.c,v 1.3 2007/08/09 23:18:31 joerg Exp $      */
 
 /*-
  * Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -40,9 +40,12 @@
 #include <sys/cdefs.h>
 #endif
 #ifndef lint
-__RCSID("$NetBSD: automatic.c,v 1.2 2005/11/06 12:37:43 wiz Exp $");
+__RCSID("$NetBSD: automatic.c,v 1.3 2007/08/09 23:18:31 joerg Exp $");
 #endif
 
+#if HAVE_ASSERT_H
+#include <assert.h>
+#endif
 #if HAVE_ERR_H
 #include <err.h>
 #endif
@@ -64,14 +67,16 @@
 #include "lib.h"
 
 Boolean
-is_automatic_installed(const char *path)
+is_automatic_installed(const char *pkg)
 {
        char    filename[BUFSIZ];
        char   *value;
        Boolean ret;
 
-       (void)snprintf(filename, sizeof(filename), "%s/%s", path,
-                      INSTALLED_INFO_FNAME);
+       assert(pkg[0] != '/');
+
+       (void)snprintf(filename, sizeof(filename), "%s/%s/%s",
+           _pkgdb_getPKGDB_DIR(), pkg, INSTALLED_INFO_FNAME);
 
        value = var_get(filename, AUTOMATIC_VARNAME);
 
@@ -86,12 +91,14 @@
 }
 
 int
-mark_as_automatic_installed(const char *path, int value)
+mark_as_automatic_installed(const char *pkg, int value)
 {
        char filename[BUFSIZ];
 
-       (void)snprintf(filename, sizeof(filename), "%s/%s", path,
-                      INSTALLED_INFO_FNAME);
+       assert(pkg[0] != '/');
+
+       (void)snprintf(filename, sizeof(filename), "%s/%s/%s",
+           _pkgdb_getPKGDB_DIR(), pkg, INSTALLED_INFO_FNAME);
 
        return var_set(filename, AUTOMATIC_VARNAME,
                       value ? "yes" : NULL);
diff -r c8c455413868 -r a08015de0ad1 pkgtools/pkg_install/files/lib/lib.h
--- a/pkgtools/pkg_install/files/lib/lib.h      Thu Aug 09 23:06:42 2007 +0000
+++ b/pkgtools/pkg_install/files/lib/lib.h      Thu Aug 09 23:18:30 2007 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lib.h,v 1.31 2007/08/08 22:33:39 joerg Exp $ */
+/* $NetBSD: lib.h,v 1.32 2007/08/09 23:18:31 joerg Exp $ */
 
 /* from FreeBSD Id: lib.h,v 1.25 1997/10/08 07:48:03 charnier Exp */
 
@@ -402,7 +402,7 @@
 void    pkgdb_close(void);
 int     pkgdb_store(const char *, const char *);
 char   *pkgdb_retrieve(const char *);
-void   pkgdb_dump(void);
+int    pkgdb_dump(void);
 int     pkgdb_remove(const char *);
 int    pkgdb_remove_pkg(const char *);
 char   *pkgdb_refcount_dir(void);
diff -r c8c455413868 -r a08015de0ad1 pkgtools/pkg_install/files/lib/pkgdb.c
--- a/pkgtools/pkg_install/files/lib/pkgdb.c    Thu Aug 09 23:06:42 2007 +0000
+++ b/pkgtools/pkg_install/files/lib/pkgdb.c    Thu Aug 09 23:18:30 2007 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pkgdb.c,v 1.25 2006/01/04 23:33:23 christos Exp $      */
+/*     $NetBSD: pkgdb.c,v 1.26 2007/08/09 23:18:31 joerg Exp $ */
 
 #if HAVE_CONFIG_H
 #include "config.h"
@@ -8,7 +8,7 @@
 #include <sys/cdefs.h>
 #endif
 #ifndef lint
-__RCSID("$NetBSD: pkgdb.c,v 1.25 2006/01/04 23:33:23 christos Exp $");
+__RCSID("$NetBSD: pkgdb.c,v 1.26 2007/08/09 23:18:31 joerg Exp $");
 #endif
 
 /*
@@ -189,7 +189,7 @@
 }
 
 /* dump contents of the database to stdout */
-void
+int
 pkgdb_dump(void)
 {
        DBT     key;
@@ -203,8 +203,9 @@
                                (int) val.size, (char *) val.data);
                }
                pkgdb_close();
-       }
-
+               return 0;
+       } else
+               return -1;
 }
 
 /*
@@ -278,7 +279,7 @@
 void   pkgdb_close(void) {}
 int    pkgdb_store(const char *key, const char *val) { return 0; }
 char   *pkgdb_retrieve(const char *key) { return NULL; }
-void   pkgdb_dump(void) {}
+int    pkgdb_dump(void) { return 0; }
 int    pkgdb_remove(const char *key) { return 0; }
 int    pkgdb_remove_pkg(const char *pkg) { return 1; }
 



Home | Main Index | Thread Index | Old Index