PERFORCE change 165842 for review

David Forsythe dforsyth at FreeBSD.org
Thu Jul 9 03:01:34 UTC 2009


http://perforce.freebsd.org/chv.cgi?CH=165842

Change 165842 by dforsyth at squirrel on 2009/07/09 03:01:31

	Continue reorganizing around new design.  Plist parser is commented
	out because it hasn't been modified yet, and should probably be
	written with undocumented commands in mind.  This code will compile
	with warnings.

Affected files ...

.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/Makefile#10 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.c#33 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.h#31 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_cfl.c#5 delete
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_cfl.h#5 delete
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_conflict.c#1 branch
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_conflict.h#1 branch
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_db.c#2 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_db.h#2 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_db_hierdb.c#2 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_db_hierdb.h#2 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_db_private.h#2 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_dep.c#6 delete
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_dep.h#7 delete
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_depend.c#1 branch
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_depend.h#1 branch
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_file.c#8 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_file.h#7 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_plist.c#25 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_plist.h#21 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_private.h#12 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_sub.c#6 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_util.c#9 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_util.h#9 edit
.. //depot/projects/soc2009/dforsyth_libpkg/pkg_info/main.c#21 edit
.. //depot/projects/soc2009/dforsyth_libpkg/pkg_info/pkg_info.h#7 edit

Differences ...

==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/Makefile#10 (text+ko) ====

@@ -1,8 +1,8 @@
 LIB=	pkg
 INCS=	pkg.h
 WARNS=	6
-SRCS=	pkgdb.c pkgdb_hierdb.c pkg.c pkg_util.c pkg_file.c \
-		pkg_dep.c pkg_cfl.c pkg_plist.c pkg_sub.c
+SRCS=	pkg_db.c pkg_db_hierdb.c pkg.c pkg_util.c pkg_file.c \
+		pkg_depend.c pkg_conflict.c pkg_plist.c pkg_sub.c
 NO_MAN=	yes
 
 .include <bsd.lib.mk>

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

@@ -3,9 +3,9 @@
 #include <string.h>
 
 #include "pkg_util.h"
-#include "pkg_dep.h"
+#include "pkg_depend.h"
 #include "pkg_file.h"
-#include "pkg_cfl.h"
+#include "pkg_conflict.h"
 #include "pkg_plist.h"
 #include "pkg_db_hierdb.h"
 #include "pkg_db.h"
@@ -23,7 +23,7 @@
 	char *mtree_dirs;
 	char *required_by;
 	
-	struct pkg_plist *plist;
+	struct pkg_plist *pl;
 
 	short dirty;
 	/* Add an owner field? */
@@ -44,10 +44,10 @@
 	 * 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) {
+	p->pl = pkg_plist_new();
+	if (p == NULL || p->pl == NULL) {
 		free(p);
-		free(p->plist);
+		free(p->pl);
 		return (NULL);
 	}
 
@@ -58,7 +58,7 @@
 	p->display = NULL;
 	p->mtree_dirs = NULL;
 	p->required_by = NULL;
-	p->plist = NULL;
+	p->pl = NULL;
 	p->dirty = 0;
 
 	return (p);
@@ -73,7 +73,7 @@
 		arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
 	
 	pkg_reset(p);
-	free(p->plist);
+	free(p->pl);
 	free(p);
 }
 
@@ -102,14 +102,14 @@
 	p->dirty = 0;
 	/* Until plist allocation is done properly, we can't free this in
 	 * here. */	
-	pkg_plist_reset(p->plist);
+	pkg_plist_reset(p->pl);
 }
 
 /* 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 *
+char *
 pkg_ident(struct pkg *p)
 {
 	if (p == NULL)
@@ -121,7 +121,7 @@
 /* Retrieve pkg name. @name in plist. Conflict and dependency checks
  * should rely on this string rather than ident. */
 
-const char *
+char *
 pkg_name(struct pkg *p)
 {
 	if (p == NULL)
@@ -129,29 +129,14 @@
 	
 	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);
 	
-	if (pkg_parse_plist(p) != OK)
-		return (NULL);
-
-	return (pkg_plist_cwd(p->plist));
+	return (strdup(pkg_plist_name(p->pl)));
 }
 
 /* Retrieve pkg origin.  @origin in plist.  The directory of the port that
  * this pkg was create from. */
 
-const char *
+char *
 pkg_origin(struct pkg *p)
 {
 	if (p == NULL)
@@ -160,7 +145,7 @@
 	if (pkg_parse_plist(p) != OK)
 		return (NULL);
 
-	return (pkg_plist_origin(p->plist));
+	return (strdup(pkg_plist_origin(p->pl)));
 }
 
 /* Set the identity for this package (does not have to be the same as the
@@ -174,7 +159,7 @@
 		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);
+			RAGE_AT_CLIENT);
 	
 	free(p->ident);
 	p->ident = strdup(ident);
@@ -194,20 +179,7 @@
 	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));
+	return (pkg_plist_set_name(p->pl, name));
 }
 
 /* Set the origin for this package.  @origin in plist. */
@@ -220,13 +192,13 @@
 	if (origin == NULL)
 		arg_rage_quit(__func__, "Not a valid origin.", RAGE_AT_CLIENT);
 
-	return (pkg_plist_set_origin(p->plist, origin));
+	return (pkg_plist_set_origin(p->pl, origin));
 }
 
 /* Retreive the short comment for this package. (Maybe consider moving
  * this into the plist? */
 
-const char *
+char *
 pkg_comment(struct pkg *p)
 {
 	if (p == NULL)
@@ -237,7 +209,7 @@
 
 /* Retrieve the long description for this package. */
 
-const char *
+char *
 pkg_description(struct pkg *p)
 {
 	if (p == NULL)
@@ -297,48 +269,48 @@
 /* Retrieve a list of file in this package.  Return a list of strings
  * terminated by NULL. */
 
-const char **
+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));
+	return (pkg_plist_files(p->pl));
 }
 
 /* Retrieve a list of dependencies for this package (by name).  Return a
  * list of strings terminated by NULL. */
 
-const char **
+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));
+	return (pkg_plist_depends(p->pl));
 }
 
 /* Retrieve a list of conflicts for this package (by name).  Return a list
  * of strings terminated by NULL. */
 
-const char **
+char **
 pkg_conflicts(struct pkg *p)
 {
 	if (p == NULL)
 		arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
 
-	return (pkg_plist_conflicts(p->plist));
+	return (pkg_plist_conflicts(p->pl));
 }
 
 /* Add a file to a package. This is fairly useless at this point
  * because... well, there the hell is the file coming from? */
 
 int
-pkg_add_file(struct pkg *p, const char *path, const char *md5, 
-	const char *owner, const char *group, const char *mode)
+pkg_add_file(struct pkg *p, const char *path, const char *cwd, 
+	const char *group, const char *md5, const char *mode, 
+	const char *owner)
 {
 	int status;
-	struct pkg_file *pf;
 
 	if (p == NULL)
 		arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
@@ -354,21 +326,11 @@
 	if (mode == NULL)
 		arg_rage_quit(__func__, "Not a valid mode.", RAGE_AT_CLIENT);
 
-	pf = pkg_file_new();
-	if (pf == NULL) {
-		return (PKG_MEMORY_ERR | PKG_NOT_OK);
-	
-	status = PKG_OK;
+	/* TODO: Add some sanity checks in here. */
 
-	status |= pkg_file_set_path(pf, path);
-	status |= pkg_file_set_md5(pf, md5);
-	status |= pkg_file_set_owner(pf, owner);
-	status |= pkg_file_set_group(pf, group);
-	status |= pkg_file_set_mode(pf, mode);
+	status = pkg_plist_add_file(p->pl, path, cwd, group, md5, mode,
+		owner);
 
-	if (status != PKG_OK)
-		pkg_file_delete(pf);
-	
 	return (status);	
 }
 
@@ -382,12 +344,12 @@
 	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->pl)) {
 		/* 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->pl);
+	status = pkg_plist_parse_contents_from_text(p->pl, p->contents);
 	return (status);
 }

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

@@ -60,48 +60,50 @@
 
 /* pkg */
 
-struct pkg *pkg_new();
+struct pkg *pkg_new(void);
 void pkg_delete(struct pkg *p);
-int pkg_reset(struct pkg *p);
+void 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);
+char *pkg_ident(struct pkg *p);
+char *pkg_name(struct pkg *p);
+char *pkg_cwd(struct pkg *p);
+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_comment(struct pkg *p);
-const char *pkg_description(struct pkg *p);
+char *pkg_comment(struct pkg *p);
+char *pkg_description(struct pkg *p);
 
 int pkg_set_comment(struct pkg *p, const char *comment);
 int pkg_set_description(struct pkg *p, const char *description);
 /* Add mtree_dirs, display, etc, etc. */
 
-const char **pkg_files(struct pkg *p);
-const char **pkg_depends(struct pkg *p);
-const char **pkg_conflicts(struct pkg *p);
+char **pkg_files(struct pkg *p);
+char **pkg_depends(struct pkg *p);
+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_add_file(struct pkg *p, const char *path, const char *cwd, 
+	const char *group, const char *md5, const char *mode, 
+	const char *owner);
 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);
+char *pkg_file_get_cwd(struct pkg *p, const char *path);
+char *pkg_file_get_group(struct pkg *p, const char *path);
+char *pkg_file_get_md5(struct pkg *p, const char *path);
+char *pkg_file_get_mode(struct pkg *p, const char *path);
+char *pkg_file_get_owner(struct pkg *p, const char *path);
 
 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);
+const char *pkg_depend_get_origin(struct pkg *p, const char *name);
+int pkg_depend_get_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);
+const char *pkg_conflict_get_version(struct pkg *p, const char *name);
 
 /* TODO: Should I add a function to add names of pkgs that depend on a
  * pkg? */
@@ -110,15 +112,14 @@
 
 /* pkg_db */
 
-struct pkg_db *pkg_db_new();
+struct pkg_db *pkg_db_new(void);
 void pkg_db_delete(struct pkg_db *db);
 
-int pkg_db_open(struct pkg_db *db, const char *path, int db_type);
-/* With the new design, is "init" even needed? */
-int pkg_db_init(struct pkg_db *db);
+int pkg_db_open(struct pkg_db *db, const char *db_root, int db_type);
+int pkg_db_close(struct pkg_db *db);
 
 /* Return a list of packages by _ident_. */
-const char *pkg_db_all_pkgs(struct pkg_db *db); /* rename.  this is lulz. */
+char **pkg_db_all_pkgs(struct pkg_db *db); /* rename.  this is lulz. */
 int pkg_db_select_pkg(struct pkg_db *db, struct pkg *p, const char *pkgident);
 
 int pkg_db_insert_pkg(struct pkg_db *db, struct pkg *p);
@@ -127,12 +128,12 @@
 
 /* pkg_repo */
 
-struct pkgrepo *pkgrepo_new();
-void pkgrepo_delete(struct pkgrepo *pr);
+struct pkg_repo *pkg_repo_new(void);
+void pkg_repo_delete(struct pkg_repo *pr);
 
-/* pkgarchive */
+/* pkg_archive */
 
-struct pkgarchive *pkgarchive_new();
-void pkgarchive_delete(struct pkgarchive *pa;
+struct pkg_archive *pkg_archive_new(void);
+void pkg_archive_delete(struct pkg_archive *pa);
 
 #endif

==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_db.c#2 (text+ko) ====

@@ -1,64 +1,54 @@
 #include <stdio.h>
 #include <stdlib.h>
-
-#include <sys/queue.h>
+#include <string.h>
 
 #include "pkg_util.h"
 #include "pkg_sub.h"
-#include "pkgdb_hierdb.h"
-#include "pkgdb_private.h"
-#include "pkgdb.h"
+#include "pkg_db_hierdb.h"
+#include "pkg_db_private.h"
+#include "pkg_db.h"
 #include "pkg.h"
 
 /* TODO: Add path length checks. */
 
-struct pkgdb *
-pkgdb_new(int type)
+struct pkg_db *
+pkg_db_new()
 {
-	struct pkgdb *db;
+	struct pkg_db *db;
 
 	db = calloc(1, sizeof(*db));
 	if (db == NULL)
 		return (db);
 
-	switch (type) {
-	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:
-		/* Bad type. */
-		free(db);
-		return (NULL);
-	}
-
 	db->open = 0;
 
 	return (db);
 }
 
 int
-pkgdb_db_open(struct pkgdb *db, const char *db_root)
+pkg_db_open(struct pkg_db *db, const char *db_root, int db_type)
 {
 	if (db->open)
 		return (DB_OPEN);
+	
+	switch (db_type) {
+	case (HIER_DB):
+		db->pkg_db_db_open = pkg_db_hierdb_db_open;
+		db->pkg_db_db_init = pkg_db_hierdb_db_init;
+		db->pkg_db_db_read_pkg_sub = pkg_db_hierdb_read_pkg_sub;
+		/* db->pkg_db_db_close = pkg_db_hierdb_db_close; */
+		break;
+	default:
+		/* Bad type. */
+		free(db);
+		return (DB_NOT_OK);
+	}
 
-	return (db->pkgdb_db_open(db, db_root));
+	return (db->pkg_db_db_open(db, db_root));
 }
 
 int
-pkgdb_db_init(struct pkgdb *db)
-{
-	if (!db->open)
-		return (DB_NOT_OPEN);
-	
-	return (db->pkgdb_db_init(db));
-}
-
-int
-pkgdb_db_close(struct pkgdb *db)
+pkg_db_close(struct pkg_db *db)
 {
 	if (db == NULL)
 		arg_rage_quit(__func__, "Not a valid database.", RAGE_AT_CLIENT);
@@ -66,7 +56,7 @@
 	if (!db->open)
 		return (DB_NOT_OPEN);
 
-	pkgdb_pkg_sub_list_free(db); /* Should set sub_count to 0. */
+	pkg_db_pkg_sub_list_free(db); /* Should set sub_count to 0. */
 	free(db->db_root);
 
 	db->open = 0;
@@ -75,47 +65,33 @@
 }
 
 void 
-pkgdb_db_delete(struct pkgdb *db)
+pkg_db_delete(struct pkg_db *db)
 {
 	if (db == NULL)
-		arg_rage_quit(__func__, "Not a valid database.", RAGE_AT_CLIENT);
+		return;
 	if (db->open)
-		pkgdb_db_close(db);
+		pkg_db_close(db);
 	
 	free(db);
 }
 
-int
-pkgdb_pkg_next(struct pkgdb *db, struct pkg *p)
+char **
+pkg_db_all_pkgs(struct pkg_db *db)
 {
-	int status;
-	struct pkg_sub *ps;
+	int i;
+	char **list;
 
-	if (db == NULL)
-		arg_rage_quit(__func__, "Not a valid database.", RAGE_AT_CLIENT);
-
-	if (p == NULL)
-		arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
-
-	/* Whenever a package is pulled from the db, we parse it again.  User
-	 * 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. */
+	list = malloc(sizeof(*list) * (db->ps_count));
+	for (i = 0; i < db->ps_count; ++i) {
+		list[i] = strdup(pkg_sub_ident(db->ps_list + i));
 	}
+	list[i] = NULL;
 
-	status |= db->pkgdb_db_read_pkg_sub(db, ps);
-	status |= pkgdb_generate_pkg_from_pkg_sub(db, p, ps);
-
-	return (status);
+	return (list);
 }
 
 int
-pkgdb_pkg_get(struct pkgdb *db, struct pkg *p, const char *ident)
+pkg_db_select_pkg(struct pkg_db *db, struct pkg *p, const char *ident)
 {
 	/* TODO: Write this function. */
 	int status;
@@ -129,9 +105,10 @@
 		arg_rage_quit(__func__, "Not a valid identifier.",
 			RAGE_AT_CLIENT);
 	
+	pkg_set_ident(p, ident);
+
 	status = PKG_OK;
-	pkg_reset(p);
-	ps = pkgdb_pkg_sub_get(db, ident);
+	ps = pkg_db_pkg_sub_get(db, ident);
 	if (ps == NULL)
 		return (DB_NO_PKG);
 	status |= pkg_sub_read_files(ps);
@@ -144,7 +121,7 @@
 }
 
 struct pkg_sub *
-pkgdb_pkg_sub_get(struct pkgdb *db, const char *ident)
+pkg_db_pkg_sub_get(struct pkg_db *db, const char *ident)
 {
 	struct pkg_sub *ps;
 
@@ -154,7 +131,7 @@
 		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);
+		sizeof(struct pkg_sub), pkg_sub_cmp);
 
 	return (ps);
 }
@@ -162,10 +139,10 @@
 /* Populate a package based on a pkg subdirectory in the db. */
 
 int
-pkgdb_generate_pkg_from_pkg_sub(struct pkgdb *db, struct pkg *p, 
+pkg_db_generate_pkg_from_pkg_sub(struct pkg_db *db, struct pkg *p, 
 	struct pkg_sub *ps)
 {
-	/* Does this need to be a pkgdb_ function? */
+	/* Does this need to be a pkg_db_ function? */
 	int status;
 
 	if (db == NULL)
@@ -182,54 +159,24 @@
 	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_contents(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));
-	status |= pkg_set_required_by(p, pkg_sub_required_by(ps));
+	/* status |= pkg_set_display(p, pkg_sub_display(ps)); */
+	/* status |= pkg_set_mtree_dirs(p, pkg_sub_mtree_dirs(ps)); */
+	/* status |= pkg_set_required_by(p, pkg_sub_required_by(ps)); */
 	
 	return (status);
 }
 
 void
-pkgdb_pkg_sub_list_free(struct pkgdb *db)
+pkg_db_pkg_sub_list_free(struct pkg_db *db)
 {
 	if (db) return;
 	return;
 }
 
-struct pkg_sub *
-pkgdb_pkg_sub_list_next(struct pkgdb *db)
-{
-	struct pkg_sub *ps;
-
-	if (db == NULL)
-		arg_rage_quit(__func__, "Not a valid database.", RAGE_AT_LIBPKG);
-
-	if (db->ps_curr == NULL)
-		ps = db->ps_curr = db->ps_list;
-	else if (db->ps_curr < db->ps_last)
-		ps = ++db->ps_curr;
-	else
-		ps = NULL;
-
-	return (ps);
-}
-
-struct pkg_sub *
-pkgdb_pkg_sub_list_first(struct pkgdb *db)
-{
-	struct pkg_sub *ps;
-
-	if (db == NULL)
-		arg_rage_quit(__func__, "Not a valid database.", RAGE_AT_LIBPKG);
-	
-	ps = db->ps_list + 0;
-	return (ps);
-}
-
 void
-pkgdb_pkg_sub_list_append(struct pkgdb *db,  struct pkg_sub *ps)
+pkg_db_pkg_sub_list_append(struct pkg_db *db,  struct pkg_sub *ps)
 {
 	if (db == NULL)
 		arg_rage_quit(__func__, "Not a valid database.", RAGE_AT_LIBPKG);
@@ -241,7 +188,7 @@
 }
 
 void
-pkgdb_pkg_sub_list_init(struct pkgdb *db)
+pkg_db_pkg_sub_list_init(struct pkg_db *db)
 {
 	if (db == NULL)
 		arg_rage_quit(__func__, "Not a valid database.", RAGE_AT_LIBPKG);
@@ -250,8 +197,8 @@
 	return;
 }
 
-char *
-pkgdb_db_root(struct pkgdb *db)
+const char *
+pkg_db_db_root(struct pkg_db *db)
 {
 	return (db->db_root);
 }

==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_db.h#2 (text+ko) ====

@@ -5,23 +5,25 @@
 
 #include "pkg.h"
 
-void pkgdb_pkg_sub_list_free(struct pkgdb *db);
+void pkg_db_pkg_sub_list_free(struct pkg_db *db);
 
-void pkgdb_pkg_sub_list_init(struct pkgdb *db);
+void pkg_db_pkg_sub_list_init(struct pkg_db *db);
 
-void pkgdb_pkg_sub_list_reset_iter(struct pkgdb *db);
+void pkg_db_pkg_sub_list_reset_iter(struct pkg_db *db);
 
-struct pkg_sub *pkgdb_pkg_sub_list_next(struct pkgdb *db);
+struct pkg_sub *pkg_db_pkg_sub_list_next(struct pkg_db *db);
 
-struct pkg_sub *pkgdb_pkg_sub_list_first(struct pkgdb *db);
+struct pkg_sub *pkg_db_pkg_sub_list_first(struct pkg_db *db);
 
-void pkgdb_pkg_sub_list_append(struct pkgdb *db,  struct pkg_sub *sub);
+void pkg_db_pkg_sub_list_append(struct pkg_db *db,  struct pkg_sub *sub);
 
-struct pkg_sub *pkgdb_pkg_sub_get(struct pkgdb *db, const char *ident);
+struct pkg_sub *pkg_db_pkg_sub_get(struct pkg_db *db, const char *ident);
 
-int pkgdb_pkg_sub_list_create(struct pkgdb *db, int size);
+int pkg_db_pkg_sub_list_create(struct pkg_db *db, int size);
 
-int pkgdb_generate_pkg_from_pkg_sub(struct pkgdb *db, struct pkg *p, 
+int pkg_db_generate_pkg_from_pkg_sub(struct pkg_db *db, struct pkg *p, 
 	struct pkg_sub *ps);
 
+const char *pkg_db_db_root(struct pkg_db *db);
+
 #endif

==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_db_hierdb.c#2 (text+ko) ====

@@ -9,13 +9,13 @@
 #include "pkg_util.h"
 #include "pkg_private.h"
 #include "pkg.h"
-#include "pkgdb.h"
-#include "pkgdb_private.h"
-#include "pkgdb_hierdb.h"
+#include "pkg_db.h"
+#include "pkg_db_private.h"
+#include "pkg_db_hierdb.h"
 #include "pkg_sub.h"
 
 int
-pkgdb_hierdb_db_open(struct pkgdb *db, const char *db_root)
+pkg_db_hierdb_db_open(struct pkg_db *db, const char *db_root)
 {
 	int s;
 	struct stat sb;
@@ -45,11 +45,11 @@
 	db->ps_curr = NULL;
 	db->ps_count = 0;
 
-	return (OK);
+	return (pkg_db_hierdb_db_init(db));
 }	
 
 int
-pkgdb_hierdb_db_init(struct pkgdb *db)
+pkg_db_hierdb_db_init(struct pkg_db *db)
 {
 	int i;
 	int c;
@@ -68,12 +68,11 @@
 	c = scandir(db->db_root, &ents, subdir_sel, alphasort);
 	if (c < 1)
 		return (NOT_OK | MEMORY_ERR);
-	
+
 	ps_list = calloc(c, sizeof(struct pkg_sub));
-	if (status != OK)
+	if (ps_list == NULL)
 		return (NOT_OK | MEMORY_ERR);
 	
-
 	for (i = 0, cnt = 0; i < c; ++i, ++cnt) {
 		if (ents[i]->d_type != DT_DIR) {
 			--cnt;
@@ -81,7 +80,7 @@
 		}
 		status |= pkg_sub_init(ps_list + cnt, db, ents[i]->d_name);
 		if (PKG_SUB_MEM_ERR(status)) {
-			pkgdb_pkg_sub_list_free(db);
+			pkg_db_pkg_sub_list_free(db);
 			for (; i < c; ++i)
 				free(ents[i]);
 			free(ents);
@@ -102,7 +101,7 @@
 }
 
 int
-pkgdb_hierdb_read_pkg_sub(struct pkgdb *db, struct pkg_sub *ps)
+pkg_db_hierdb_read_pkg_sub(struct pkg_db *db, struct pkg_sub *ps)
 {
 	int status;
 #if 0 /* The client doesn't know about the functions in this file. */
@@ -131,7 +130,7 @@
 }
 
 int
-pkgdb_hierdb_db_sync(struct pkgdb *db)
+pkg_db_hierdb_db_sync(struct pkg_db *db)
 {
 	int status;
 

==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_db_hierdb.h#2 (text+ko) ====

@@ -4,14 +4,14 @@
 #include "pkg.h"
 #include "pkg_sub.h"
 
-int pkgdb_hierdb_db_open(struct pkgdb *db, const char *db_root);
+int pkg_db_hierdb_db_open(struct pkg_db *db, const char *db_root);
 
-int pkgdb_hierdb_db_init(struct pkgdb *db);
+int pkg_db_hierdb_db_init(struct pkg_db *db);
 
-int pkgdb_hierdb_read_pkg_sub(struct pkgdb *db, struct pkg_sub *ps);
+int pkg_db_hierdb_read_pkg_sub(struct pkg_db *db, struct pkg_sub *ps);
 
-/* int pkgdb_hierdb_db_close(struct pkgdb *db); */
+/* int pkg_db_hierdb_db_close(struct pkg_db *db); */
 
-int pkgdb_hierdb_db_sync(struct pkgdb *db);
+int pkg_db_hierdb_db_sync(struct pkg_db *db);
 
 #endif

==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_db_private.h#2 (text+ko) ====

@@ -3,7 +3,7 @@
 
 #include <sys/queue.h>
 
-struct pkgdb {
+struct pkg_db {
 	int open;
 	int type;
 	int dirty;
@@ -17,11 +17,11 @@
 	struct pkg_sub *ps_list;
 	struct pkg_sub *ps_last;
 
-	int (*pkgdb_db_open) (struct pkgdb *db, const char *db_root);
-	int (*pkgdb_db_init) (struct pkgdb *db);
-	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);
+	int (*pkg_db_db_open) (struct pkg_db *db, const char *db_root);
+	int (*pkg_db_db_init) (struct pkg_db *db);
+	int (*pkg_db_db_read_pkg_sub) (struct pkg_db *db, struct pkg_sub *ps);
+	int (*pkg_db_db_close) (struct pkg_db *db);
+	int (*pkg_db_db_sync) (struct pkg_db *db);
 };
 
 #endif

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

@@ -2,29 +2,78 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "pkg_util.h"
 #include "pkg_file.h"
 #include "pkg.h"
 
-/* TODO: Evolve these functions to check for the actual existance of
- * users, groups, mode validity.  Add md5 comparison functions, etc... */
-
 struct pkg_file *
 pkg_file_new()
 {	
 	struct pkg_file *pf;
 	
 	pf = calloc(1, sizeof(*pf));
+	if (pf == NULL)
+		return (NULL);
+
+	pf->cwd = NULL;
+	pf->group = NULL;
+	pf->md5 = NULL;
+	pf->mode = NULL;
+	pf->owner = NULL;
+	pf->path = NULL;
 
 	return (pf);
 }
 
+void
+pkg_file_reset(struct pkg_file *pf)
+{
+	if (pf == NULL)
+		arg_rage_quit(__func__, "Not a valid package file.",
+			RAGE_AT_LIBPKG);
+	
+	free(pf->cwd);
+	free(pf->group);
+	free(pf->md5);
+	free(pf->mode);
+	free(pf->owner);
+	free(pf->path);
+	pf->cwd = NULL;
+	pf->group = NULL;
+	pf->md5 = NULL;
+	pf->mode = NULL;
+	pf->owner = NULL;
+	pf->path = NULL;
+}
+
+void
+pkg_file_delete(struct pkg_file *pf)
+{
+	if (pf == NULL)
+		arg_rage_quit(__func__, "Not a valid package file.", 
+			RAGE_AT_LIBPKG);
+
+	pkg_file_reset(pf);
+	free(pf);
+}
+
 const char *
-pkg_file_path(struct pkg_file *pf)
+pkg_file_cwd(struct pkg_file *pf)
+{
+	if (pf == NULL)
+		return (NULL);
+
+	return (pf->cwd);
+
+}
+
+const char *
+pkg_file_group(struct pkg_file *pf)
 {
 	if (pf == NULL)
 		return (NULL);
 
-	return (pf->path);
+	return (pf->group);
 }
 
 const char *
@@ -45,9 +94,6 @@
 	return (pf->mode);
 }
 
-/* If NULL is returned from pkg_file_owner or pkg_file_group, assume the
- * default owner and group. */
-
 const char *
 pkg_file_owner(struct pkg_file *pf)
 {
@@ -57,14 +103,7 @@
 	return (pf->owner);
 }
 
-const char *
-pkg_file_group(struct pkg_file *pf)
-{
-	if (pf == NULL)
-		return (NULL);

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


More information about the p4-projects mailing list