From owner-p4-projects@FreeBSD.ORG Sat Jul 18 16:17:52 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id E042A1065676; Sat, 18 Jul 2009 16:17:50 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 81DF4106564A for ; Sat, 18 Jul 2009 16:17:50 +0000 (UTC) (envelope-from dforsyth@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 6EAE88FC1E for ; Sat, 18 Jul 2009 16:17:50 +0000 (UTC) (envelope-from dforsyth@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id n6IGHn6h080608 for ; Sat, 18 Jul 2009 16:17:49 GMT (envelope-from dforsyth@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id n6IGHn7x080606 for perforce@freebsd.org; Sat, 18 Jul 2009 16:17:49 GMT (envelope-from dforsyth@FreeBSD.org) Date: Sat, 18 Jul 2009 16:17:49 GMT Message-Id: <200907181617.n6IGHn7x080606@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to dforsyth@FreeBSD.org using -f From: David Forsythe To: Perforce Change Reviews Cc: Subject: PERFORCE change 166231 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 18 Jul 2009 16:17:53 -0000 http://perforce.freebsd.org/chv.cgi?CH=166231 Change 166231 by dforsyth@squirrel on 2009/07/18 16:17:42 Sort packages on add, but don't sort plist elements on add (it breaks the parse). Parse needs to be rewritten to deal with plist variables correctly. Affected files ... .. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.c#37 edit .. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_conflict.c#5 edit .. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_conflict.h#3 edit .. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_db.c#6 edit .. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_depend.c#4 edit .. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_depend.h#3 edit .. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_file.c#10 edit .. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_file.h#9 edit .. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_plist.c#28 edit .. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_plist.h#24 edit .. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_private.h#15 edit .. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_util.c#13 edit .. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_util.h#11 edit .. //depot/projects/soc2009/dforsyth_libpkg/pkg_info/main.c#24 edit Differences ... ==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.c#37 (text+ko) ==== @@ -7,8 +7,6 @@ #include "pkg_file.h" #include "pkg_conflict.h" #include "pkg_plist.h" -#include "pkg_db_hierdb.h" -#include "pkg_db.h" #include "pkg_private.h" #include "pkg.h" @@ -306,8 +304,12 @@ return (PKG_OK); } -/* Maybe I should do these list retrievals in a fashion similar to - * scandir? */ +int +pkg_clone(struct pkg *psrc, struct pkg *pdest) +{ + /* Write this. */ + return 0; +} /* Retrieve a list of file in this package. Return a list of strings * terminated by NULL. */ @@ -466,9 +468,14 @@ if (p == NULL) arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT); - + /* + if (p->pl != NULL) + return (OK); + p->pl = pkg_plist_new(); + if (p->pl == NULL) + return (PKG_NOT_OK | PKG_MEMORY_ERR); + */ if (pkg_plist_parsed(p->pl)) { - /* For now, just jump ship if the package already has a plist. */ return (OK); } @@ -476,3 +483,15 @@ status = pkg_plist_parse_contents_from_text(p->pl, p->contents); return (status); } + +int +pkgcmp(const void *a, const void *b) +{ + const struct pkg *pa; + const struct pkg *pb; + + pa = a; + pb = b; + + return (strsort(pa->ident, pb->ident)); +} ==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_conflict.c#5 (text+ko) ==== @@ -52,3 +52,15 @@ return pc->name; } + +int +pkg_conflictcmp(const void *a, const void *b) +{ + const struct pkg_conflict *pca; + const struct pkg_conflict *pcb; + + pca = a; + pcb = b; + + return (strsort(pca->name, pcb->name)); +} ==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_conflict.h#3 (text+ko) ==== @@ -3,7 +3,7 @@ struct pkg_conflict { char *name; - int version; + char *version; }; struct pkg_conflict *pkg_conflict_new(void); @@ -14,4 +14,6 @@ const char *pkg_conflict_name(struct pkg_conflict *pc); +int pkg_conflictcmp(const void *a, const void *b); + #endif ==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_db.c#6 (text+ko) ==== @@ -92,6 +92,7 @@ { int i; struct pkg *p; + struct pkg key; if (db == NULL) arg_rage_quit(__func__, "Not a valid database.", RAGE_AT_CLIENT); @@ -99,14 +100,16 @@ arg_rage_quit(__func__, "Not a valid identifier.", RAGE_AT_CLIENT); - /*p = (struct pkg *)bsearch(ident, db->pkg_list, db->pkg_count - 1, - sizeof(struct pkg), pkg_cmp);*/ + /* + p = bsearch(&key, db->pkg_entries, db->pkg_count, + sizeof(struct pkg *), pkgcmp); + */ p = NULL; for (i = 0; i < db->pkg_count; ++i) if (strcmp(db->pkg_entries[i]->ident, ident) == 0) p = db->pkg_entries[i]; - + db->pkg_db_db_read_pkg_from_db(db, p); return (p); @@ -150,9 +153,9 @@ db->pkg_count++; db->pkg_entries[db->pkg_count] = NULL; db->pkg_list[db->pkg_count] = NULL; - - /* Add a qsort here. We're getting the packages in order now because - * we arent doing anything, but eventually, well need to sort on add. */ + + qsort(db->pkg_entries, db->pkg_count, sizeof(struct pkg *), pkgcmp); + qsort(db->pkg_list, db->pkg_count, sizeof(struct pkg *), strsort); return (DB_OK); } ==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_depend.c#4 (text+ko) ==== @@ -74,3 +74,17 @@ return (pd->origin); } + +int +pkg_dependcmp(const void *a, const void *b) +{ + const struct pkg_depend *pda; + const struct pkg_depend *pdb; + + pda = a; + pdb = b; + + printf("%s vs %s\n", pda->name, pdb->name); + + return (strsort(pda->name, pdb->name)); +} ==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_depend.h#3 (text+ko) ==== @@ -7,7 +7,7 @@ char *name; char *origin; - int version; + char *version; }; struct pkg_depend *pkg_depend_new(void); @@ -22,4 +22,6 @@ const char *pkg_depend_origin(struct pkg_depend *pd); +int pkg_dependcmp(const void *a, const void *b); + #endif ==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_file.c#10 (text+ko) ==== @@ -173,3 +173,16 @@ pf->mode = mode; return (OK); } + +int +pkg_filecmp(const void *a, const void *b) +{ + const struct pkg_file *pfa; + const struct pkg_file *pfb; + + pfa = a; + pfb = b; + + return (strsort(pfa->path, pfb->path)); +} + ==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_file.h#9 (text+ko) ==== @@ -30,4 +30,6 @@ int pkg_file_set_owner(struct pkg_file *pf, const char *owner); int pkg_file_set_path(struct pkg_file *pf, const char *path); +int pkg_filecmp(const void *a, const void *b); + #endif ==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_plist.c#28 (text+ko) ==== @@ -20,6 +20,9 @@ struct parse_state { enum plist_elem last_elem; + struct pkg_conflict *last_conflict; + struct pkg_depend *last_depend; + struct pkg_file *last_file; char *cwd; char *owner; char *group; @@ -480,7 +483,10 @@ pl->pkg_file_count++; pl->pkg_file_entries[pl->pkg_file_count] = NULL; pl->pkg_file_list[pl->pkg_file_count] = NULL; - /* sort. */ + + /* Having the sort in here (or in any of other element adders) breaks + * the parse. + */ return (OK); } @@ -537,7 +543,7 @@ pl->pkg_depend_count++; pl->pkg_depend_entries[pl->pkg_depend_count] = NULL; pl->pkg_depend_list[pl->pkg_depend_count] = NULL; - + return (OK); } @@ -618,6 +624,15 @@ } int +pkg_plist_add_install(struct pkg_plist *pl, const char *cmd) +{ + if (pl == NULL) + arg_rage_quit(__func__, "Not a valid plist.", RAGE_AT_LIBPKG); + if (cmd == NULL) + arg_rage_quit(__func__, "Not a valid install command.", + RAGE_AT_LIBPKG); + +int pkg_plist_set_name(struct pkg_plist *pl, const char *name) { if (pl == NULL) ==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_plist.h#24 (text+ko) ==== @@ -92,6 +92,12 @@ int pkg_conflict_count; char **pkg_conflict_list; struct pkg_conflict **pkg_conflict_entries; + + int pkg_install_count; + char **pkg_install_list; + + int pkg_deinstall_count; + char **pkg_deinstall_list; short parsed; }; ==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_private.h#15 (text+ko) ==== @@ -25,4 +25,6 @@ int pkg_parse_plist(struct pkg *p); +int pkgcmp(const void *a, const void *b); + #endif ==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_util.c#13 (text+ko) ==== @@ -9,16 +9,11 @@ #include "pkg_private.h" #include "pkg.h" + int -pkg_cmp(const void *a, const void *b) +strsort(const void *a, const void *b) { - const struct pkg *pa; - const struct pkg *pb; - - pa = a; - pb = b; - - return (strcmp(pa->ident, pb->ident)); + return (strcmp(*(char **)a, *(char **)b)); } int ==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_util.h#11 (text+ko) ==== @@ -5,7 +5,7 @@ int subdir_sel(struct dirent *ent); -int pkg_cmp(const void *a, const void *b); +int strsort(const void *a, const void *b); char *path_strdup(const char *name); ==== //depot/projects/soc2009/dforsyth_libpkg/pkg_info/main.c#24 (text+ko) ==== @@ -1,23 +1,61 @@ #include #include +#include #include #include "pkg.h" #include "pkg_info.h" +/* DEBUG */ +short opt_debug_dump = 0; /* M */ + short opt_all = 0; short opt_glob = 0; +short opt_no_glob = 0; +short opt_keep_package = 0; short opt_show_all_info = 0; +short opt_show_checksum = 0; +short opt_show_comment = 0; +short opt_show_display = 0; +short opt_show_deinstall = 0; +short opt_show_depends = 0; +short opt_show_description = 0; +short opt_show_files = 0; +short opt_show_format_revision = 0; short opt_show_index = 0; -short opt_show_comment = 0; -char *info_targets; +short opt_show_install = 0; +short opt_show_mtree = 0; +short opt_show_origin = 0; +short opt_show_pkg_name = 0; +short opt_show_plist = 0; +short opt_show_prefix = 0; +short opt_show_require = 0; +short opt_show_required_by = 0; +short opt_show_size = 0; +short opt_match_origin = 0; +short opt_use_block = 0; +char *info_origin; /* TODO: Write common error handling functions for pkg_tools. */ -static char opts[] = "abcdDe:EfgGhiIjkKl:LmoO:pPqQrRst:vVW:xX"; +static char opts[] = "MabcdDe:EfgGhiIjkKl:LmoO:pPqQrRst:vVW:xX"; static struct option lopts[] = { - { "all", no_argument, NULL, 'a'}, - {NULL, 0, NULL, 0}, + { "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 }, }; /* Mock pkg_info for testing, */ @@ -79,8 +117,97 @@ return; } while ((a = getopt_long(argc, argv, opts, lopts, NULL)) != -1) { - /* ... */ - opt_show_all_info = 1; + switch (a) { + case ('a'): + opt_all = 1; + break; + case ('v'): + opt_show_comment = 1; + opt_show_description = 1; + opt_show_plist = 1; + opt_show_install = 1; + opt_show_deinstall = 1; + opt_show_require = 1; + opt_show_display = 1; + opt_show_mtree = 1; + break; + case ('E'): + opt_show_pkg_name = 1; + break; + case ('I'): + opt_show_index = 1; + break; + case ('p'): + opt_show_prefix = 1; + break; + case ('c'): + opt_show_comment = 1; + break; + case ('d'): + opt_show_description = 1; + break; + case ('D'): + opt_show_display = 1; + break; + case ('f'): + opt_show_plist = 1; + break; + case ('g'): + opt_show_checksum = 1; + break; + case ('G'): + opt_no_glob = 1; + break; + case ('i'): + opt_show_install = 1; + break; + case ('j'): + opt_show_require = 1; + break; + case ('k'): + opt_show_deinstall = 1; + break; + case ('K'): + opt_keep_package = 1; + break; + case ('r'): + opt_show_depends = 1; + break; + case ('R'): + opt_show_required_by = 1; + break; + case ('L'): + opt_show_files = 1; + break; + case ('m'): + opt_show_mtree = 1; + break; + case ('s'): + opt_show_size = 1; + break; + case ('o'): + opt_show_origin = 1; + break; + case ('O'): + opt_match_origin = 1; + info_origin = strdup(optarg); + if (info_origin == NULL) { + printf("mem\n"); + exit(1); + } + break; + case ('V'): + opt_show_format_revision = 1; + break; + case ('M'): + opt_debug_dump = 1; + break; + /* lazy. */ + case ('h'): + default: + usage(0); + break; + } } } @@ -113,7 +240,7 @@ /* Just print the basic PKGNAME COMMENT scheme right now. Other * information isn't collected by the library yet. */ - if (!opt_show_all_info) { + if (!opt_debug_dump) { /* Use pkg_ident because old pkg_info goes by directory name. */ ident = pkg_ident(p); comment = pkg_comment(p);