PERFORCE change 166764 for review
David Forsythe
dforsyth at FreeBSD.org
Thu Jul 30 06:01:36 UTC 2009
http://perforce.freebsd.org/chv.cgi?CH=166764
Change 166764 by dforsyth at squirrel on 2009/07/30 06:01:03
Generalize to manifest, rewrite parser, add magic values, reorganize db. Builds,
but is broken. Submitting for backup.
Affected files ...
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/Makefile#14 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.c#39 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.h#34 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_command.c#2 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_command.h#2 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_conflict.c#6 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_conflict.h#4 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_db.c#7 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_db.h#4 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_db_hierdb.c#6 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_db_hierdb.h#5 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_db_hierdb_read.c#1 add
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_db_hierdb_read.h#1 add
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_db_hierdb_write.c#1 add
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_db_hierdb_write.h#1 add
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_db_private.h#6 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_db_read.c#1 add
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_db_read.h#1 add
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_db_write.c#1 add
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_db_write.h#1 add
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_depend.c#5 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_depend.h#4 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_error.c#1 add
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_error.h#3 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_file.c#11 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_file.h#10 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_manifest.c#1 add
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_manifest.h#1 add
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_manifest_plist.c#1 add
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_manifest_plist.h#1 add
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_plist.c#30 delete
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_plist.h#26 delete
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_private.h#16 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_util.c#14 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_util.h#12 edit
.. //depot/projects/soc2009/dforsyth_libpkg/pkg_info/main.c#25 edit
Differences ...
==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/Makefile#14 (text+ko) ====
@@ -1,8 +1,23 @@
LIB= pkg
INCS= pkg.h
WARNS= 6
-SRCS= pkg_db.c pkg_db_hierdb.c pkg.c pkg_util.c pkg_file.c \
- pkg_depend.c pkg_conflict.c pkg_command.c pkg_plist.c
+
+SRCS= pkg.c \
+ pkg_db.c \
+ pkg_db_read.c \
+ pkg_db_write.c \
+ pkg_db_hierdb.c \
+ pkg_db_hierdb_read.c \
+ pkg_db_hierdb_write.c \
+ pkg_manifest.c \
+ pkg_manifest_plist.c \
+ pkg_file.c \
+ pkg_depend.c \
+ pkg_conflict.c \
+ pkg_command.c \
+ pkg_util.c \
+ pkg_error.c
+
NO_MAN= yes
.include <bsd.lib.mk>
==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.c#39 (text+ko) ====
@@ -3,14 +3,29 @@
#include <string.h>
#include "pkg_util.h"
+#include "pkg_error.h"
#include "pkg_depend.h"
#include "pkg_file.h"
#include "pkg_conflict.h"
-#include "pkg_plist.h"
+#include "pkg_db_write.h"
+#include "pkg_db_read.h"
+#include "pkg_db.h"
+#include "pkg_manifest.h"
#include "pkg_private.h"
#include "pkg.h"
-/* Maybe I should add a pkg_init routine? */
+void pkg_check_magic(struct pkg *p, const char *where);
+static int pkg_set_field(char *dest, const char *src);
+static int pkg_read_pkg_element_from_db(struct pkg *p, int element);
+static int pkg_write_pkg_element_to_db(struct pkg *p, int element);
+static int pkg_parse_manifest(struct pkg *p);
+
+void
+pkg_check_magic(struct pkg *p, const char *where)
+{
+ if (p == NULL || p->magic != PKG_MAGIC)
+ bad_magic_quit("pkg", where);
+}
/* Create a new pkg. */
@@ -18,30 +33,27 @@
pkg_new()
{
struct pkg *p;
-
+
p = calloc(1, sizeof(*p));
+ if (p == NULL)
+ return (NULL);
+ __pkg_init(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. */
+ return (p);
+}
- p->pl = pkg_plist_new();
- if (p == NULL || p->pl == NULL) {
- free(p);
- free(p->pl);
- return (NULL);
- }
-
+void
+__pkg_init(struct pkg *p)
+{
+ p->magic = PKG_MAGIC;
p->ident = NULL;
p->comment = NULL;
- p->contents = NULL;
p->description = NULL;
p->display = NULL;
+ p->required_by = NULL;
p->mtree_dirs = NULL;
- p->required_by = NULL;
- p->dirty = 0;
-
- return (p);
+ p->pm = NULL;
+ p->in_db = NULL;
}
/* Clear and free an allocated pkg. */
@@ -49,11 +61,8 @@
void
pkg_delete(struct pkg *p)
{
- if (p == NULL)
- arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
-
+ pkg_check_magic(p, __func__);
pkg_reset(p);
- free(p->pl);
free(p);
}
@@ -62,28 +71,24 @@
void
pkg_reset(struct pkg *p)
{
- if (p == NULL)
- arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
-
+ pkg_check_magic(p, __func__);
+ if (p->in_db != NULL) {
+ /* change to error msg. */
+ fprintf(stderr, "Package %s is in database %s. Packages in a database \
+ cannot be reset.\n", p->ident, pkg_db_db_root(p->in_db));
+ exit(1);
+ }
+
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_delete(p->pl);
- p->pl = NULL;
+
+ if (p->pm != NULL)
+ pkg_manifest_delete(p->pm);
+ __pkg_init(p);
}
/* Retrieve pkg identity. In hierdb, this is the directory containing the
@@ -93,10 +98,9 @@
const char *
pkg_ident(struct pkg *p)
{
- if (p == NULL)
- arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
+ pkg_check_magic(p, __func__);
- return (p->ident);
+ return ((const char *)p->ident);
}
/* Retrieve pkg name. @name in plist. Conflict and dependency checks
@@ -105,13 +109,11 @@
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) & NOT_OK)
+ pkg_check_magic(p, __func__);
+ if (pkg_parse_manifest(p) != OK)
return (NULL);
- return (pkg_plist_name(p->pl));
+ return (pkg_manifest_name(p->pm));
}
/* Retrieve pkg origin. @origin in plist. The directory of the port that
@@ -120,13 +122,11 @@
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) & NOT_OK)
+ pkg_check_magic(p, __func__);
+ if (p->in_db != NULL && (pkg_parse_manifest(p) & NOT_OK))
return (NULL);
- return (pkg_plist_origin(p->pl));
+ return (pkg_manifest_origin(p->pm));
}
/* Set the identity for this package (does not have to be the same as the
@@ -136,18 +136,16 @@
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);
+ pkg_check_magic(p, __func__);
+ if (p->in_db != NULL) {
+ /* Can't change the ident of a package once it's in a db. */
+ pkg_error_msg("package is in db cant ident");
+ rage_quit();
+ }
+
+ /* TODO: Check ident for validity. Do a string search on the passed ident. */
- free(p->ident);
- p->ident = strdup(ident);
- if (p->ident == NULL)
- return (PKG_MEMORY_ERR | PKG_NOT_OK);
-
- return (PKG_OK);
+ return (pkg_util_strdup(ident, &p->ident));
}
/* Set the name for this package. @name in plist. */
@@ -155,12 +153,16 @@
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);
+ int status;
- return (pkg_plist_set_name(p->pl, name));
+ pkg_check_magic(p, __func__);
+
+ status = OK;
+ status |= pkg_manifest_set_name(p->pm, name);
+ if (status != OK || p->in_db == NULL)
+ return (status);
+ /* Update manifest in db. */
+ return (status);
}
/* Set the origin for this package. @origin in plist. */
@@ -168,12 +170,16 @@
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);
+ int status;
+
+ pkg_check_magic(p, __func__);
- return (pkg_plist_set_origin(p->pl, origin));
+ status = OK;
+ status |= pkg_manifest_set_origin(p->pm, origin);
+ if (status != OK || p->in_db == NULL)
+ return (status);
+ /* Update manifest in db. */
+ return (status);
}
/* Retreive the short comment for this package. (Maybe consider moving
@@ -182,8 +188,13 @@
const char *
pkg_comment(struct pkg *p)
{
- if (p == NULL)
- arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
+ pkg_check_magic(p, __func__);
+
+ if (p->in_db == NULL)
+ return (p->comment);
+
+ if (p->comment == NULL)
+ pkg_read_pkg_element_from_db(p, PKG_ELEM_COMMENT);
return (p->comment);
}
@@ -193,50 +204,23 @@
const char *
pkg_description(struct pkg *p)
{
- if (p == NULL)
- arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
-
+ pkg_check_magic(p, __func__);
+ if (p->in_db == NULL)
+ return (p->description);
+
+ if (p->description == NULL &&
+ pkg_read_pkg_element_from_db(p, PKG_ELEM_DESCRIPTION) != OK)
+ return (NULL);
return (p->description);
}
-/* Retrieve the contents text for this package. Dumps in plist in current
- * FreeBSD format. */
+/* Set the comment for this package. */
-const char *
-pkg_contents(struct pkg *p)
-{
- if (p == NULL)
- arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
-
- if (pkg_plist_parsed(p->pl) && pkg_plist_dirty(p->pl)) {
- free(p->contents);
- p->contents = pkg_plist_dump_to_text(p->pl);
- }
-
- return (p->contents);
-}
-
-/* Set the short comment for this package */
-
int
pkg_set_comment(struct pkg *p, const char *comment)
{
- char *f;
-
- if (p == NULL)
- arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
-
- free(p->comment);
- p->comment = (comment != NULL) ? strdup(comment) : NULL;
- if (p->comment == NULL)
- return (PKG_MEMORY_ERR | PKG_NOT_OK);
-
- /* Blot out trailing \n, if it's there. */
- f = strrchr(p->comment, (int)'\n');
- if (f != NULL && *(f + 1) == '\0')
- *f = '\0';
-
- return (PKG_OK);
+ pkg_check_magic(p, __func__);
+ return (pkg_util_strdup(comment, &p->comment));
}
/* Set the long description for this package. */
@@ -244,45 +228,19 @@
int
pkg_set_description(struct pkg *p, const char *description)
{
- char *f;
+ pkg_check_magic(p, __func__);
- if (p == NULL)
- arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
-
- free(p->description);
- p->description = (description != NULL) ? strdup(description) : NULL;
- if (p->description == NULL)
- return (PKG_MEMORY_ERR | PKG_NOT_OK);
-
- f = strrchr(p->description, (int)'\n');
- if (f != NULL && *(f + 1) == '\0')
- *f = '\0';
-
- return (PKG_OK);
+ return (pkg_util_strdup(description, &p->description));
}
-/* Set the contents (plist) for this package. */
-
-int
-pkg_set_contents(struct pkg *p, const char *contents)
-{
- if (p == NULL)
- arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
-
- p->contents = contents;
- return (PKG_OK);
-}
-
/* Set the display text for this package. */
int
pkg_set_display(struct pkg *p, const char *display)
{
- if (p == NULL)
- arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
+ pkg_check_magic(p, __func__);
- p->display = display;
- return (PKG_OK);
+ return (pkg_util_strdup(display, &p->display));
}
/* Set the mtree_dirs text for this package. This is *NOT* the name of
@@ -291,11 +249,8 @@
int
pkg_set_mtree_dirs(struct pkg *p, const char *mtree_dirs)
{
- if (p == NULL)
- arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
-
- p->mtree_dirs = mtree_dirs;
- return (PKG_OK);
+ pkg_check_magic(p, __func__);
+ return (pkg_util_strdup(mtree_dirs, &p->mtree_dirs));
}
/* Set the required_by text for this file. */
@@ -303,30 +258,35 @@
int
pkg_set_required_by(struct pkg *p, const char *required_by)
{
- if (p == NULL)
- arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
-
- p->required_by = required_by;
- return (PKG_OK);
+ pkg_check_magic(p, __func__);
+ return (pkg_util_strdup(required_by, &p->required_by));
}
int
-pkg_clone(struct pkg *psrc, struct pkg *pdest)
+pkg_clone(struct pkg *src, struct pkg *dest)
{
int status;
+ struct pkg_manifest *pm;
+
+ pkg_check_magic(src, __func__);
+ pkg_check_magic(dest, __func__);
- if (psrc == NULL)
- arg_rage_quit(__func__, "Not a valid package (src).",
- RAGE_AT_CLIENT);
- if (pdest == NULL)
- arg_rage_quit(__func__, "Not a valid package (dest).",
- RAGE_AT_CLIENT);
-
- status = PKG_OK;
- status |= pkg_set_ident(pdest, pkg_ident(psrc));
+ status = OK;
+ pkg_reset(dest);
+ status |= pkg_set_ident(dest, src->ident);
+ status |= pkg_set_comment(dest, src->comment);
+ status |= pkg_set_description(dest, src->description);
+ status |= pkg_set_display(dest, src->display);
+ if (src->pm == NULL)
+ return (status);
+ pm = pkg_manifest_new();
+ if (pm == NULL)
+ status |= MEMORY_ERR;
+ else {
+ status |= pkg_manifest_clone(pm, src->pm);
+ dest->pm = pm;
+ }
- /* Write the rest of this. Need array dup'ing functions. */
-
return (status);
}
@@ -336,10 +296,11 @@
const char *const *
pkg_files(struct pkg *p)
{
- if (p == NULL)
- arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
-
- return (pkg_plist_files(p->pl));
+ pkg_check_magic(p, __func__);
+ if (p->pm == NULL)
+ pkg_parse_manifest(p);
+
+ return (pkg_manifest_pkg_file_list(p->pm));
}
/* Retrieve a list of dependencies for this package (by name). Return a
@@ -348,10 +309,11 @@
const char *const *
pkg_depends(struct pkg *p)
{
- if (p == NULL)
- arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
-
- return (pkg_plist_depends(p->pl));
+ pkg_check_magic(p, __func__);
+ if (p->pm == NULL && p->in_db != NULL)
+ pkg_parse_manifest(p);
+
+ return (pkg_manifest_pkg_depend_list(p->pm));
}
/* Retrieve a list of conflicts for this package (by name). Return a list
@@ -360,147 +322,207 @@
const char *const *
pkg_conflicts(struct pkg *p)
{
- if (p == NULL)
- arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
+ pkg_check_magic(p, __func__);
+ if (p->pm == NULL && p->in_db != NULL)
+ pkg_parse_manifest(p);
- return (pkg_plist_conflicts(p->pl));
+ return (pkg_manifest_pkg_conflict_list(p->pm));
}
/* 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 *cwd,
- const char *group, const char *md5, const char *mode,
- const char *owner)
+pkg_insert_pkg_file(struct pkg *p, const char *path, const char *cwd, const char *md5,
+ const char *mode, const char *owner, const char *group)
{
- struct pkg_file *pf;
int status;
- if (p == NULL)
- arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
+ pkg_check_magic(p, __func__);
- if (path == NULL)
- arg_rage_quit(__func__, "Not a valid path.", RAGE_AT_CLIENT);
- if (md5 == NULL)
- arg_rage_quit(__func__, "Not a valid md5.", RAGE_AT_CLIENT);
- if (owner == NULL)
- arg_rage_quit(__func__, "Not a valid owner.", RAGE_AT_CLIENT);
- if (group == NULL)
- arg_rage_quit(__func__, "Not a valid group.", RAGE_AT_CLIENT);
- if (mode == NULL)
- arg_rage_quit(__func__, "Not a valid mode.", RAGE_AT_CLIENT);
-
/* TODO: Add some sanity checks in here. */
-
- pf = pkg_file_new();
- pkg_file_set_path(pf, path);
- pkg_file_set_cwd(pf, cwd);
- pkg_file_set_group(pf, group);
- pkg_file_set_md5(pf, md5);
- pkg_file_set_mode(pf, mode);
- pkg_file_set_owner(pf, owner);
-
- status = pkg_plist_add_pkg_file(p->pl, pf);
+
+ status = OK;
+ pkg_parse_manifest(p);
+ status |= pkg_manifest_insert_pkg_file(p->pm, path, md5, cwd, mode, owner, group);
return (status);
}
const char *
-pkg_file_get_cwd(struct pkg *p, const char *path)
+pkg_pkg_file_cwd(struct pkg *p, const char *path)
{
struct pkg_file *pf;
-
- pf = pkg_plist_get_pkg_file(p->pl, path);
- if (pf == NULL)
+ pkg_check_magic(p, __func__);
+ if ((pf = pkg_manifest_select_pkg_file(p->pm, path)) == NULL)
return (NULL);
-
- return (pkg_file_cwd(pf));
+ return ((const char *)pkg_file_cwd(pf));
}
const char *
-pkg_file_get_group(struct pkg *p, const char *path)
+pkg_pkg_file_group(struct pkg *p, const char *path)
{
struct pkg_file *pf;
-
- pf = pkg_plist_get_pkg_file(p->pl, path);
- if (pf == NULL)
+ pkg_check_magic(p, __func__);
+ if ((pf = pkg_manifest_select_pkg_file(p->pm, path)) == NULL)
return (NULL);
-
- return (pkg_file_group(pf));
+ return ((const char *)pkg_file_group(pf));
}
const char *
-pkg_file_get_md5(struct pkg *p, const char *path)
+pkg_pkg_file_md5(struct pkg *p, const char *path)
{
struct pkg_file *pf;
-
- pf = pkg_plist_get_pkg_file(p->pl, path);
- if (pf == NULL)
+ pkg_check_magic(p, __func__);
+ if ((pf = pkg_manifest_select_pkg_file(p->pm, path)) == NULL)
return (NULL);
-
- return (pkg_file_md5(pf));
+ return ((const char *)pkg_file_md5(pf));
}
const char *
-pkg_file_get_mode(struct pkg *p, const char *path)
+pkg_pkg_file_mode(struct pkg *p, const char *path)
{
struct pkg_file *pf;
-
- pf = pkg_plist_get_pkg_file(p->pl, path);
- if (pf == NULL)
+ pkg_check_magic(p, __func__);
+ if ((pf = pkg_manifest_select_pkg_file(p->pm, path)) == NULL)
return (NULL);
-
- return (pkg_file_mode(pf));
+ return ((const char *)pkg_file_mode(pf));
}
const char *
-pkg_file_get_owner(struct pkg *p, const char *path)
+pkg_pkg_file_owner(struct pkg *p, const char *path)
{
struct pkg_file *pf;
-
- pf = pkg_plist_get_pkg_file(p->pl, path);
- if (pf == NULL)
+ pkg_check_magic(p, __func__);
+ if ((pf = pkg_manifest_select_pkg_file(p->pm, path)) == NULL)
return (NULL);
-
- return (pkg_file_owner(pf));
+ return ((const char *)pkg_file_owner(pf));
}
const char *
-pkg_depend_get_origin(struct pkg *p, const char *name)
+pkg_pkg_depend_origin(struct pkg *p, const char *name)
{
struct pkg_depend *pd;
+ pkg_check_magic(p, __func__);
+ if ((pd = pkg_manifest_select_pkg_depend(p->pm, name)) == NULL)
+ return (NULL);
+ return ((const char *)pkg_depend_origin(pd));
+}
+
+/* Wrap _write_pkg_element. */
+
+static int
+pkg_write_pkg_element_to_db(struct pkg *p, int element)
+{
+ return (pkg_db_write_pkg_element(p->in_db, p, element));
+}
- pd = pkg_plist_get_pkg_depend(p->pl, name);
- if (pd == NULL)
- return (NULL);
+/* Wrap _read_pkg_element. */
- return (pkg_depend_origin(pd));
+static int
+pkg_read_pkg_element_from_db(struct pkg *p, int element)
+{
+ return (pkg_db_read_pkg_element(p->in_db, p, element));
}
/* Parse the plist (contents) of a package. */
-int
-pkg_parse_plist(struct pkg *p)
+static int
+pkg_parse_manifest(struct pkg *p)
{
int status;
- if (p == NULL)
- arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
- /*
- if (p->pl != NULL)
+ pkg_check_magic(p, __func__);
+
+ /* Manifest has been parsed already. */
+ if (p->pm != 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)) {
- return (OK);
+
+ status = OK;
+ p->pm = pkg_manifest_new();
+ if (p->pm == NULL)
+ return (MEMORY_ERR | NOT_OK);
+ pkg_manifest_reset(p->pm);
+ if (p->in_db != NULL) {
+ status |= pkg_read_pkg_element_from_db(p, PKG_ELEM_MANIFEST);
}
+
+ return (status);
+}
+
+int
+pkg_force_parse_manifest(struct pkg *p)
+{
+ pkg_check_magic(p, __func__);
+
+
+ return (0);
+}
+
+/* These need to be moved. */
- pkg_plist_reset(p->pl);
- status = pkg_plist_parse_contents_from_text(p->pl, p->contents);
- return (status);
+int
+__pkg_set_ident_ptr(struct pkg *p, char *ident_ptr)
+{
+ pkg_check_magic(p, __func__);
+ p->ident = ident_ptr;
+ return (OK);
+}
+
+int
+__pkg_set_comment_ptr(struct pkg *p, char *comment_ptr)
+{
+ pkg_check_magic(p, __func__);
+ p->comment = comment_ptr;
+ return (OK);
+}
+
+int
+__pkg_set_description_ptr(struct pkg *p, char *description_ptr)
+{
+ pkg_check_magic(p, __func__);
+ p->description = description_ptr;
+ return (OK);
+}
+
+int
+__pkg_set_display_ptr(struct pkg *p, char *display_ptr)
+{
+ pkg_check_magic(p, __func__);
+ p->display = display_ptr;
+ return (OK);
+}
+
+int
+__pkg_set_required_by_ptr(struct pkg *p, char *required_by_ptr)
+{
+ pkg_check_magic(p, __func__);
+ p->required_by = required_by_ptr;
+ return (OK);
+}
+
+int
+__pkg_set_mtree_dirs_ptr(struct pkg *p, char *mtree_dirs_ptr)
+{
+ pkg_check_magic(p, __func__);
+ p->mtree_dirs = mtree_dirs_ptr;
+ return (OK);
+}
+
+int
+__pkg_set_pkg_manifest_ptr(struct pkg *p, struct pkg_manifest *pm_ptr)
+{
+ pkg_check_magic(p, __func__);
+ p->pm = pm_ptr;
+ return (OK);
+}
+
+int
+__pkg_set_in_db_ptr(struct pkg *p, struct pkg_db *db)
+{
+ pkg_check_magic(p, __func__);
+ p->in_db = db;
+ return (OK);
}
int
==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.h#34 (text+ko) ====
@@ -1,63 +1,26 @@
#ifndef __PKG_H__
#define __PKG_H__
-#define HIER_DB 0
-#define FLAT_DB 1 /* O_o */
+/* Plist/DB types. Format is 0xXXXXYYYY, where XXXX is manifest type, and YYYY is db type. */
+
+/* HIERDB: Assumes information is stored in files with names with a preceding '+'.
+ * It is the current FreeBSD DB type. */
-/* Here have some error codes. */
+/* PLIST, manifest is in a plist format. */
+#define PLIST_HIER_DB 0x00000000
+/* EXAMPLE: XML, manifest is in xml format. */
+#define XML_HIER_DB 0x00010000
-/* These error codes are no good. Switch to contextual errors/macros. */
/* General Errors. */
#define OK 0x00000000
#define NOT_OK 0x00000001
#define MEMORY_ERR 0x00000002
-#define BAD_IDENT 0x00000004 /* remove db_bad_root? */
-#define RAGE_AT_CLIENT 0x00000008
-#define RAGE_AT_LIBPKG 0x00000010
-/* PKGDB Errors. */
+#define FOREACH_PKG_IN_DB(p, db, list) \
+ while (*list != NULL && (p = pkg_db_select_pkg(db, *list++)))
-#define DB_OK 0x00000000
-#define DB_NOT_OK 0x10000000
-#define DB_BAD_ROOT 0x20000000
-#define DB_NOT_OPEN 0x40000000
-#define DB_OPEN 0x80000000
-#define DB_NO_PKG 0x01000000
-#define DB_MEMORY_ERR 0x02000000
-
-/* These should probably go to _private */
-#define SUB_OK 0x00000000
-#define SUB_NO_COMMENT 0x10000000
-#define SUB_NO_CONTENTS 0x20000000
-#define SUB_NO_DESC 0x40000000
-#define SUB_NO_DISPLAY 0x80000000
-#define SUB_NO_MTREE_DIRS 0x01000000
-#define SUB_NO_REQUIRED_BY 0x02000000
-#define SUB_NO_FILE 0x04000000
-#define SUB_EMPTY_FILE 0x08000000
-#define SUB_MEMORY_ERR 0x00100000
-
-/* PKG Errors. */
-
-#define PKG_OK 0x00000000
-#define PKG_NOT_OK 0x10000000
-#define PKG_PARSE_NOT_OK 0x20000000
-#define PKG_NO_COMMENT 0x40000000
-#define PKG_NO_DESC 0x80000000
-#define PKG_NO_DISPLAY 0x01000000
-#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 "???"
-
/* pkg */
struct pkg *pkg_new(void);
@@ -74,21 +37,19 @@
int pkg_set_cwd(struct pkg *p, const char *cwd);
int pkg_set_origin(struct pkg *p, const char *origin);
+int pkg_set_comment(struct pkg *p, const char *comment);
+int pkg_set_description(struct pkg *p, const char *description);
+int pkg_set_display(struct pkg *p, const char *display);
+
const char *pkg_comment(struct pkg *p);
const char *pkg_description(struct pkg *p);
-const char *pkg_contents(struct pkg *p);
const char *pkg_display(struct pkg *p);
-const char *pkg_mtree_dirs(struct pkg *p);
-const char *pkg_required_by(struct pkg *p);
-int pkg_set_comment(struct pkg *p, const char *comment);
-int pkg_set_description(struct pkg *p, const char *description);
-int pkg_set_contents(struct pkg *p, const char *contents);
-int pkg_set_display(struct pkg *p, const char *display);
+/* tmp */
int pkg_set_mtree_dirs(struct pkg *p, const char *mtree_dirs);
int pkg_set_required_by(struct pkg *p, const char *required_by);
-int pkg_clone(struct pkg *psrc, struct pkg *pdest);
+int pkg_clone(struct pkg *src, struct pkg *dest);
/* Add mtree_dirs, display, etc, etc. */
@@ -100,27 +61,21 @@
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_get_cwd(struct pkg *p, const char *path);
-const char *pkg_file_get_group(struct pkg *p, const char *path);
-const char *pkg_file_get_md5(struct pkg *p, const char *path);
-const char *pkg_file_get_mode(struct pkg *p, const char *path);
-const char *pkg_file_get_owner(struct pkg *p, const char *path);
+const char *pkg_pkg_file_cwd(struct pkg *p, const char *path);
+const char *pkg_pkg_file_group(struct pkg *p, const char *path);
+const char *pkg_pkg_file_md5(struct pkg *p, const char *path);
+const char *pkg_pkg_file_mode(struct pkg *p, const char *path);
+const char *pkg_pkg_file_owner(struct pkg *p, const char *path);
-int pkg_add_depend(struct pkg *p, const char *name, const char *origin,
- int version);
+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_get_origin(struct pkg *p, const char *name);
-int pkg_depend_get_version(struct pkg *p, const char *name);
+const char *pkg_pkg_depend_origin(struct pkg *p, const char *name);
+int pkg_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);
int 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? */
-
-/* TODO: Add installation/deinstallation routine modification... routines. */
-
/* pkg_db */
struct pkg_db *pkg_db_new(void);
@@ -129,8 +84,8 @@
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 *const *pkg_db_all_pkgs(struct pkg_db *db); /* rename. this is lulz. */
+/* Return a list of package keys for this a database. */
+const char *const *pkg_db_all_pkg_keys(struct pkg_db *db);
struct pkg *pkg_db_select_pkg(struct pkg_db *db, const char *ident);
int pkg_db_pkg_count(struct pkg_db *db);
==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_command.c#2 (text+ko) ====
@@ -2,10 +2,21 @@
#include <stdlib.h>
#include <string.h>
+#include "pkg_error.h"
>>> TRUNCATED FOR MAIL (1000 lines) <<<
More information about the p4-projects
mailing list