Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 6 Jul 2009 06:37:15 GMT
From:      David Forsythe <dforsyth@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 165666 for review
Message-ID:  <200907060637.n666bF7k003102@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=165666

Change 165666 by dforsyth@squirrel on 2009/07/06 06:36:57

	Started reorganizing things and simplifying API.  This wont compile.

Affected files ...

.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.c#29 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.h#27 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_file.c#7 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_plist.c#22 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_plist.h#18 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_sub.c#4 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_sub.h#4 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_util.c#8 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkgdb.c#20 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkgdb_hierdb.c#11 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkgdb_private.h#5 edit
.. //depot/projects/soc2009/dforsyth_libpkg/pkg_info/main.c#19 edit
.. //depot/projects/soc2009/dforsyth_libpkg/pkg_info/pkg_info.h#6 edit

Differences ...

==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.c#29 (text+ko) ====

@@ -25,12 +25,14 @@
 	char *mtree_dirs;
 	char *required_by;
 
-	struct pkg_plist plist;
+	struct pkg_plist *plist;
 
 	short dirty;
 	/* Add an owner field? */
 };
 
+/* Maybe I should add a pkg_init routine? */
+
 /* Create a new pkg. */
 
 struct pkg *
@@ -39,30 +41,227 @@
 	struct pkg *p;
 
 	p = calloc(1, sizeof(*p));
+
+	/* Because I changed plist into a pointer, I need alloc it somewhere
+	 * for now.  Do it in here, but remember to get this out of here and
+	 * add it to the parse check in the getters. */
+
+	p->plist = pkg_plist_new();
+	if (p == NULL || p->plist == NULL) {
+		free(p);
+		free(p->plist);
+		return (NULL);
+	}
+
+	p->ident = NULL;
+	p->comment = NULL;
+	p->contents = NULL;
+	p->description = NULL;
+	p->display = NULL;
+	p->mtree_dirs = NULL;
+	p->required_by = NULL;
+	p->plist = NULL;
+	p->dirty = 0;
+
+	return (p);
+}
+
+/* Clear and free an allocated pkg. */
+
+void
+pkg_delete(struct pkg *p)
+{
+	if (p == NULL)
+		arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
+	
+	pkg_reset(p);
+	free(p->plist);
+	free(p);
+}
+
+/* Reset a package, but do not free it. */
+
+void
+pkg_reset(struct pkg *p)
+{
+	if (p == NULL)
+		arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
+	
+	free(p->ident);
+	free(p->comment);
+	free(p->contents);
+	free(p->description);
+	free(p->display);
+	free(p->mtree_dirs);
+	free(p->required_by);
+	p->ident = NULL;
+	p->comment = NULL;
+	p->contents = NULL;
+	p->description = NULL;
+	p->display = NULL;
+	p->mtree_dirs = NULL;
+	p->required_by = NULL;
+	p->dirty = 0;
+	/* Until plist allocation is done properly, we can't free this in
+	 * here. */	
+	pkg_plist_reset(p->plist);
+}
+
+/* Retrieve pkg identity.  In hierdb, this is the directory containing the
+ * plist. This is a client set identifier, so conflict and dependendency
+ * checks should not rely on it. */
+
+const char *
+pkg_ident(struct pkg *p)
+{
+	if (p == NULL)
+		arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
+
+	return (p->ident);
+}
+
+/* Retrieve pkg name. @name in plist. Conflict and dependency checks
+ * should rely on this string rather than ident. */
+
+const char *
+pkg_name(struct pkg *p)
+{
+	if (p == NULL)
+		arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
+	
+	if (pkg_parse_plist(p) != OK)
+		return (NULL);
+
+	return (pkg_plist_name(p->plist));
+}
+
+/* Retrieve pkg cwd.  @cwd in plist.  All file paths are relative to this
+ * directory. */
+
+const char *
+pkg_cwd(struct pkg *p)
+{
+	if (p == NULL)
+		arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
 	
-	return (p);
+	if (pkg_parse_plist(p) != OK)
+		return (NULL);
+
+	return (pkg_plist_cwd(p->plist));
 }
 
-/* For now, copy all text into the package.  Yes, it's storing information
- * twice, but until I'm sure about what I'm going to do with all of the
- * information, pkgs can have their own copies of the data. */
+/* Retrieve pkg origin.  @origin in plist.  The directory of the port that
+ * this pkg was create from. */
+
+const char *
+pkg_origin(struct pkg *p)
+{
+	if (p == NULL)
+		arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
+	
+	if (pkg_parse_plist(p) != OK)
+		return (NULL);
+
+	return (pkg_plist_origin(p->plist));
+}
 
 /* Set the identity for this package (does not have to be the same as the
  * name from plist, but it generally is.  This is the name used for the
  * directory in a hierdb. */
 
-
-/* TODO: All of these assignments need mem checks. */
 int
 pkg_set_ident(struct pkg *p, const char *ident)
 {
 	if (p == NULL)
 		arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
+	if (ident == NULL)
+		arg_rage_quit(__func__, "Not a valid identifier.",
+		RAGE_AT_CLIENT);
 	
 	free(p->ident);
-	p->ident = (ident != NULL) ? strdup(ident) : NULL;
+	p->ident = strdup(ident);
+	if (p->ident == NULL)
+		return (PKG_MEMORY_ERR | PKG_NOT_OK);
+
+	return (PKG_OK);
+}
+
+/* Set the name for this package.  @name in plist. */
+
+int
+pkg_set_name(struct pkg *p, const char *name)
+{
+	if (p == NULL)
+		arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
+	if (name == NULL)
+		arg_rage_quit(__func__, "Not a valid name.", RAGE_AT_CLIENT);
+
+	return (pkg_plist_set_name(p->plist, name));
+}
+
+/* Set the cwd for this package. @cwd in plist. */
+
+int
+pkg_set_cwd(struct pkg *p, const char *cwd)
+{
+	if (p == NULL)
+		arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
+	if (cwd == NULL)
+		arg_rage_quit(__func__, "Not a valid cwd.", RAGE_AT_CLIENT);
+	
+	return (pkg_plist_set_cwd(p->plist, cwd));
+}
+
+/* Set the origin for this package.  @origin in plist. */
+
+int
+pkg_set_origin(struct pkg *p, const char *origin)
+{
+	if (p == NULL)
+		arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
+	if (origin == NULL)
+		arg_rage_quit(__func__, "Not a valid origin.", RAGE_AT_CLIENT);
+
+	return (pkg_plist_set_origin(p->plist, origin));
+}
+
+/* Maybe I should do these list retrievals in a fashion similar to
+ * scandir? */
+
+/* Retrieve a list of file in this package.  Return a list of strings
+ * terminated by NULL. */
+
+const char **
+pkg_files(struct pkg *p)
+{
+	if (p == NULL)
+		arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
+	
+	return (pkg_plist_files(p->plist));
+}
+
+/* Retrieve a list of dependencies for this package (by name).  Return a
+ * list of strings terminated by NULL. */
+
+const char **
+pkg_depends(struct pkg *p)
+{
+	if (p == NULL)
+		arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
+	
+	return (pkg_plist_depends(p->plist));
+}
+
+/* Retrieve a list of conflicts for this package (by name).  Return a list
+ * of strings terminated by NULL. */
+
+const char **
+pkg_conflicts(struct pkg *p)
+{
+	if (p == NULL)
+		arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
 
-	return (OK);
+	return (pkg_plist_conflicts(p->plist));
 }
 
 /* Set the short comment for this package */
@@ -159,28 +358,19 @@
 
 	if (p == NULL)
 		arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
-	
-	if (pkg_plist_parsed(&p->plist)) {
+
+	if (pkg_plist_parsed(p->plist)) {
 		/* For now, just jump ship if the package already has a plist. */
 		return (OK);
 	}
 
-	pkg_plist_reset(&p->plist);
-	status = pkg_plist_parse_contents_from_text(&p->plist, p->contents);
-
+	pkg_plist_reset(p->plist);
+	status = pkg_plist_parse_contents_from_text(p->plist, p->contents);
 	return (status);
 }
 
 /* ident and name are different, even though they might be the same. */
-char *
-pkg_ident(struct pkg *p)
-{
-	if (p == NULL)
-		arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
 
-	return (p->ident);
-}
-
 char *
 pkg_comment(struct pkg *p)
 {
@@ -191,39 +381,8 @@
 }
 
 /* Functions to access information stored in the pkg_plist. */
-char *
-pkg_name(struct pkg *p)
-{
-	if (p == NULL)
-		arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
-
-	if (pkg_parse_plist(p) != OK)
-		return (NULL);
-
-	return (pkg_plist_name(&p->plist));
-}
 
-char *
-pkg_cwd(struct pkg *p)
-{
-	if (p == NULL)
-		arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
-	
-	if (pkg_parse_plist(p) != OK)
-		return (NULL);
-	return (pkg_plist_cwd(&p->plist));
-}
 
-char *
-pkg_origin(struct pkg *p)
-{
-	if (p == NULL)
-		arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
-	
-	if (pkg_parse_plist(p) != OK)
-		return (NULL);
-	return (pkg_plist_origin(&p->plist));
-}
 
 char *
 pkg_mtree_file(struct pkg *p)
@@ -233,7 +392,7 @@
 
 	if (pkg_parse_plist(p) != OK)
 		return (NULL);
-	return (pkg_plist_mtree_file(&p->plist));
+	return (pkg_plist_mtree_file(p->plist));
 }
 
 /* Other properties. */
@@ -247,7 +406,7 @@
 	if (pkg_parse_plist(p) != OK)
 		return (PKG_PARSE_NOT_OK);
 
-	return (pkg_plist_extract_in_place(&p->plist));
+	return (pkg_plist_extract_in_place(p->plist));
 }
 
 int
@@ -259,7 +418,7 @@
 	if (pkg_parse_plist(p) != OK)
 		return (PKG_PARSE_NOT_OK);
 
-	return (pkg_plist_preserve(&p->plist));
+	return (pkg_plist_preserve(p->plist));
 }
 
 int
@@ -271,7 +430,7 @@
 	if (pkg_parse_plist(p) != OK)
 		return (PKG_PARSE_NOT_OK);
 
-	return (pkg_plist_complete(&p->plist));
+	return (pkg_plist_complete(p->plist));
 }
 
 /* These need to be renamed. */
@@ -282,7 +441,7 @@
 	if (p == NULL)
 		arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
 
-	pkg_plist_pkg_file_list_reset(&p->plist);
+	pkg_plist_pkg_file_list_reset(p->plist);
 }
 
 struct pkg_file *
@@ -291,7 +450,7 @@
 	if (p == NULL)
 		arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
 
-	return (pkg_plist_pkg_file_list_next(&p->plist));
+	return (pkg_plist_pkg_file_list_next(p->plist));
 }
 
 void
@@ -300,7 +459,7 @@
 	if (p == NULL)
 		arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
 
-	return (pkg_plist_pkg_dep_list_reset(&p->plist));
+	return (pkg_plist_pkg_dep_list_reset(p->plist));
 }
 
 struct pkg_dep *
@@ -309,7 +468,7 @@
 	if (p == NULL)
 		arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
 
-	return (pkg_plist_pkg_dep_list_next(&p->plist));
+	return (pkg_plist_pkg_dep_list_next(p->plist));
 }
 
 void
@@ -318,7 +477,7 @@
 	if (p == NULL)
 		arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
 
-	return (pkg_plist_pkg_cfl_list_reset(&p->plist));
+	return (pkg_plist_pkg_cfl_list_reset(p->plist));
 }
 
 struct pkg_cfl *
@@ -326,42 +485,7 @@
 {
 	if (p == NULL)
 		arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
-
-	return (pkg_plist_pkg_cfl_list_next(&p->plist));
-}
-
-void
-pkg_reset(struct pkg *p)
-{
-	if (p == NULL)
-		arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
 	
-	free(p->ident);
-	free(p->comment);
-	free(p->contents);
-	free(p->description);
-	free(p->display);
-	free(p->mtree_dirs);
-	free(p->required_by);
-	p->ident = NULL;
-	p->comment = NULL;
-	p->contents = NULL;
-	p->description = NULL;
-	p->display = NULL;
-	p->mtree_dirs = NULL;
-	p->required_by = NULL;
-	pkg_plist_reset(&p->plist);
+	return (pkg_plist_pkg_cfl_list_next(p->plist));
 }
 
-/* TODO: Make an note in the manual for libpkg that pkg_delete should not be
- * called on pkgs that are not explicitly created by the client. */
-
-void
-pkg_delete(struct pkg *p)
-{
-	if (p == NULL)
-		arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
-	
-	pkg_reset(p);
-	free(p);
-}

==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.h#27 (text+ko) ====

@@ -50,11 +50,14 @@
 #define PKG_NO_MTREE_DIRS	0x02000000
 #define PKG_NO_REQUIRED_BY	0x04000000
 #define PKG_CORRUPT			0x08000000
+#define PKG_MEMORY_ERR		0x00100000
 
 /* Parse errors. */
 #define PARSE_OK			0x00000000
 #define PARSE_FAIL			0x10000000
 
+#define BAD_OR_UNKNOWN_VALUE "???"
+
 /* TODO: All these explicit functions are great, but the client doesn't
  * need to make a "new" pkg_cfl, when all they really have to insert are a
  * sting and an integer (they dont even have to set the int).  So write
@@ -215,4 +218,80 @@
 
 void pkgdb_db_delete(struct pkgdb *db);
 
+/* Util (will probably dissapear). */
+
+void pkg_dump(struct pkg *p, FILE *stream);
+
+
+#if 0
+
+/* pkg */
+
+struct pkg *pkg_new();
+void pkg_delete(struct pkg *p);
+int pkg_reset(struct pkg *p);
+
+const char *pkg_ident(struct pkg *p);
+const char *pkg_name(struct pkg *p);
+const char *pkg_cwd(struct pkg *p);
+const char *pkg_origin(struct pkg *p);
+
+int pkg_set_ident(struct pkg *p, const char *ident);
+int pkg_set_name(struct pkg *p, const char *name);
+int pkg_set_cwd(struct pkg *p, const char *cwd);
+int pkg_set_origin(struct pkg *p, const char *origin);
+
+const char **pkg_files(struct pkg *p);
+const char **pkg_depends(struct pkg *p);
+const char **pkg_conflicts(struct pkg *p);
+
+int pkg_add_file(struct pkg *p, const char *path, const char *md5, 
+	const char *owner, const char *group, const char *mode);
+int pkg_remove_file(struct pkg *p, const char *path);
+const char *pkg_file_md5(struct pkg *p, const char *path);
+const char *pkg_file_owner(struct pkg *p, const char *path);
+const char *pkg_file_group(struct pkg *p, const char *path);
+const char *pkg_file_mode(struct pkg *p, const char *mode);
+
+int pkg_add_depend(struct pkg *p, const char *name, const char *origin, 
+	int version);
+int pkg_remove_depend(struct pkg *p, const char *name);
+const char *pkg_depend_origin(struct pkg *p, const char *name);
+int pkg_depend_version(struct pkg *p, const char *name);
+
+int pkg_add_conflict(struct pkg *p, const char *name, int version);
+int pkg_remove_conflict(struct pkg *p, const char *name);
+const char *pkg_conflict_version(struct pkg *p, const char *name);
+
+/* TODO: Add installation/deinstallation routine modification... routines. */
+
+/* pkgdb */
+
+struct pkgdb *pkgdb_new();
+void pkgdb_delete(struct pkgdb *db);
+
+int pkgdb_open(struct pkgdb *db, const char *path, int db_type);
+/* With the new design, is "init" even needed? */
+int pkgdb_init(struct pkgdb *db);
+
+/* Return a list of packages by _ident_. */
+const char *pkgdb_all_pkgs(struct pkgdb *db);
+int pkgdb_select_pkg(struct pkgdb *db, struct pkg *p, const char *pkgident);
+
+int pkgdb_insert_pkg(struct pkgdb *db, struct pkg *p);
+int pkgdb_delete_pkg(struct pkgdb *db, const char *pkgident);
+int pkgdb_update_pkg(struct pkgdb *db, const char *pkgident, struct pkg *p);
+
+/* pkgrepo */
+
+struct pkgrepo *pkgrepo_new();
+void pkgrepo_delete(struct pkgrepo *pr);
+
+/* pkgarcv */
+
+struct pkgarcv *pkgarcv_new();
+void pkgarcv_delete(struct pkgarcv *pa;
+
+#endif
+
 #endif

==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_file.c#7 (text+ko) ====

@@ -12,7 +12,7 @@
 pkg_file_new()
 {	
 	struct pkg_file *pf;
-
+	
 	pf = calloc(1, sizeof(*pf));
 
 	return (pf);

==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_plist.c#22 (text+ko) ====

@@ -76,6 +76,15 @@
 	
 	/* TODO: Write this. */
 
+	free(pl->pkg_file_list);
+	pl->pkg_file_cnt = 0;
+
+	free(pl->pkg_dep_list);
+	pl->pkg_dep_cnt = 0;
+
+	free(pl->pkg_cfl_list);
+	pl->pkg_cfl_cnt = 0;
+
 	pl->extract_in_place = 0;
 	pl->preserve = 0;
 	pl->complete = 0;
@@ -119,7 +128,7 @@
 	if (textp == NULL)
 		return (MEMORY_ERR);
 
-	pl->text = textp;	
+	pl->text = textp;
 
 	/* TODO: Use fgets(), and have the different lists have their own copy
 	 * of information so that packages can be freely manipulated without
@@ -574,7 +583,7 @@
 pkg_plist_pkg_cfl_list_next(struct pkg_plist *pl)
 {
 	struct pkg_cfl *pc;
-
+	
 	if (pl == NULL)
 		arg_rage_quit(__func__, "Not a valid plist.", RAGE_AT_LIBPKG);
 	

==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_plist.h#18 (text+ko) ====

@@ -77,7 +77,7 @@
 	char *mtree_file;
 	short extract_in_place;
 	short preserve;
-	short complete;
+	short complete;  /* fat. */
 
 	char *text; /* The entire plist */
 
@@ -88,10 +88,20 @@
 	/* Use these lists here so that appending to our list doesnt need a
 	 * bunch of realloc procedures.  This will be convenient for clients
 	 * that want to build plists on the fly, modify plists, etc. */
+	/* No, screw them I hate them and hope they burn. */
 
 	TAILQ_HEAD(pkg_file_head, pkg_file) pkg_file_head; /* pkg_file list. */
 	TAILQ_HEAD(pkg_dep_head, pkg_dep) pkg_dep_head; /* pkg_dep list. */
 	TAILQ_HEAD(pkg_cfl_head, pkg_cfl) pkg_cfl_head; /* pkg_cfl list. */
+	
+	unsigned int pkg_file_cnt;
+	struct pkg_file *pkg_file_list;
+
+	unsigned int pkg_dep_cnt;
+	struct pkg_dep *pkg_dep_list;
+
+	unsigned int pkg_cfl_cnt;
+	struct pkg_cfl *pkg_cfl_list;
 
 	short parsed;
 };

==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_sub.c#4 (text+ko) ====

@@ -14,8 +14,14 @@
 #include "pkg_sub.h"
 
 int 
-pkg_sub_cmp(struct pkg_sub *ps1, struct pkg_sub *ps2)
+pkg_sub_cmp(const void *a, const void *b)
 {
+	const struct pkg_sub *ps1;
+	const struct pkg_sub *ps2;
+
+	ps1 = a;
+	ps2 = b;
+
 	return (strcmp(ps1->ident, ps2->ident));
 }
 

==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_sub.h#4 (text+ko) ====

@@ -43,7 +43,7 @@
 
 struct pkg_sub;
 
-int pkg_sub_cmp(struct pkg_sub *ps1, struct pkg_sub *ps2);
+int pkg_sub_cmp(const void *a, const void *b);
 
 int pkg_sub_mark_read(struct pkg_sub *ps);
 

==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_util.c#8 (text+ko) ====

@@ -6,6 +6,7 @@
 #include <dirent.h>
 
 #include "pkg_util.h"
+#include "pkg.h"
 
 int
 subdir_sel(struct dirent *ent)
@@ -60,3 +61,86 @@
 	fprintf(stderr, "Bad argument in %s: %s\n", function, message);
 	exit(ret);
 }
+
+void
+pkg_dump(struct pkg *p, FILE *stream)
+{
+	struct pkg_dep *pd;
+	struct pkg_cfl *pc;
+	struct pkg_file *pf;
+
+	const char *ident;
+	const char *comment;
+	const char *name;
+	const char *cwd;
+	const char *origin;
+	const char *mtree_file;
+	const char *path;
+	const char *md5;
+	const char *owner;
+	const char *group;
+	const char *mode;
+
+	ident = pkg_ident(p);
+	comment = pkg_comment(p);
+	
+	name = pkg_name(p);
+	cwd = pkg_cwd(p);
+	origin = pkg_origin(p);
+	mtree_file = pkg_mtree_file(p);
+	
+
+	fprintf(stream, "IDENT: %s\n\n",
+		(ident != NULL ? ident : BAD_OR_UNKNOWN_VALUE));
+	fprintf(stream, "\t%s\n\n",
+		(comment != NULL ? comment : BAD_OR_UNKNOWN_VALUE));
+
+	fprintf(stream, "\tname: %s\n", 
+		(name != NULL ? name : BAD_OR_UNKNOWN_VALUE));
+	fprintf(stream, "\tcwd: %s\n", 
+		(cwd != NULL ? name : BAD_OR_UNKNOWN_VALUE));
+	fprintf(stream, "\torigin: %s\n", 
+		(origin != NULL ? origin : BAD_OR_UNKNOWN_VALUE));
+	fprintf(stream, "\tmtree file: %s\n",
+		(mtree_file != NULL ? mtree_file : BAD_OR_UNKNOWN_VALUE));
+	fprintf(stream, "\textract in place: %s\n",
+		(pkg_extract_in_place(p) ? "YES" : "NO"));
+	fprintf(stream, "\tpreserve: %s\n",
+		(pkg_preserve(p) ? "YES" : "NO"));
+	fprintf(stream, "\tcomplete: %s\n",
+		(pkg_complete(p) ? "YES" : "NO"));
+	fprintf(stream, "\tfiles:\n");
+	pkg_pkg_file_list_init(p);
+	while ((pf = pkg_pkg_file_list_next(p)) != NULL) {
+		path = pkg_file_path(pf);
+		md5 = pkg_file_md5(pf);
+		owner = pkg_file_owner(pf);
+		group = pkg_file_group(pf);
+		mode = pkg_file_mode(pf);
+		fprintf(stream, "\t\t%s\n", 
+			(path != NULL ? path : BAD_OR_UNKNOWN_VALUE));
+		fprintf(stream, "\t\t\tMD5: %s\n", 
+			(md5 != NULL ? md5 : BAD_OR_UNKNOWN_VALUE));
+		fprintf(stream, "\t\t\tOWNER: %s\n", 
+			(owner != NULL ? owner : BAD_OR_UNKNOWN_VALUE));
+		fprintf(stream, "\t\t\tGROUP: %s\n", 
+			(group != NULL ? group : BAD_OR_UNKNOWN_VALUE));
+		fprintf(stream, "\t\t\tMODE: %s\n",
+			(mode != NULL ? mode : BAD_OR_UNKNOWN_VALUE));
+	}
+
+	fprintf(stream, "\tdepends:\n");
+	pkg_pkg_dep_list_init(p);
+	while ((pd = pkg_pkg_dep_list_next(p)) != NULL) {
+		name = pkg_dep_name(pd);
+		origin = pkg_dep_origin(pd);
+		fprintf(stream, "\t\t%s : %s\n", name, origin);
+	}
+
+	fprintf(stream, "\tconflicts:\n");
+	pkg_pkg_cfl_list_init(p);
+	while ((pc = pkg_pkg_cfl_list_next(p)) != NULL) {
+		name = pkg_cfl_name(pc);
+		fprintf(stream, "\t\t%s\n", name);
+	}
+}

==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkgdb.c#20 (text+ko) ====

@@ -25,6 +25,7 @@
 	case (HIER_DB):
 		db->pkgdb_db_open = pkgdb_hierdb_db_open;
 		db->pkgdb_db_init = pkgdb_hierdb_db_init;
+		db->pkgdb_db_read_pkg_sub = pkgdb_hierdb_read_pkg_sub;
 		/* db->pkgdb_db_close = pkgdb_hierdb_db_close; */
 		break;
 	default:
@@ -100,13 +101,15 @@
 	 * can have multiple copies of a package which do not share a state.
 	 * Is this a terrible idea?  Stay tuned to find out. */
 
+	status = PKG_OK;
 	pkg_reset(p);
 	ps = pkgdb_pkg_sub_list_next(db);
 	if (ps == NULL) {
 		return (DB_NO_PKG); /* Already at the end. */
 	}
-	pkgdb_hierdb_read_pkg_sub(db, ps);
-	status = pkgdb_generate_pkg_from_pkg_sub(db, p, ps);
+
+	status |= db->pkgdb_db_read_pkg_sub(db, ps);
+	status |= pkgdb_generate_pkg_from_pkg_sub(db, p, ps);
 
 	return (status);
 }
@@ -131,8 +134,8 @@
 	ps = pkgdb_pkg_sub_get(db, ident);
 	if (ps == NULL)
 		return (DB_NO_PKG);
-	status = pkg_sub_read_files(ps);
-	if (status == NOT_OK) {
+	status |= pkg_sub_read_files(ps);
+	if (status & NOT_OK) {
 		/* might have to free some things in here. */
 		return (NOT_OK);
 	}
@@ -145,8 +148,10 @@
 {
 	struct pkg_sub *ps;
 
-	if (db || ident)
-		;;
+	if (db == NULL)
+		arg_rage_quit(__func__, "Not a valid database.", RAGE_AT_LIBPKG);
+	if (ident == NULL)
+		arg_rage_quit(__func__, "Must pass identifier.", RAGE_AT_LIBPKG);
 	
 	ps = (struct pkg_sub *)bsearch(ident, db->ps_list, db->ps_count,
 		sizeof(*ps), pkg_sub_cmp);
@@ -177,7 +182,7 @@
 	status = PKG_OK;
 	status |= pkg_set_ident(p, pkg_sub_ident(ps));
 	status |= pkg_set_comment(p, pkg_sub_comment(ps));
-	status |= pkg_set_contents(p, pkg_sub_comment(ps));
+	status |= pkg_set_contents(p, pkg_sub_contents(ps));
 	status |= pkg_set_description(p, pkg_sub_desc(ps));
 	status |= pkg_set_display(p, pkg_sub_display(ps));
 	status |= pkg_set_mtree_dirs(p, pkg_sub_mtree_dirs(ps));

==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkgdb_hierdb.c#11 (text+ko) ====

@@ -112,14 +112,7 @@
 		arg_rage_quit(__func__, "Not a valid database.", RAGE_AT_CLIENT);
 	
 	status = OK;
-	// status |= pkg_sub_set_ident(ps, ident);
-	/* Directory is verified here. */
-	// status |= pkgdb_sub_set_assign_db(db, ps);
 	
-	if ((MEMORY_ERR & status) || (BAD_IDENT & status))
-		return (status);
-
-	/* Hope you have your reading glasses on... */
 	status = OK;
 	status |= pkg_sub_read_file_to_text(ps, COMMENT_FILE_ID) &
 		(SUB_EMPTY_FILE | SUB_NO_FILE) ? SUB_NO_COMMENT : OK;

==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkgdb_private.h#5 (text+ko) ====

@@ -19,7 +19,7 @@
 
 	int (*pkgdb_db_open) (struct pkgdb *db, const char *db_root);
 	int (*pkgdb_db_init) (struct pkgdb *db);
-	int (*pkgdb_db_read_sub) (struct pkgdb *db, struct pkg_sub *ps);
+	int (*pkgdb_db_read_pkg_sub) (struct pkgdb *db, struct pkg_sub *ps);
 	int (*pkgdb_db_close) (struct pkgdb *db);
 	int (*pkgdb_db_sync) (struct pkgdb *db);
 };

==== //depot/projects/soc2009/dforsyth_libpkg/pkg_info/main.c#19 (text+ko) ====

@@ -113,25 +113,14 @@
 			print_pkg_information(p);
 		}
 	}
+	pkg_delete(p);
 }
 
 void
 print_pkg_information(struct pkg *p)
 {
-	struct pkg_file *pf;
-	struct pkg_dep *pd;
-	struct pkg_cfl *pc;
 	const char *ident;
 	const char *comment;
-	const char *name;
-	const char *cwd;
-	const char *origin;
-	const char *mtree_file;
-	const char *path;
-	const char *md5;
-	const char *owner;
-	const char *group;
-	const char *mode;
 
 	/* Just print the basic PKGNAME COMMENT scheme right now.  Other
 	 * information isn't collected by the library yet. */
@@ -143,60 +132,7 @@
 			(ident != NULL ? ident : BAD_OR_UNKNOWN_VALUE), 
 			(comment != NULL ? comment : BAD_OR_UNKNOWN_VALUE));
 	} else {
-		/* Testing plist interaction. */
-		name = pkg_name(p);
-		cwd = pkg_cwd(p);
-		origin = pkg_origin(p);
-		mtree_file = pkg_mtree_file(p);
-		
-		printf("%s:\n", 
-			(name != NULL ? name : BAD_OR_UNKNOWN_VALUE));
-		printf("\tcwd: %s\n", 
-			(cwd != NULL ? name : BAD_OR_UNKNOWN_VALUE));
-		printf("\torigin: %s\n", 
-			(origin != NULL ? origin : BAD_OR_UNKNOWN_VALUE));
-		printf("\tmtree file: %s\n",
-			(mtree_file != NULL ? mtree_file : BAD_OR_UNKNOWN_VALUE));
-		printf("\textract in place: %s\n",
-			(pkg_extract_in_place(p) ? "YES" : "NO"));
-		printf("\tpreserve: %s\n",
-			(pkg_preserve(p) ? "YES" : "NO"));
-		printf("\tcomplete: %s\n",
-			(pkg_complete(p) ? "YES" : "NO"));
-		printf("\tfiles:\n");
-		pkg_pkg_file_list_init(p);
-		while ((pf = pkg_pkg_file_list_next(p)) != NULL) {
-			path = pkg_file_path(pf);
-			md5 = pkg_file_md5(pf);
-			owner = pkg_file_owner(pf);
-			group = pkg_file_group(pf);
-			mode = pkg_file_mode(pf);
-			printf("\t\t%s\n", 
-				(path != NULL ? path : BAD_OR_UNKNOWN_VALUE));
-			printf("\t\t\tMD5: %s\n", 
-				(md5 != NULL ? md5 : BAD_OR_UNKNOWN_VALUE));
-			printf("\t\t\tOWNER: %s\n", 
-				(owner != NULL ? owner : BAD_OR_UNKNOWN_VALUE));
-			printf("\t\t\tGROUP: %s\n", 
-				(group != NULL ? group : BAD_OR_UNKNOWN_VALUE));
-			printf("\t\t\tMODE: %s\n",
-				(mode != NULL ? mode : BAD_OR_UNKNOWN_VALUE));
-		}
-
-		printf("\tdepends:\n");
-		pkg_pkg_dep_list_init(p);
-		while ((pd = pkg_pkg_dep_list_next(p)) != NULL) {
-			name = pkg_dep_name(pd);
-			origin = pkg_dep_origin(pd);
-			printf("\t\t%s : %s\n", name, origin);
-		}
-
-		printf("\tconflicts:\n");
-		pkg_pkg_cfl_list_init(p);
-		while ((pc = pkg_pkg_cfl_list_next(p)) != NULL) {
-			name = pkg_cfl_name(pc);
-			printf("\t\t%s\n", name);
-		}
+		pkg_dump(p, stdout);
 	}
 }
 

==== //depot/projects/soc2009/dforsyth_libpkg/pkg_info/pkg_info.h#6 (text+ko) ====

@@ -5,7 +5,6 @@
 /* A goal should be to eliminate this directory, and instead store options
  * seamlessly in plists. */
 #define PORTS_DBDIR_DEFAULT "/var/db/ports"
-#define BAD_OR_UNKNOWN_VALUE "???"
 
 void perform_on_db(struct pkgdb *db);
 void print_pkg_information(struct pkg *p);



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