PERFORCE change 166061 for review
David Forsythe
dforsyth at FreeBSD.org
Tue Jul 14 06:20:29 UTC 2009
http://perforce.freebsd.org/chv.cgi?CH=166061
Change 166061 by dforsyth at squirrel on 2009/07/14 06:19:28
Reorganize and lighten up things. qsort and bsearch need to be
dropped into place. This rev compiles with some complaints, but it
works fine.
Affected files ...
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/Makefile#11 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.c#34 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.h#32 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_conflict.c#3 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_db.c#3 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_db.h#3 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_db_hierdb.c#3 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_db_hierdb.h#3 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_db_private.h#3 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_plist.c#26 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_plist.h#22 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_private.h#13 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_sub.c#7 delete
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_sub.h#6 delete
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_util.c#10 edit
.. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_util.h#10 edit
.. //depot/projects/soc2009/dforsyth_libpkg/pkg_info/main.c#22 edit
Differences ...
==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/Makefile#11 (text+ko) ====
@@ -2,7 +2,7 @@
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_plist.c pkg_sub.c
+ pkg_depend.c pkg_conflict.c pkg_plist.c
NO_MAN= yes
.include <bsd.lib.mk>
==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.c#34 (text+ko) ====
@@ -10,25 +10,8 @@
#include "pkg_db_hierdb.h"
#include "pkg_db.h"
#include "pkg_private.h"
-#include "pkg_sub.h"
#include "pkg.h"
-struct pkg {
- char *ident; /* User given name for this pkg. */
-
- char *contents;
- char *comment;
- char *description;
- char *display;
- char *mtree_dirs;
- char *required_by;
-
- struct pkg_plist *pl;
-
- short dirty;
- /* Add an owner field? */
-};
-
/* Maybe I should add a pkg_init routine? */
/* Create a new pkg. */
@@ -109,7 +92,7 @@
* plist. This is a client set identifier, so conflict and dependendency
* checks should not rely on it. */
-char *
+const char *
pkg_ident(struct pkg *p)
{
if (p == NULL)
@@ -121,31 +104,31 @@
/* Retrieve pkg name. @name in plist. Conflict and dependency checks
* should rely on this string rather than ident. */
-char *
+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)
+ if (pkg_parse_plist(p) | NOT_OK)
return (NULL);
- return (strdup(pkg_plist_name(p->pl)));
+ return (pkg_plist_name(p->pl));
}
/* Retrieve pkg origin. @origin in plist. The directory of the port that
* this pkg was create from. */
-char *
+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)
+
+ if (pkg_parse_plist(p) | NOT_OK)
return (NULL);
- return (strdup(pkg_plist_origin(p->pl)));
+ return (pkg_plist_origin(p->pl));
}
/* Set the identity for this package (does not have to be the same as the
@@ -198,7 +181,7 @@
/* Retreive the short comment for this package. (Maybe consider moving
* this into the plist? */
-char *
+const char *
pkg_comment(struct pkg *p)
{
if (p == NULL)
@@ -209,7 +192,7 @@
/* Retrieve the long description for this package. */
-char *
+const char *
pkg_description(struct pkg *p)
{
if (p == NULL)
@@ -218,6 +201,17 @@
return (p->description);
}
+/* Retrieve the contents text for this package. */
+
+const char *
+pkg_contents(struct pkg *p)
+{
+ if (p == NULL)
+ arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_CLIENT);
+
+ return (p->contents);
+}
+
/* Set the short comment for this package */
int
@@ -263,13 +257,62 @@
return (PKG_OK);
}
+/* 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);
+
+ p->display = display;
+ return (PKG_OK);
+}
+
+/* Set the mtree_dirs text for this package. This is *NOT* the name of
+ * the mtree file. */
+
+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);
+}
+
+/* Set the required_by text for this file. */
+
+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);
+}
+
/* 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. */
-char **
+const char *const *
pkg_files(struct pkg *p)
{
if (p == NULL)
@@ -281,7 +324,7 @@
/* Retrieve a list of dependencies for this package (by name). Return a
* list of strings terminated by NULL. */
-char **
+const char *const *
pkg_depends(struct pkg *p)
{
if (p == NULL)
@@ -293,7 +336,7 @@
/* Retrieve a list of conflicts for this package (by name). Return a list
* of strings terminated by NULL. */
-char **
+const char *const *
pkg_conflicts(struct pkg *p)
{
if (p == NULL)
==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.h#32 (text+ko) ====
@@ -64,36 +64,47 @@
void pkg_delete(struct pkg *p);
void pkg_reset(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);
+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);
-char *pkg_comment(struct pkg *p);
-char *pkg_description(struct pkg *p);
+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);
+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);
+
/* Add mtree_dirs, display, etc, etc. */
-char **pkg_files(struct pkg *p);
-char **pkg_depends(struct pkg *p);
-char **pkg_conflicts(struct pkg *p);
+const char *const *pkg_files(struct pkg *p);
+const char *const *pkg_depends(struct pkg *p);
+const char *const *pkg_conflicts(struct pkg *p);
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);
-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);
+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);
int pkg_add_depend(struct pkg *p, const char *name, const char *origin,
int version);
@@ -103,7 +114,7 @@
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_get_version(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? */
@@ -119,8 +130,9 @@
int pkg_db_close(struct pkg_db *db);
/* Return a list of packages by _ident_. */
-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);
+const char *const *pkg_db_all_pkgs(struct pkg_db *db); /* rename. this is lulz. */
+struct pkg *pkg_db_select_pkg(struct pkg_db *db, const char *ident);
+int pkg_db_pkg_count(struct pkg_db *db);
int pkg_db_insert_pkg(struct pkg_db *db, struct pkg *p);
int pkg_db_delete_pkg(struct pkg_db *db, const char *pkgident);
==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_conflict.c#3 (text+ko) ====
@@ -14,6 +14,8 @@
struct pkg_conflict *pc;
pc = calloc(1, sizeof(*pc));
+ if (pc != NULL)
+ pc->name = NULL;
return (pc);
}
==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_db.c#3 (text+ko) ====
@@ -3,10 +3,10 @@
#include <string.h>
#include "pkg_util.h"
-#include "pkg_sub.h"
#include "pkg_db_hierdb.h"
#include "pkg_db_private.h"
#include "pkg_db.h"
+#include "pkg_private.h"
#include "pkg.h"
/* TODO: Add path length checks. */
@@ -28,14 +28,15 @@
int
pkg_db_open(struct pkg_db *db, const char *db_root, int db_type)
{
+ int status;
+
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_read_pkg_from_db = pkg_db_hierdb_read_pkg_from_db;
/* db->pkg_db_db_close = pkg_db_hierdb_db_close; */
break;
default:
@@ -43,8 +44,11 @@
free(db);
return (DB_NOT_OK);
}
+
+ status = DB_OK;
+ status |= db->pkg_db_db_open(db, db_root);
- return (db->pkg_db_db_open(db, db_root));
+ return (status);
}
int
@@ -56,7 +60,7 @@
if (!db->open)
return (DB_NOT_OPEN);
- pkg_db_pkg_sub_list_free(db); /* Should set sub_count to 0. */
+ pkg_db_clear_pkg_list(db); /* Should set sub_count to 0. */
free(db->db_root);
db->open = 0;
@@ -75,130 +79,112 @@
free(db);
}
-char **
+const char *const *
pkg_db_all_pkgs(struct pkg_db *db)
{
- int i;
- char **list;
-
- 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;
-
- return (list);
+ if (db == NULL)
+ arg_rage_quit(__func__, "Not a valid database.", RAGE_AT_CLIENT);
+ return (db->pkg_list);
}
-int
-pkg_db_select_pkg(struct pkg_db *db, struct pkg *p, const char *ident)
+struct pkg *
+pkg_db_select_pkg(struct pkg_db *db, const char *ident)
{
- /* TODO: Write this function. */
- int status;
- struct pkg_sub *ps;
+ int i;
+ struct pkg *p;
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);
if (ident == NULL)
arg_rage_quit(__func__, "Not a valid identifier.",
RAGE_AT_CLIENT);
- pkg_set_ident(p, ident);
+ /*p = (struct pkg *)bsearch(ident, db->pkg_list, db->pkg_count - 1,
+ sizeof(struct pkg), pkg_cmp);*/
+
+ p = NULL;
+ for (i = 0; i < db->pkg_count; ++i)
+ if (strcmp(db->pkg_entries[i]->ident, ident) == 0)
+ p = db->pkg_entries[i];
- status = PKG_OK;
- ps = pkg_db_pkg_sub_get(db, ident);
- if (ps == NULL)
- return (DB_NO_PKG);
- status |= pkg_sub_read_files(ps);
- if (status & NOT_OK) {
- /* might have to free some things in here. */
- return (NOT_OK);
- }
-
- return (status);
+ return (p);
}
-struct pkg_sub *
-pkg_db_pkg_sub_get(struct pkg_db *db, const char *ident)
+int
+pkg_db_insert_pkg(struct pkg_db *db, struct pkg *p)
{
- struct pkg_sub *ps;
-
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);
+ 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);
- ps = (struct pkg_sub *)bsearch(ident, db->ps_list, db->ps_count,
- sizeof(struct pkg_sub), pkg_sub_cmp);
+ /* do work. */
- return (ps);
+ return (/* status */ DB_OK);
}
-/* Populate a package based on a pkg subdirectory in the db. */
-
int
-pkg_db_generate_pkg_from_pkg_sub(struct pkg_db *db, struct pkg *p,
- struct pkg_sub *ps)
+pkg_db_add_pkg_entry(struct pkg_db *db, struct pkg *p)
{
- /* Does this need to be a pkg_db_ function? */
- int status;
+ char **pkg_list_tmp;
+ struct pkg **pkg_entries_tmp;
+
- if (db == NULL)
- arg_rage_quit(__func__, "Not a valid database.", RAGE_AT_LIBPKG);
+ if (db->pkg_count % 10 == 0) {
+ pkg_entries_tmp = db->pkg_entries;
+ pkg_list_tmp = db->pkg_list;
+ db->pkg_entries = realloc(pkg_entries_tmp,
+ sizeof(struct pkg *) * (db->pkg_count + 10 + 1));
+ db->pkg_list = realloc(pkg_list_tmp,
+ sizeof(char *) * (db->pkg_count + 10 + 1));
+ /* Dont feel like writing this out right now. */
+ if (db->pkg_entries == NULL || db->pkg_list == NULL) {
+ printf("need moar memory\n");
+ exit(100);
+ }
+ }
+
+ db->pkg_entries[db->pkg_count] = p;
+ db->pkg_list[db->pkg_count] = p->ident;
+ 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. */
- if (p == NULL)
- arg_rage_quit(__func__, "Not a valid package.", RAGE_AT_LIBPKG);
-
- if (ps == NULL)
- arg_rage_quit(__func__, "Not a valid pkg_sub.", RAGE_AT_LIBPKG);
-
- pkg_reset(p);
-
- 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_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)); */
-
- return (status);
+ return (DB_OK);
}
void
-pkg_db_pkg_sub_list_free(struct pkg_db *db)
+pkg_db_clear_pkg_entries(struct pkg_db *db)
{
- if (db) return;
+ if (db)
+ return;
return;
}
void
-pkg_db_pkg_sub_list_append(struct pkg_db *db, struct pkg_sub *ps)
+pkg_db_clear_pkg_list(struct pkg_db *db)
{
- if (db == NULL)
- arg_rage_quit(__func__, "Not a valid database.", RAGE_AT_LIBPKG);
-
- if (ps == NULL)
- arg_rage_quit(__func__, "Not a valid sub directory.",
- RAGE_AT_LIBPKG);
- return;
+ if (db)
+ return;
+ return;
}
-void
-pkg_db_pkg_sub_list_init(struct pkg_db *db)
+int
+pkg_db_pkg_count(struct pkg_db *db)
{
if (db == NULL)
arg_rage_quit(__func__, "Not a valid database.", RAGE_AT_LIBPKG);
- db->ps_curr = NULL;
- return;
+ return (db->pkg_count);
}
const char *
pkg_db_db_root(struct pkg_db *db)
{
+ if (db == NULL)
+ arg_rage_quit(__func__, "Not a valid database.", RAGE_AT_LIBPKG);
+
return (db->db_root);
}
==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_db.h#3 (text+ko) ====
@@ -5,24 +5,11 @@
#include "pkg.h"
-void pkg_db_pkg_sub_list_free(struct pkg_db *db);
+int pkg_db_add_pkg_entry(struct pkg_db *db, struct pkg *p);
-void pkg_db_pkg_sub_list_init(struct pkg_db *db);
+void pkg_db_clear_pkg_entries(struct pkg_db *db);
-void pkg_db_pkg_sub_list_reset_iter(struct pkg_db *db);
-
-struct pkg_sub *pkg_db_pkg_sub_list_next(struct pkg_db *db);
-
-struct pkg_sub *pkg_db_pkg_sub_list_first(struct pkg_db *db);
-
-void pkg_db_pkg_sub_list_append(struct pkg_db *db, struct pkg_sub *sub);
-
-struct pkg_sub *pkg_db_pkg_sub_get(struct pkg_db *db, const char *ident);
-
-int pkg_db_pkg_sub_list_create(struct pkg_db *db, int size);
-
-int pkg_db_generate_pkg_from_pkg_sub(struct pkg_db *db, struct pkg *p,
- struct pkg_sub *ps);
+void pkg_db_clear_pkg_list(struct pkg_db *db);
const char *pkg_db_db_root(struct pkg_db *db);
==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_db_hierdb.c#3 (text+ko) ====
@@ -5,6 +5,8 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
+#include <fcntl.h>
+#include <unistd.h>
#include "pkg_util.h"
#include "pkg_private.h"
@@ -12,13 +14,16 @@
#include "pkg_db.h"
#include "pkg_db_private.h"
#include "pkg_db_hierdb.h"
-#include "pkg_sub.h"
int
pkg_db_hierdb_db_open(struct pkg_db *db, const char *db_root)
{
+ int i;
+ int c;
int s;
+ struct dirent **ents;
struct stat sb;
+ struct pkg *p;
#if 0
if (!VALID_DB(db))
#endif
@@ -34,53 +39,23 @@
s = lstat(db_root, &sb);
if (s < 0 || !S_ISDIR(sb.st_mode) || S_ISLNK(sb.st_mode))
- return (DB_BAD_ROOT);
+ return (DB_NOT_OK | DB_BAD_ROOT);
db->db_root = strdup(db_root);
if (db->db_root == NULL)
- return (MEMORY_ERR);
-
- db->dirty = 1;
- db->open = 1;
- db->ps_curr = NULL;
- db->ps_count = 0;
+ return (DB_NOT_OK | MEMORY_ERR);
- return (pkg_db_hierdb_db_init(db));
-}
-
-int
-pkg_db_hierdb_db_init(struct pkg_db *db)
-{
- int i;
- int c;
- int cnt;
- int status;
- struct dirent **ents;
- struct pkg_sub *ps_list;
-#if 0
- if (!VALID_DB(db))
-#endif
- if (db == NULL)
- arg_rage_quit(__func__, "Not a valid database.", RAGE_AT_CLIENT);
-
- /* TODO: Add dirty check. */
-
+ s = 0;
c = scandir(db->db_root, &ents, subdir_sel, alphasort);
if (c < 1)
- return (NOT_OK | MEMORY_ERR);
+ return (DB_NOT_OK | DB_MEMORY_ERR);
- ps_list = calloc(c, sizeof(struct pkg_sub));
- 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;
- continue;
- }
- status |= pkg_sub_init(ps_list + cnt, db, ents[i]->d_name);
- if (PKG_SUB_MEM_ERR(status)) {
- pkg_db_pkg_sub_list_free(db);
+ for (i = 0; i < c; ++i) {
+ p = pkg_new();
+ s |= pkg_db_hierdb_read_pkg_from_db(db, p, ents[i]->d_name);
+ s |= pkg_db_add_pkg_entry(db, p);
+ if (s & DB_NOT_OK) {
+ pkg_db_clear_pkg_entries(db);
for (; i < c; ++i)
free(ents[i]);
free(ents);
@@ -90,19 +65,65 @@
}
free(ents);
- db->ps_list = ps_list;
- db->ps_last = db->ps_list + (cnt - 1);
+ db->dirty = 0;
+
+ return (s);
+}
+
+char *
+pkg_db_hierdb_read_file_to_text(struct pkg_db *db, const char *subpath)
+{
+ int fd;
+ int status;
+ char *path;
+ char *text;
+ struct stat sb;
+
+ if (db == NULL)
+ arg_rage_quit(__func__, "Not a valid database.", RAGE_AT_LIBPKG);
+ if (subpath == NULL)
+ arg_rage_quit(__func__, "Not a valid subpath.", RAGE_AT_LIBPKG);
+
+ status = DB_OK;
+ path = path_build(pkg_db_db_root(db), subpath);
+
+ status = lstat(path, &sb);
+ if (status < 0 || !S_ISREG(sb.st_mode)) {
+ free(path);
+ return (NULL);
+ }
+ if (sb.st_size == 0) {
+ free(path);
+ return (NULL);
+ }
+
+ fd = open(path, O_RDONLY);
+ free(path);
+ if (fd < 0)
+ return (NULL);
- db->ps_curr = NULL;
- db->ps_count = cnt;
- db->dirty = 0;
+ text = malloc(sb.st_size + 1);
+ if (text == NULL) {
+ close(fd);
+ return (NULL);
+ }
+ status = read(fd, text, sb.st_size);
+ close(fd);
+
+ if (status < 0) {
+ free(text);
+ return (NULL);
+ }
+ text[sb.st_size] = '\0';
- return (OK);
+ return (text);
}
int
-pkg_db_hierdb_read_pkg_sub(struct pkg_db *db, struct pkg_sub *ps)
+pkg_db_hierdb_read_pkg_from_db(struct pkg_db *db, struct pkg *p,
+ const char *ident)
{
+ char *path;
int status;
#if 0 /* The client doesn't know about the functions in this file. */
if (!VALID_DB(x))
@@ -110,36 +131,34 @@
if (db == NULL)
arg_rage_quit(__func__, "Not a valid database.", RAGE_AT_CLIENT);
+ pkg_reset(p);
+
status = OK;
+ status |= pkg_set_ident(p, ident);
+
+ path = path_build(ident, COMMENT_FILE);
+ status |= pkg_set_comment(p,pkg_db_hierdb_read_file_to_text(db, path));
+ free(path);
- status = OK;
- status |= pkg_sub_read_file_to_text(ps, COMMENT_FILE_ID) &
- (SUB_EMPTY_FILE | SUB_NO_FILE) ? SUB_NO_COMMENT : OK;
- status |= pkg_sub_read_file_to_text(ps, CONTENTS_FILE_ID) &
- (SUB_EMPTY_FILE | SUB_NO_FILE) ? SUB_NO_CONTENTS : OK;
- status |= pkg_sub_read_file_to_text(ps, DESC_FILE_ID) &
- (SUB_EMPTY_FILE | SUB_NO_FILE) ? SUB_NO_DESC : OK;
- status |= pkg_sub_read_file_to_text(ps, DISPLAY_FILE_ID) &
- (SUB_EMPTY_FILE | SUB_NO_FILE) ? SUB_NO_DISPLAY : OK;
- status |= pkg_sub_read_file_to_text(ps, MTREE_DIRS_FILE_ID) &
- (SUB_EMPTY_FILE | SUB_NO_FILE) ? SUB_NO_MTREE_DIRS : OK;
- status |= pkg_sub_read_file_to_text(ps, REQUIRED_BY_FILE_ID) &
- (SUB_EMPTY_FILE | SUB_NO_FILE) ? SUB_NO_REQUIRED_BY : OK;
+ path = path_build(ident, DESC_FILE);
+ status |= pkg_set_description(p, pkg_db_hierdb_read_file_to_text(db, path));
+ free(path);
- return (status);
-}
+ path = path_build(ident, CONTENTS_FILE);
+ status |= pkg_set_contents(p, pkg_db_hierdb_read_file_to_text(db, path));
+ free(path);
-int
-pkg_db_hierdb_db_sync(struct pkg_db *db)
-{
- int status;
+ path = path_build(ident, DISPLAY_FILE);
+ status |= pkg_set_display(p, pkg_db_hierdb_read_file_to_text(db, path));
+ free(path);
- if (db == NULL)
- arg_rage_quit(__func__, "Not a valid database.", RAGE_AT_CLIENT);
+ path = path_build(ident, MTREE_DIRS_FILE);
+ status |= pkg_set_mtree_dirs(p, pkg_db_hierdb_read_file_to_text(db, path));
+ free(path);
- status = OK;
- if (!db->dirty)
- return (status);
+ path = path_build(ident, REQUIRED_BY_FILE);
+ status |= pkg_set_required_by(p, pkg_db_hierdb_read_file_to_text(db, path));
+ free(path);
return (status);
}
==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_db_hierdb.h#3 (text+ko) ====
@@ -2,16 +2,13 @@
#define __PKGDB_HIERDB_H__
#include "pkg.h"
-#include "pkg_sub.h"
int pkg_db_hierdb_db_open(struct pkg_db *db, const char *db_root);
-int pkg_db_hierdb_db_init(struct pkg_db *db);
+char *pkg_db_hierdb_read_file_to_text(struct pkg_db *db,
+ const char *subpath);
-int pkg_db_hierdb_read_pkg_sub(struct pkg_db *db, struct pkg_sub *ps);
-
-/* int pkg_db_hierdb_db_close(struct pkg_db *db); */
-
-int pkg_db_hierdb_db_sync(struct pkg_db *db);
+int pkg_db_hierdb_read_pkg_from_db(struct pkg_db *db, struct pkg *p,
+ const char *ident);
#endif
==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_db_private.h#3 (text+ko) ====
@@ -1,8 +1,6 @@
#ifndef __PKGDB_PRIVATE_H__
#define __PKGDB_PRIVATE_H__
-#include <sys/queue.h>
-
struct pkg_db {
int open;
int type;
@@ -11,15 +9,14 @@
char *db_root;
- int ps_count;
+ int pkg_count;
- struct pkg_sub *ps_curr;
- struct pkg_sub *ps_list;
- struct pkg_sub *ps_last;
+ char **pkg_list;
+ struct pkg **pkg_entries;
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_read_pkg_from_db) (struct pkg_db *db, struct pkg *p,
+ const char *ident);
int (*pkg_db_db_close) (struct pkg_db *db);
int (*pkg_db_db_sync) (struct pkg_db *db);
};
==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_plist.c#26 (text+ko) ====
@@ -77,20 +77,20 @@
free(pl->origin);
free(pl->srcdir);
- for (c = 0; c < pl->pkg_file_cnt; ++c)
- pkg_file_delete(pl->pkg_file_list + c);
+ for (c = 0; c < pl->pkg_file_count; ++c)
+ pkg_file_delete(pl->pkg_file_list[c]);
free(pl->pkg_file_list);
- pl->pkg_file_cnt = 0;
+ pl->pkg_file_count = 0;
- for (c = 0; c < pl->pkg_depend_cnt; ++c)
- pkg_depend_delete(pl->pkg_depend_list + c);
+ for (c = 0; c < pl->pkg_depend_count; ++c)
+ pkg_depend_delete(pl->pkg_depend_list[c]);
free(pl->pkg_depend_list);
- pl->pkg_depend_cnt = 0;
+ pl->pkg_depend_count = 0;
- for (c = 0; c < pl->pkg_conflict_cnt; ++c)
- pkg_conflict_delete(pl->pkg_conflict_list + c);
+ for (c = 0; c < pl->pkg_conflict_count; ++c)
+ pkg_conflict_delete(pl->pkg_conflict_list[c]);
free(pl->pkg_conflict_list);
- pl->pkg_conflict_cnt = 0;
+ pl->pkg_conflict_count = 0;
pl->extract_in_place = 0;
pl->preserve = 0;
@@ -167,21 +167,15 @@
struct parse_state *st)
{
int s;
-#if 0
size_t line_len;
char *command;
char *argument;
char *sep;
- struct pkg_file *pf;
- struct pkg_depend*pd;
- struct pkg_conflict *pc;
-#endif
if (pl == NULL || line == NULL || st == NULL)
return (-1);
s = PARSE_OK;
-#if 0
line_len = strlen(line);
if (*line == '@') {
sep = strchr(line, ' ');
@@ -192,7 +186,10 @@
argument = sep + 1;
if (strcmp(command, PLIST_CMD_CWD) == 0 ||
strcmp(command, PLIST_CMD_CD) == 0) {
- st->cwd = argument;
+ if (line_len == strlen(PLIST_CMD_CWD))
+ st->cwd = NULL;
+ else
+ st->cwd = argument;
st->last_elem = PLIST_CWD;
} else if (strcmp(command, PLIST_CMD_SRCDIR) == 0) {
pl->srcdir = argument;
@@ -263,29 +260,28 @@
* deal with package versioning in dependencies. */
if (st->last_elem != PLIST_PKGDEP)
return (PARSE_FAIL);
- /* add the the dependency list. */
- pd = pkg_plist_pkg_dep_list_last(pl);
- pkg_dep_set_origin(pd, sep + 1);
+ pkg_depend_set_origin(
+ pl->pkg_depend_list[pl->pkg_depend_count],
+ sep + 1);
} else if (strcmp(argument, PLIST_COMMENT_MD5) == 0) {
if (st->last_elem != PLIST_FILE)
return (PARSE_FAIL);
- pf = pkg_plist_pkg_file_list_last(pl);
- pkg_file_set_md5(pf, sep + 1);
+ pkg_file_set_md5(
+ pl->pkg_file_list[pl->pkg_file_count],
+ sep + 1);
} else {
/* Comment we don't know anything about. */
}
- st->last_elem = PLIST_COMMENT;
+
+ /* Don't set this for now. */
+ /* st->last_elem = PLIST_COMMENT; */
} else if (strcmp(command, PLIST_CMD_PKGDEP) == 0) {
/* I should really be checking the name setting return values
* for errors. */
- pd = pkg_dep_new();
- pkg_dep_set_name(pd, argument);
- pkg_plist_pkg_dep_list_append(pl, pd);
+ s |= pkg_plist_add_depend(pl, argument, NULL);
st->last_elem = PLIST_PKGDEP;
} else if (strcmp(command, PLIST_CMD_CONFLICTS) == 0) {
- pc = pkg_conflict_new();
- pkg_conflict_set_name(pc, argument);
- pkg_plist_pkg_conflict_list_append(pl, pc);
+ s |= pkg_plist_add_conflict(pl, argument);
st->last_elem = PLIST_CONFLICTS;
>>> TRUNCATED FOR MAIL (1000 lines) <<<
More information about the p4-projects
mailing list