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/admin Split check functions...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/6c5cb0e3bcd9
branches:  trunk
changeset: 539618:6c5cb0e3bcd9
user:      joerg <joerg%pkgsrc.org@localhost>
date:      Sun Mar 09 19:02:27 2008 +0000

description:
Split check functions into a separate file.
Drop checkall and implement it using "*" as wildcard match.

diffstat:

 pkgtools/pkg_install/files/admin/Makefile.in |    4 +-
 pkgtools/pkg_install/files/admin/admin.h     |   36 +++
 pkgtools/pkg_install/files/admin/check.c     |  285 +++++++++++++++++++++++++++
 pkgtools/pkg_install/files/admin/main.c      |  227 +---------------------
 4 files changed, 328 insertions(+), 224 deletions(-)

diffs (truncated from 627 to 300 lines):

diff -r 004b5e7fa23a -r 6c5cb0e3bcd9 pkgtools/pkg_install/files/admin/Makefile.in
--- a/pkgtools/pkg_install/files/admin/Makefile.in      Sun Mar 09 18:28:54 2008 +0000
+++ b/pkgtools/pkg_install/files/admin/Makefile.in      Sun Mar 09 19:02:27 2008 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.in,v 1.11 2007/07/16 09:57:57 joerg Exp $
+# $NetBSD: Makefile.in,v 1.12 2008/03/09 19:02:27 joerg Exp $
 
 srcdir=                @srcdir@
 
@@ -22,7 +22,7 @@
 
 PROG=          pkg_admin
 
-OBJS=  main.o
+OBJS=          check.o main.o
 
 all: $(PROG)
 
diff -r 004b5e7fa23a -r 6c5cb0e3bcd9 pkgtools/pkg_install/files/admin/admin.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/pkgtools/pkg_install/files/admin/admin.h  Sun Mar 09 19:02:27 2008 +0000
@@ -0,0 +1,36 @@
+/*-
+ * Copyright (c) 2008 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *        This product includes software developed by the NetBSD
+ *        Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+extern int quiet;
+
+void   check(char **);
diff -r 004b5e7fa23a -r 6c5cb0e3bcd9 pkgtools/pkg_install/files/admin/check.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/pkgtools/pkg_install/files/admin/check.c  Sun Mar 09 19:02:27 2008 +0000
@@ -0,0 +1,285 @@
+/*     $NetBSD: check.c,v 1.1 2008/03/09 19:02:27 joerg Exp $  */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+#include <nbcompat.h>
+#if HAVE_SYS_CDEFS_H
+#include <sys/cdefs.h>
+#endif
+#ifndef lint
+__RCSID("$NetBSD: check.c,v 1.1 2008/03/09 19:02:27 joerg Exp $");
+#endif
+
+/*-
+ * Copyright (c) 1999-2008 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Hubert Feyrer <hubert%feyrer.de@localhost>.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *        This product includes software developed by the NetBSD
+ *        Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#if HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+#if HAVE_DIRENT_H
+#include <dirent.h>
+#endif
+#if HAVE_ERR_H
+#include <err.h>
+#endif
+#if HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#if HAVE_FCNTL_H
+#include <fcntl.h>
+#endif
+#if HAVE_MD5_H
+#include <md5.h>
+#endif
+#if HAVE_LIMITS_H
+#include <limits.h>
+#endif
+#if HAVE_STDIO_H
+#include <stdio.h>
+#endif
+#if HAVE_STRING_H
+#include <string.h>
+#endif
+
+#include "admin.h"
+#include "lib.h"
+
+static int checkpattern_fn(const char *, void *);
+
+/*
+ * Assumes CWD is in /var/db/pkg/<pkg>!
+ */
+static void 
+check1pkg(const char *pkgdir, int *filecnt, int *pkgcnt)
+{
+       FILE   *f;
+       plist_t *p;
+       package_t Plist;
+       char   *PkgName, *dirp = NULL, *md5file;
+       char    file[MaxPathSize];
+       char    dir[MaxPathSize];
+
+       f = fopen(CONTENTS_FNAME, "r");
+       if (f == NULL)
+               err(EXIT_FAILURE, "can't open %s/%s/%s", _pkgdb_getPKGDB_DIR(), pkgdir, CONTENTS_FNAME);
+
+       Plist.head = Plist.tail = NULL;
+       read_plist(&Plist, f);
+       p = find_plist(&Plist, PLIST_NAME);
+       if (p == NULL)
+               errx(EXIT_FAILURE, "Package %s has no @name, aborting.",
+                   pkgdir);
+       PkgName = p->name;
+       for (p = Plist.head; p; p = p->next) {
+               switch (p->type) {
+               case PLIST_FILE:
+                       if (dirp == NULL) {
+                               warnx("dirp not initialized, please send-pr!");
+                               abort();
+                       }
+                       
+                       (void) snprintf(file, sizeof(file), "%s/%s", dirp, p->name);
+
+                       if (isfile(file) || islinktodir(file)) {
+                               if (p->next && p->next->type == PLIST_COMMENT) {
+                                       if (strncmp(p->next->name, CHECKSUM_HEADER, ChecksumHeaderLen) == 0) {
+                                               if ((md5file = MD5File(file, NULL)) != NULL) {
+                                                       /* Mismatch? */
+#ifdef PKGDB_DEBUG
+                                                       printf("%s: md5 should=<%s>, is=<%s>\n",
+                                                           file, p->next->name + ChecksumHeaderLen, md5file);
+#endif
+                                                       if (strcmp(md5file, p->next->name + ChecksumHeaderLen) != 0)
+                                                               printf("%s fails MD5 checksum\n", file);
+
+                                                       free(md5file);
+                                               }
+                                       } else if (strncmp(p->next->name, SYMLINK_HEADER, SymlinkHeaderLen) == 0) {
+                                               char    buf[MaxPathSize + SymlinkHeaderLen];
+                                               int     cc;
+
+                                               (void) strlcpy(buf, SYMLINK_HEADER, sizeof(buf));
+                                               if ((cc = readlink(file, &buf[SymlinkHeaderLen],
+                                                         sizeof(buf) - SymlinkHeaderLen - 1)) < 0) {
+                                                       warnx("can't readlink `%s'", file);
+                                               } else {
+                                                       buf[SymlinkHeaderLen + cc] = 0x0;
+                                                       if (strcmp(buf, p->next->name) != 0) {
+                                                               printf("symlink (%s) is not same as recorded value, %s: %s\n",
+                                                                   file, buf, p->next->name);
+                                                       }
+                                               }
+                                       }
+                               }
+                               
+                               (*filecnt)++;
+                       } else if (isbrokenlink(file)) {
+                               warnx("%s: Symlink `%s' exists and is in %s but target does not exist!", PkgName, file, CONTENTS_FNAME);
+                       } else {
+                               warnx("%s: File `%s' is in %s but not on filesystem!", PkgName, file, CONTENTS_FNAME);
+                       }
+                       break;
+               case PLIST_CWD:
+                       if (strcmp(p->name, ".") != 0)
+                               dirp = p->name;
+                       else {
+                               (void) snprintf(dir, sizeof(dir), "%s/%s", _pkgdb_getPKGDB_DIR(), pkgdir);
+                               dirp = dir;
+                       }
+                       break;
+               case PLIST_IGNORE:
+                       p = p->next;
+                       break;
+               case PLIST_SHOW_ALL:
+               case PLIST_SRC:
+               case PLIST_CMD:
+               case PLIST_CHMOD:
+               case PLIST_CHOWN:
+               case PLIST_CHGRP:
+               case PLIST_COMMENT:
+               case PLIST_NAME:
+               case PLIST_UNEXEC:
+               case PLIST_DISPLAY:
+               case PLIST_PKGDEP:
+               case PLIST_MTREE:
+               case PLIST_DIR_RM:
+               case PLIST_IGNORE_INST:
+               case PLIST_OPTION:
+               case PLIST_PKGCFL:
+               case PLIST_BLDDEP:
+                       break;
+               }
+       }
+       free_plist(&Plist);
+       fclose(f);
+       (*pkgcnt)++;
+}
+
+struct checkpattern_arg {
+       int filecnt;
+       int pkgcnt;
+       int got_match;
+};
+
+static int
+checkpattern_fn(const char *pkg, void *vp)
+{
+       struct checkpattern_arg *arg = vp;
+       int rc;
+
+       rc = chdir(pkg);
+       if (rc == -1)
+               err(EXIT_FAILURE, "Cannot chdir to %s/%s", _pkgdb_getPKGDB_DIR(), pkg);
+
+       check1pkg(pkg, &arg->filecnt, &arg->pkgcnt);
+       if (!quiet) {
+               printf(".");
+       }
+
+       chdir("..");
+       
+       arg->got_match = 1;
+
+       return 0;
+}
+
+static void
+check_pkg(const char *pkg, int *filecnt, int *pkgcnt, int allow_unmatched)
+{
+       struct checkpattern_arg arg;
+       char *pattern;
+
+       arg.filecnt = *filecnt;
+       arg.pkgcnt = *pkgcnt;
+       arg.got_match = 0;
+
+       if (match_installed_pkgs(pkg, checkpattern_fn, &arg) == -1)
+               errx(EXIT_FAILURE, "Cannot process pkdbdb");
+       if (arg.got_match != 0) {
+               *filecnt = arg.filecnt;
+               *pkgcnt = arg.pkgcnt;
+               return;



Home | Main Index | Thread Index | Old Index