diff options
author | joerg <joerg@pkgsrc.org> | 2007-08-09 23:18:30 +0000 |
---|---|---|
committer | joerg <joerg@pkgsrc.org> | 2007-08-09 23:18:30 +0000 |
commit | 7a51a218c2402be5199e42d7ed3e7068397539ec (patch) | |
tree | 7782693cc7e7672ac62409c95a7db35650ecd3a2 /pkgtools | |
parent | 710504e20a8c6719fb57732597870bc7b4512f19 (diff) | |
download | pkgsrc-7a51a218c2402be5199e42d7ed3e7068397539ec.tar.gz |
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 (limited to 'pkgtools')
-rw-r--r-- | pkgtools/pkg_install/files/add/perform.c | 12 | ||||
-rw-r--r-- | pkgtools/pkg_install/files/info/perform.c | 48 | ||||
-rw-r--r-- | pkgtools/pkg_install/files/lib/automatic.c | 23 | ||||
-rw-r--r-- | pkgtools/pkg_install/files/lib/lib.h | 4 | ||||
-rw-r--r-- | pkgtools/pkg_install/files/lib/pkgdb.c | 13 |
5 files changed, 47 insertions, 53 deletions
diff --git a/pkgtools/pkg_install/files/add/perform.c b/pkgtools/pkg_install/files/add/perform.c index c19f6ad7414..41d5d5801a4 100644 --- a/pkgtools/pkg_install/files/add/perform.c +++ b/pkgtools/pkg_install/files/add/perform.c @@ -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 @@ pkg_do(const char *pkg, lpkg_head_t *pkgs) } /* 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 @@ ignore_replace_depends_check: } } 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 --git a/pkgtools/pkg_install/files/info/perform.c b/pkgtools/pkg_install/files/info/perform.c index 6fd7564fade..c1fdf1713d2 100644 --- a/pkgtools/pkg_install/files/info/perform.c +++ b/pkgtools/pkg_install/files/info/perform.c @@ -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 @@ cleanup(int sig) 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 --git a/pkgtools/pkg_install/files/lib/automatic.c b/pkgtools/pkg_install/files/lib/automatic.c index 1c39c68adb1..c0ec8a21a2a 100644 --- a/pkgtools/pkg_install/files/lib/automatic.c +++ b/pkgtools/pkg_install/files/lib/automatic.c @@ -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 @@ __RCSID("$NetBSD: automatic.c,v 1.2 2005/11/06 12:37:43 wiz Exp $"); #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 @@ is_automatic_installed(const char *path) } 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 --git a/pkgtools/pkg_install/files/lib/lib.h b/pkgtools/pkg_install/files/lib/lib.h index f51a4c08b6a..74394c64b1a 100644 --- a/pkgtools/pkg_install/files/lib/lib.h +++ b/pkgtools/pkg_install/files/lib/lib.h @@ -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 @@ int pkgdb_open(int); 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 --git a/pkgtools/pkg_install/files/lib/pkgdb.c b/pkgtools/pkg_install/files/lib/pkgdb.c index 96b959dea62..5a602f6cd7d 100644 --- a/pkgtools/pkg_install/files/lib/pkgdb.c +++ b/pkgtools/pkg_install/files/lib/pkgdb.c @@ -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 @@ pkgdb_retrieve(const char *key) } /* dump contents of the database to stdout */ -void +int pkgdb_dump(void) { DBT key; @@ -203,8 +203,9 @@ pkgdb_dump(void) (int) val.size, (char *) val.data); } pkgdb_close(); - } - + return 0; + } else + return -1; } /* @@ -278,7 +279,7 @@ int pkgdb_open(int mode) { return 1; } 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; } |