Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 12 Aug 2010 02:41:19 GMT
From:      David Forsythe <dforsyth@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 182295 for review
Message-ID:  <201008120241.o7C2fJLi090781@skunkworks.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/@@182295?ac=10

Change 182295 by dforsyth@skunk on 2010/08/12 02:41:19

	   Fix busted utils

Affected files ...

.. //depot/projects/soc2010/dforsyth_libpkg/pkg_install/Makefile#2 edit
.. //depot/projects/soc2010/dforsyth_libpkg/pkg_install/pkg_add/Makefile#2 edit
.. //depot/projects/soc2010/dforsyth_libpkg/pkg_install/pkg_add/pkg_add.c#2 edit
.. //depot/projects/soc2010/dforsyth_libpkg/pkg_install/pkg_add/pkg_add.h#2 edit
.. //depot/projects/soc2010/dforsyth_libpkg/pkg_install/pkg_info/Makefile#2 edit
.. //depot/projects/soc2010/dforsyth_libpkg/pkg_install/pkg_info/pkg_info.c#2 edit
.. //depot/projects/soc2010/dforsyth_libpkg/pkg_install/pkg_info/pkg_info.h#2 edit

Differences ...

==== //depot/projects/soc2010/dforsyth_libpkg/pkg_install/Makefile#2 (text+ko) ====

@@ -3,5 +3,5 @@
 # See LICENSE file for license details.
 #
 
-SUBDIR=	pkg_info
+SUBDIR=	pkg_dump pkg_info pkg_delete pkg_add pkg_validate
 .include <bsd.subdir.mk>

==== //depot/projects/soc2010/dforsyth_libpkg/pkg_install/pkg_add/Makefile#2 (text+ko) ====

@@ -8,7 +8,7 @@
 WARNS?=	6
 CFLAGS+=	 -I${.CURDIR}/../../libpkg
 DEBUG_FLAGS+=	-g
-LDADD+=	-L../../libpkg -lpkg -larchive
+LDADD+=	-L../../libpkg -lpkg -larchive -lfetch
 
 NO_MAN=	true
 

==== //depot/projects/soc2010/dforsyth_libpkg/pkg_install/pkg_add/pkg_add.c#2 (text+ko) ====

@@ -2,114 +2,530 @@
  * See LICENSE file for license details.
  */
 
+#include <archive.h>
+#include <archive_entry.h>
+#include <sys/param.h>
+#include <stdio.h>
+#include <fetch.h>
+#include <fcntl.h>
 #include <limits.h>
-#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <sys/queue.h>
+#include <getopt.h>
+#include <sys/utsname.h>
+
+#include <libgen.h>
+
+#include <pkg.h>
+#include <pkg_freebsd.h>
+
+#define ADD_NODEPS 0x00000001
+#define ADD_NORECORD 0x00000002
+#define ADD_NOSCRIPT 0x00000004
+#define ADD_FORCE 0x00000008
+#define ADD_DRYRUN 0x00000010
+#define ADD_KEEP 0x00000020
+#define ADD_REMOTE 0x00000040
+#define ADD_VERBOSE 0x00000080
+#define ADD_IGNOREDEPS 0x00000100
+#define ADD_SLAVE 0x00000200
+
+#define HAVE_URL 0x10000000
+
+const char *prefix;
+const char *ad; /* Archive directory. */
+
+struct pkg_database *db;
+struct pkg_repository *rp;
+uint32_t flags;
+
+struct pkg_target {
+        char name[PATH_MAX];
+        STAILQ_ENTRY(pkg_target) next;
+};
+
+struct add_artifact {
+        char name[PATH_MAX];
+        LIST_ENTRY(add_artifact) next;
+};
+LIST_HEAD(added, add_artifact) test_added;
+
+STAILQ_HEAD(target_queue, pkg_target) targets;
+
+void (*progress_handle) (const char *, size_t, size_t);
+
+struct {
+	uint32_t lowver;	/* Lowest version number to match */
+	uint32_t hiver;	/* Highest version number to match */
+	const char *directory;	/* Directory it lives in */
+} releases[] = {
+	{ 410000, 410000, "/packages-4.1-release" },
+	{ 420000, 420000, "/packages-4.2-release" },
+	{ 430000, 430000, "/packages-4.3-release" },
+	{ 440000, 440000, "/packages-4.4-release" },
+	{ 450000, 450000, "/packages-4.5-release" },
+	{ 460000, 460001, "/packages-4.6-release" },
+	{ 460002, 460099, "/packages-4.6.2-release" },
+	{ 470000, 470099, "/packages-4.7-release" },
+	{ 480000, 480099, "/packages-4.8-release" },
+	{ 490000, 490099, "/packages-4.9-release" },
+	{ 491000, 491099, "/packages-4.10-release" },
+	{ 492000, 492099, "/packages-4.11-release" },
+	{ 500000, 500099, "/packages-5.0-release" },
+	{ 501000, 501099, "/packages-5.1-release" },
+	{ 502000, 502009, "/packages-5.2-release" },
+	{ 502010, 502099, "/packages-5.2.1-release" },
+	{ 503000, 503099, "/packages-5.3-release" },
+	{ 504000, 504099, "/packages-5.4-release" },
+	{ 505000, 505099, "/packages-5.5-release" },
+	{ 600000, 600099, "/packages-6.0-release" },
+	{ 601000, 601099, "/packages-6.1-release" },
+	{ 602000, 602099, "/packages-6.2-release" },
+	{ 603000, 603099, "/packages-6.3-release" },
+	{ 604000, 604099, "/packages-6.4-release" },
+	{ 700000, 700099, "/packages-7.0-release" },
+	{ 701000, 701099, "/packages-7.1-release" },
+	{ 702000, 702099, "/packages-7.2-release" },
+	{ 800000, 800499, "/packages-8.0-release" },
+	{ 300000, 399000, "/packages-3-stable" },
+	{ 400000, 499000, "/packages-4-stable" },
+	{ 502100, 502128, "/packages-5-current" },
+	{ 503100, 599000, "/packages-5-stable" },
+	{ 600100, 699000, "/packages-6-stable" },
+	{ 700100, 799000, "/packages-7-stable" },
+	{ 800500, 899000, "/packages-8-stable" },
+	{ 900000, 999000, "/packages-9-current" },
+	{ 0, 9999999, "/packages-current" },
+	{ 0, 0, NULL }
+};
+
+const char *repos[] = {
+        "ftp.freebsd.org/pub/FreeBSD/ports/",
+        "ftp2.freebsd.org/pub/FreeBSD/ports/",
+        NULL
+};
+
+static void parse_arguments(int, char **);
+static int pkg_add(struct pkg_repository *, struct pkg_database *, 
+        struct target_queue *, const char *, uint32_t, 
+        void (*) (const char *, size_t, size_t));
+static void clean_up(int);
+static void usage(void);
+
+static void
+usage(void)
+{
+        exit(100);
+}
+
+static void
+parse_arguments(int argc, char **argv)
+{
+        int o;
+
+        static char opts[] = "hviIRfFnrp:P:SMt:C:K";
+        static struct option longopts[] = {
+                { "chroot",	required_argument,	NULL,		'C' },
+                { "dry-run",	no_argument,		NULL,		'n' },
+                { "force",	no_argument,		NULL,		'f' },
+                { "help",	no_argument,		NULL,		'h' },
+                { "keep",	no_argument,		NULL,		'K' },
+                { "master",	no_argument,		NULL,		'M' },
+                { "no-deps",	no_argument,		NULL,		'i' },
+                { "no-record",	no_argument,		NULL,		'R' },
+                { "no-script",	no_argument,		NULL,		'I' },
+                { "prefix",	required_argument,	NULL,		'p' },
+                { "remote",	no_argument,		NULL,		'r' },
+                { "template",	required_argument,	NULL,		't' },
+                { "slave",	no_argument,		NULL,		'S' },
+                { "verbose",	no_argument,		NULL,		'v' },
+                { NULL,         0,                      NULL,           0},
+        };
+        
+        struct pkg_target *pt;
+
+        flags = 0;
+        while ((o = getopt_long(argc, argv, opts, longopts, NULL)) != -1) {
+                switch (o) {
+                case ('f'):
+                        flags |= ADD_FORCE;
+                        break;
+                case ('K'):
+                        flags |= ADD_KEEP;
+                        break;
+                case ('n'):
+                        flags |= ADD_DRYRUN;
+                        break;
+                case ('p'):
+                        prefix = optarg;
+                        break;
+                case ('r'):
+                        flags |= ADD_REMOTE;
+                        break;
+                case ('v'):
+                        flags |= ADD_VERBOSE;
+                        break;
+                case ('h'):
+                default:
+                        usage();
+                        break;
+                }
+        }
+
+        STAILQ_INIT(&targets);
+
+        argv += optind;
+        for (; *argv != NULL; ++argv) {
+                pt = calloc(1, sizeof(*pt));
+                strcpy(pt->name, *argv);
+                STAILQ_INSERT_TAIL(&targets, pt, next);
+        }
 
-#include "pkg.h"
+}
+
+static void
+clean_up(int r)
+{
+        exit(r);
+}
+
+static int
+check_installed(struct pkg_database *_db, struct pkg *p, const char *name)
+{
+        pkg_database_rewind(_db);
 
-int COMPLETE = 0;
+        printf("check: %s\n", name);
+        /* XXX: Fix skips. */
+        while (pkg_database_get_next_pkg(_db, p, 0) == PKG_OK) {
+                if (strcmp(pkg_freebsd_get_name(p), name) == 0) {
+                        return (1);
+                }
+        }
+        struct add_artifact *t;
+        LIST_FOREACH(t, &test_added, next) {
+                if (strcmp(t->name, name) == 0) {
+                        return (1);
+                }
+        }
+        return (0);
+}
 
-const char *basedir;
+static void
+progress(const char *name, size_t fetched, size_t total)
+{
+        printf("\r%s: %lu/%lu bytes", name, (long unsigned)fetched, 
+                (long unsigned)total);
+}
 
-int fake_pkg_install(const char *pkgname);
-static void pkg_add_bail_out(struct pkg_archive *archive);
 
 int
 main(int argc, char **argv)
 {
-	int i;
+        int r;
+
+        parse_arguments(argc, argv);
+        
+        ad = "pkgdl";
+
+        db = pkg_freebsd_database_create();
+        rp = pkg_freebsd_repository_create();
 
-	if (argc < 2)
-		printf("need packages.");
-	
-	
-	for (i = 1; i < argc; ++i)
-		fake_pkg_install(argv[i]);
+        r = pkg_add(rp, db, &targets, ad, flags, progress);
+        clean_up(r);
 
-	return (EXIT_SUCCESS);
+        /* NOT REACHED. */
+        return (0);
 }
 
-int
-fake_pkg_install(const char *pkgname)
+#define FLAGGED(x, y) (x & y)
+
+static int
+add_package(const char *_pkg, struct pkg_repository *_rp, struct pkg_database *_db, 
+        const char *_ad, uint32_t _flags,
+        void (*_progress) (const char *, size_t, size_t))
 {
-	FILE *fp;
-	int r;
-	struct pkg_archive *archive;
-        struct archive_entry *entry;
-	struct pkg_repository *repository;
+        struct archive *ar;
+        struct archive_entry *ae;
+        struct pkg *p;
+        struct pkg *op;
+        FILE *fp;
+        int r;
+        char *buf;
+        ssize_t bufsz;
+        struct pkg_dependency d;
+        struct pkg_conflict c;
+
+        char depname[PATH_MAX];
+
+        /* For package fetch. */
+        FILE *dl;
+        char *aname;
+        size_t asz;
+        size_t track;
+
+        int w;
+        int f;
+
+        char buffer[256];
+
+        int fd;
+        
+        printf("_pkg = %s\n", _pkg);
+        /* Grap the package from an open repository. */
+        dl = pkg_repository_fetch_pkg(_rp, _pkg, &aname, &asz, 0);
+        if (dl == NULL) {
+                printf("pkg not found.\n");
+                return (-1);
+        }
+
+        if (aname == NULL) {
+                aname = strdup("TEMP_PACKAGE.tbz");
+        }
+
+        mkdir(_ad, 0700);
+        chdir(_ad);
+
+        warnx("opening: %s\n", aname);
+
+        fd = open(aname, O_WRONLY | O_CREAT | O_TRUNC, 
+                S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+        if (fd < 0) {
+                printf("could not open %s\n", aname);
+                return (-1);
+        }
+        
+        track = 0;
+        while ((f = fread(buffer, 1, sizeof(buffer), dl)) > 0) {
+                if ((w = write(fd, buffer, f)) != f) {
+                        errx(1, "Read: %d Wrote: %d", f, w);
+                }
+                track += w;
+                if (_progress != NULL) {
+                        _progress(aname, track, asz);
+                }
+        }
+        printf("\n");
+
+        fp = fopen(aname, "r");
+        if (fp == NULL) {
+                printf("fp fail\n");
+                return (-1);
+        }
+
+        ar = archive_read_new();
+        archive_read_support_format_tar(ar);
+        archive_read_support_compression_bzip2(ar);
+        archive_read_support_compression_gzip(ar);
+        
+        warnx("starting extract.\n");
 
-	repository = pkg_repository_create();
+        r = archive_read_open_FILE(ar, fp);
+        /* 
+         * It looks like the old pkg_add checks gets the archive before it does
+         * any db checks.  This makes sense, because a package may not be named
+         * correctly (or rather, it might just not be named... its name).
+         */
 
-	pkg_repository_set_repository_type_local(repository);
-	pkg_repository_set_location(repository, "/usr/ports/packages");
-	
+        /* First entry should be +CONTENTS. */
+        r = archive_read_next_header(ar, &ae);
+        if (strcmp(archive_entry_pathname(ae), "+CONTENTS") != 0) {
+                errx(1, "Package contents invalid: +CONTENTS is not the first"
+                " entry in the archive.");
+                fclose(fp);
+                return (-1);
+        }
 
-	r = pkg_repository_open(repository);
-	if (r != PKG_OK) {
-		/* Do stuff and die. */
-		return (r);
-	}
+        warnx("reading contents");
 
-	fp = pkg_repository_open_pkg_FILE(repository, pkgname);
-	if (f == NULL) {
-		/* Miss. Clean up. */
-		return (PKG_NOT_OK);
-	}
-	
-	archive = pkg_archive_create();
-	r = pkg_archive_open_read(archive, fp);
-	if (r != PKG_OK) {
-		/* Open fail. */
-		return (r);
-	}
+        buf = malloc(archive_entry_size(ae) + 1);
+        bufsz = archive_entry_size(ae);
+        r = archive_read_data(ar, buf, archive_entry_size(ae));
+        buf[bufsz + 1] = '\0';
+        p = pkg_freebsd_create();
+        op = pkg_freebsd_create();
+        r = pkg_parse(p, buf, "CONTENTS");
+        
+        warnx("checking if %s already installed", _pkg);
+        if (check_installed(db, op, pkg_freebsd_get_name(p))) {
+                fclose(fp);
+                printf("already installed!\n");
+                return (-1);
+        }
         
-        /* Go through the archive, installing as we go. */
-	while (r = (pkg_archive_next_header(archive, &entry) == PKG_OK)) { 
-                /* Skip this file if it is a meta object. */
-                if (!pkg_archive_read_header_is_meta(archive, entry)) {
-                        r = pkg_archive_read_install_file(archive, entry,
-                                basedir, 0);
-                        if (r != PKG_OK) {
-                                pkg_add_bail_out(archive);
-                                return (-1);
+        warnx("checking conflicts for %s", _pkg);
+
+        while (pkg_freebsd_get_next_conflict(p, &c) == PKG_OK) {
+                /* Need to do a regex check for installed. */
+                if (check_installed(db, op, 
+                        pkg_freebsd_conflict_get_expression(&c))) {
+                        /* Conflict alert. */
+                        printf("conflicts with %s\n",
+                                pkg_freebsd_conflict_get_expression(&c));
+                        return (-1);
+                }
+        }
+
+        while (pkg_freebsd_get_next_dependency(p, &d) == PKG_OK) {
+                if (!check_installed(db, op,
+                        pkg_freebsd_dependency_get_name(&d))) {
+                        warnx("%s depends on %s\n", aname,
+                                pkg_freebsd_dependency_get_name(&d));
+                        printf("dep: %s\n", 
+                                pkg_freebsd_dependency_get_name(&d));
+                        strcpy(depname, "All/");
+                        strcat(depname, pkg_freebsd_dependency_get_name(&d));
+                        add_package(depname, _rp, _db, _ad, _flags, _progress);
+                }
+        }
+
+        while (archive_read_next_header(ar, &ae) == ARCHIVE_OK) {
+                if (/* pkg_meta_entry(ae) */ archive_entry_pathname(ae)[0] == '+') {
+                        if (bufsz < archive_entry_size(ae)) {
+                                /* XXX: Check for neg. */
+                                buf = malloc(archive_entry_size(ae));
+                                if (buf == NULL) {
+                                        return (-1);
+                                }
+                                bufsz = archive_entry_size(ae);
                         }
+                        r = archive_read_data(ar, buf, archive_entry_size(ae));
+                        r = pkg_parse(p, buf, archive_entry_pathname(ae));
+                } else {
+                        pkg_freebsd_extract(p, ar, ae);
                 }
         }
         
-        if (r == PKG_FATAL) {
-                pkg_add_bail_out(archive);
-                return (-1);
+        printf("\n\nXXX: ADD: %s\n\n", basename(_pkg));
+        struct add_artifact *add;
+        add = calloc(1, sizeof(*add));
+        strcpy(add->name, basename(_pkg));
+        LIST_INSERT_HEAD(&test_added, add, next);
+
+        return (0);
+}
+
+static const char *
+get_repo_sub_path(void)
+{
+        uint32_t rel;
+        
+        rel = getosreldate();
+
+        for (int i = 0; releases[i].directory != NULL; ++i) {
+                if (rel >= releases[i].lowver && rel <= releases[i].hiver) {
+                        return (releases[i].directory);
+                }
         }
+        return (NULL);
+}
 
-	return (0);
+static const char *
+get_repo_arch(void)
+{
+        static struct utsname n;
+        if (uname(&n) < 0) {
+                return (NULL);
+        }
+        return (n.machine);
 }
 
-void
-pkg_add_bail_out(struct pkg_archive *archive)
+/* 
+ * Set up the repository and prepare for the add.  Use do_add to actually
+ * install a package.
+ */
+
+static int
+pkg_add(struct pkg_repository *_rp, struct pkg_database *_db,
+        struct target_queue *_tq, const char *_ad, uint32_t _flags,
+        void (*_progress) (const char *, size_t, size_t))
 {
-        struct pkg_file *file;
-        struct pkg *pkg;
         int r;
-        struct pkg_unexec *unexec;
-        
-        pkg = pkg_create();
-        file = pkg_file_create();
-        unexec = pkg_exec_create();
+        struct pkg_target *t;
+        char name[PATH_MAX];
+        char repo_site[PATH_MAX];
+        const char *repo_sub;
+        const char *repo_arch;
+
+        /* 
+         * XXX: To be clear: We could stream right to archive_open_FILE(), but
+         * we want a bit of insurance against a lost connection.  So we pull
+         * down the entire archive (even when we don't have keep set).
+         */
+
+        /* TODO: Dummy repo. */
+
+        if (FLAGGED(_flags, ADD_REMOTE)) {
+                repo_sub = get_repo_sub_path();
+                repo_arch = get_repo_arch();
+                if (repo_sub == NULL) {
+                        errx(1, "Can't figure out relver");
+                }
+                /* XXX: We're lying for testing. */
+                repo_sub = "/packages-8.1-release";
+                rp = pkg_freebsd_repository_create();
+                r = 0;
+                for (int i = 0; repos[i] != NULL; ++i) {
+                        /* O.O */
+                        strcpy(repo_site, repos[i]);
+                        strcat(repo_site, "/");
+                        strcat(repo_site, repo_arch);
+                        strcat(repo_site, "/");
+                        strcat(repo_site, repo_sub);
+                        strcat(repo_site, "/");
+                        
+                        r = pkg_repository_open(_rp, repo_site, 0);
+                        if (r == PKG_OK) {
+                                break;
+                        }
+                }
+#if 0
+                "ftp.freebsd.org/pub/FreeBSD/ports/amd64/packages-8.1-release/Latest/",
+                0);
+#endif
+        } else {
+                /* 
+                 * This is the 'dummy repo' situation.  Just set a path and use
+                 * the repository interface to fetch packages.
+                 */
+                rp = NULL;
+                r = 0;
+#if 0
+                rp = pkg_freebsd_repository_path_create();
+                r = 0;
+#endif
+        }
+#if 0
+        /* XXX: Something I want to play with. */
+        else if (FLAGGED(_a->flags, ADD_LOCAL_REPO)){
+                rp = pkg_freebsd_repository_local_create();
+                r = pkg_repository_open(rp, packages, 0);
+        }
 
-        pkg_archive_read_to_pkg(archive, pkg);
+#endif
+        if (r != PKG_OK) {
+                errx(1, "Could not open repository.\n");
+        }
         
-        while (pkg_get_next_file(pkg, file) == PKG_OK)
-                pkg_util_delete_file(file, basedir);
-        
-        while (pkg_get_next_unexec(pkg, unexec) == PKG_OK)
-                pkg_util_run_exec(unexec);
+        pkg_database_open(db, "/var/db/pkg", 0);
+        STAILQ_FOREACH(t, _tq, next) {
+#if 0
+                if (check_installed(db, p, t->target)) {
+                        /* TODO: Act on installed. */
+                        continue;
+                }
+#endif
+                strcpy(name, "Latest/");
+                strcat(name, t->name);
+                if (add_package(name, _rp, _db, _ad, _flags, _progress) < 0) {
+                        warnx("error adding %s", t->name);
+                        break;
+                }
+        }
 
-        pkg_file_release(file);
-        pkg_exec_release(unexec);
-        pkg_release(pkg);
+        pkg_repository_close(rp);
+        pkg_repository_release(rp);
 
-        /* Don't need to check for FATALs, we're screwed anyway. */
+        return (0);
 }

==== //depot/projects/soc2010/dforsyth_libpkg/pkg_install/pkg_add/pkg_add.h#2 (text+ko) ====


==== //depot/projects/soc2010/dforsyth_libpkg/pkg_install/pkg_info/Makefile#2 (text+ko) ====

@@ -8,8 +8,11 @@
 WARNS?=	6
 CFLAGS+= -I${.CURDIR}/../../libpkg
 DPADD=  ${LIBPKG} ${LIBFETCH}
-LDADD=	-L../../libpkg -lpkg -lfetch
-DEBUG_FLAGS=-g
+LDADD=	-L../../libpkg -larchive -lpkg -lfetch
+DEBUG_FLAGS+=-g
+.if defined(PROFILE_BUILD)
+DEBUG_FLAGS+=    -pg
+.endif
 NO_MAN=	true
 
 .include <bsd.prog.mk>

==== //depot/projects/soc2010/dforsyth_libpkg/pkg_install/pkg_info/pkg_info.c#2 (text+ko) ====

@@ -1,454 +1,835 @@
-/* Copyright (c) 2009-2010 David Forsythe.
- * See LICENSE file for license details.
- */
-
+#include <archive.h>
+#include <archive_entry.h>
+#include <getopt.h>
+#include <sys/types.h>
+#include <md5.h>
+#include <sys/stat.h>
+#include <sys/param.h>
+#include <fetch.h>
+#include <regex.h>
+#include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <string.h>
-#include <err.h>
-#include <getopt.h>
-
+#include <unistd.h>
+/* Libpkg base. */
 #include <pkg.h>
+/* FreeBSD package and database. */
+#include <pkg_freebsd.h>
 
-#include "pkg_info.h"
+#if 0
+/* FreeBSD routines. */
+#include <pkg_install.h>
+#endif
 
-static void perform_on_db(struct pkg_database *db);
-static int print_pkg_information(struct pkg *p);
-static void parse_opts(int argc, char **argv);
-static void usage(int exit_val);
+typedef enum {
+        MATCH_ALL,
+        MATCH_EXACT,
+        MATCH_EREGEX,
+        MATCH_GLOB,
+        MATCH_NGLOB,
+        MATCH_REGEX
+} match_t;
 
-int	flags = 0x00000000;
-int	match = 0x00000000;
-int 	getflags = 0x00000000;
-char	**targets = NULL;
+typedef enum {
+        REMOTE_REPOSITORY,
+        LOCAL_REPOSITORY,
+        URL,
+        LOCAL,
+        WHICH,
+        INSTALLED
+} target_t;
 
-char	*info_origin = NULL;
-char	*info_prefix = NULL;
-char	*info_template = NULL;
-char	*info_exists = NULL;
-char	*info_which = NULL;
+struct pkg_target {
+        char target[PATH_MAX];
+        target_t target_type;
+        STAILQ_ENTRY(pkg_target) next;
+};
 
-FILE *out;
+struct info_config {
+        STAILQ_HEAD(target_head, pkg_target) targets;
+        STAILQ_HEAD(which_head, pkg_target) which;
+        const char *database_location;
+        const char *info_prefix;
+        int verbose;
+        int quiet;
+        int show_flags;
+        /* related... */
+        int skip_flags;
+        match_t match;
+        int use_block_size;
+        const char *check_package;
+        const char *lookup_origin;
+        int keep_package;
+};
 
-/* TODO: Write common error handling functions for pkg_tools. */
+#define FLAGGED(x, y) (x & y)
+#define SET_FLAG(x, y) (x |= y)
 
-static char opts[] = "MabcdDe:EfgGhiIjkKl:LmoO:pPqQrRst:vVW:xX";
-static struct option lopts[] = {
-	{ "debugdump", no_argument, NULL, 'M' },
-	{ "all", no_argument, NULL, 'a' },
-	{ "blocksize", no_argument, NULL, 'b' },
-	{ "exists", required_argument, NULL, 'X' },
-	{ "extended", no_argument, NULL, 'e' },
-	{ "help", no_argument, NULL, 'h' },
-	{ "keep", no_argument, NULL, 'K' },
-	{ "no-glob", no_argument, NULL, 'G' },
-	{ "origin", required_argument, NULL, 'O' },
-	{ "quiet", no_argument, NULL, 'q' },
-	{ "regex", no_argument, NULL, 'x' },
-	{ "template", required_argument, NULL, 't' },
-	{ "verbose", no_argument, NULL, 'v' },
-	{ "version", no_argument, NULL, 'P' },
-	{ "which", required_argument, NULL, 'W' },
-	{ NULL, 0, NULL, 0 },
-};
+#define PKG_INFO_VERSION 00000000
 
-/* Mock pkg_info for testing, */
+#define SHOW_LIBPKG_VERSION 0x00000001
+#define SHOW_PKG_INFO_VERSION 0x00000002
+#define SHOW_PKG_NAME 0x00000004
+#define SHOW_COMMENT 0x00000008
+#define SHOW_DESCRIPTION 0x00000010
+#define SHOW_DEINSTALL 0x00000020
+#define SHOW_DISPLAY 0x00000040
+#define SHOW_INSTALL 0x00000080
+#define SHOW_MTREE 0x00000100
+#define SHOW_PLIST 0x00000200
+#define SHOW_INDEX 0x00000400
+#define XXXXXXXXXX 0x00000800
+#define SHOW_CHECKSUM_CHECK 0x00001000
+#define SHOW_REQUIRE 0x00010000
+#define SHOW_DEPEND 0x00020000
+#define SHOW_SIZE 0x00040000
+#define SHOW_ORIGIN 0x00080000
+#define SHOW_PKGNAME 0x00100000
+#define SHOW_FILES 0x00200000
+#define SHOW_REQBY 0x00400000
+#define SHOW_FMTREV 0x00800000
+#define SHOW_PREFIX 0x01000000
+#define SHOW_CONFLICTS 0x02000000
+#define SHOW_OPTIONS 0x04000000
 
-int
-main (int argc, char **argv)
-{
-	const char *db_root;
-        struct pkg_database db;
+#define PKG_DBDIR "/var/db/pkg";
 
-	getflags |= P_SKIPCOMMENT | P_SKIPDESC;
-	getflags |= P_SKIPDISPLAY | P_SKIPMANIFEST;
-	getflags |= P_SKIPMANIFEST | P_SKIPMTREEDIRS;
-	getflags |= P_SKIPREQUIREDBY;
-	
-	/* Just check for any argument to trigger file list vomit. */
-	parse_opts(argc, argv);
-	
-	db_root = getenv("PKG_DBDIR"); /* User set it */
-	if (db_root == NULL)
-		db_root = PKG_DBDIR_DEFAULT;	/* Default */
-        
-        pkg_database_init(&db, FREEBSD_DIRDB);
-        if (db.open(&db, db_root, 0) != PKG_OK)
-                err(EXIT_FAILURE, "Could not open database at \"%s\"",
-                        db_root);
+#define SKIP_ALL FBSD_METACODE_COMMENT | FBSD_METACODE_CONTENTS
 
-	perform_on_db(&db);
-        
-        db.close(&db);
+static void clean_up(int);
+static void parse_arguments(int, char **);
+static void usage(void);
+static void version(void);
+static int is_url(const char *);
+static int regex_match(const char *, const char *, int);
+static int glob_match(const char *, const char *);
+static int info_show(struct pkg *p, struct info_config *);
+static void config_init(struct info_config *);
+static int pkg_info(struct info_config *);
+static int pattern_match(match_t, const char *, const char *);
+static int pkg_info_hash_match(struct pkg_file *);
+static void print_chunk(struct pkg *, const char *(*)(struct pkg *), 
+        const char *, struct info_config *);
+static void print_file(const char *, const char *, struct info_config *);
 
-	return (EXIT_SUCCESS);
-}
+/* Configuration for pkg_info run. */
+struct info_config c;
 
-void
-usage(int exit_val)
+static int
+is_url(const char *path)
 {
-	fprintf(stderr, "%s", "If you don't know how to use me, then you shouldn't be...\n");
-	exit(exit_val);
+        (void)path;
+        return (0);
 }
 
-void
-parse_opts(int argc, char **argv)
+static void
+parse_arguments(int argc, char **argv)
 {
-	int opt;
+        struct pkg_target *pt;
+        int o;
 
-	if (argc == 1) {
-		match |= OPT_MATCH_ALL;
-		flags |= OPT_SHOW_INDEX;
-		getflags ^= P_SKIPCOMMENT;
+        static char opts[] = "abcdDe:EfgGhiIjkKl:LmoO:pPqQrRst:vVW:xX";
+        static struct option long_opts[] = {
+                { "all",	no_argument,		NULL,		'a' },
+                { "blocksize",	no_argument,		NULL,		'b' },
+                { "exist",	required_argument,	NULL,		'X' },
+                { "exists",	required_argument,	NULL,		'X' },
+                { "extended",	no_argument,		NULL,		'e' },
+                { "help",	no_argument,		NULL,		'h' },
+                { "keep",	no_argument,		NULL,		'K' },
+                { "no-glob",	no_argument,		NULL,		'G' },
+                { "origin",	required_argument,	NULL,		'O' },
+                { "quiet",	no_argument,		NULL,		'q' },
+                { "regex",	no_argument,		NULL,		'x' },
+                { "template",	required_argument,	NULL,		't' },
+                { "verbose",	no_argument,		NULL,		'v' },
+                { "version",	no_argument,		NULL,		'P' },
+                { "which",	required_argument,	NULL,		'W' },
+                { NULL,		0,			NULL,		0 }
+        };
+        
+        if (argc == 1) {
+                /* No args.  Set up a basic name/comment dump. */
+                c.match = MATCH_ALL;
+                c.show_flags = SHOW_INDEX;
+                return;
+        }
 
-		return;
-	}
+        /* Go through command line arguments and set up our config. */
+        while ((o = getopt_long(argc, argv, opts, long_opts, NULL)) != -1) {
+                switch (o) {
+                case 'a':
+                        c.match = MATCH_ALL;
+                        break;
+                case 'b':
+                        c.use_block_size = 1;
+                        break;
+                case 'c':
+                        c.show_flags |= SHOW_COMMENT;
+                        break;
+                case 'd':
+                        c.show_flags |= SHOW_DESCRIPTION;
+                        break;
+                case 'e':
+                        c.check_package = optarg;
+                        break;
+                case 'f':
+                        c.show_flags |= SHOW_PLIST;
+                        c.show_flags |= SHOW_FILES;
+                        // c.show_flags |= SHOW_SRCDIR;
+                        // c.show_flags |= SHOW_INSTALL;
+                        // c.show_flags |= SHOW_DEINSTALL;
+                        // c.show_flags |= SHOW_COMMENT;
+                        c.show_flags |= SHOW_PKG_NAME;
+                        // c.show_flags |= SHOW_DISPLAY;
+                        c.show_flags |= SHOW_DEPEND;
+                        // c.show_flags |= SHOW_CONFLICTS;
+                        // c.show_flags |= SHOW_DIRRM;
+                        c.show_flags |= SHOW_ORIGIN;
+                        c.show_flags |= SHOW_OPTIONS;
+                        c.show_flags |= SHOW_FMTREV;
+                        break;
+                case 'g':
+                        c.show_flags |= SHOW_CHECKSUM_CHECK;
+                        break;
+                case 'i':
+                        c.show_flags |= SHOW_INSTALL;
+                        break;
+                case 'j':
+                        c.show_flags |= SHOW_REQUIRE;
+                        break;
+                case 'k':
+                        c.show_flags |= SHOW_DEINSTALL;
+                        break;
+                case 'l':
+                        c.info_prefix = optarg;
+                        break;
+                case 'r':
+                        c.show_flags |= SHOW_DEPEND;
+                        break;
+                case 'm':
+                        c.show_flags |= SHOW_MTREE;
+                        break;
+                case 's':
+                        c.show_flags |= SHOW_SIZE;
+                        break;
+                case 'o':
+                        c.show_flags |= SHOW_ORIGIN;
+                        break;
+                case 'q':
+                        c.quiet = 1;
+                        break;
+                case 'v':
+                        c.verbose = 1;
+                        c.show_flags |= SHOW_COMMENT | SHOW_DESCRIPTION |
+                                SHOW_PLIST | SHOW_INSTALL |
+                                SHOW_DEINSTALL | SHOW_REQUIRE | SHOW_DISPLAY |
+                                SHOW_MTREE;
+                case 'x':
+                        c.match = MATCH_REGEX;
+                        break;
+                case 'D':
+                        c.show_flags |= SHOW_DISPLAY;
+                        break;
+                case 'E':
+                        c.show_flags |= SHOW_PKGNAME;
+                        break;
+                case 'G':
+                        c.match = MATCH_EXACT;
+                        break;
+                case 'I':
+                        c.show_flags |= SHOW_INDEX;
+                        break;
+                case 'K':
+                        c.keep_package = 1;
+                        break;
+                case 'L':
+                        c.show_flags |= SHOW_FILES;
+                        break;

>>> TRUNCATED FOR MAIL (1000 lines) <<<



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201008120241.o7C2fJLi090781>