PERFORCE change 163072 for review
David Forsythe
dforsyth at FreeBSD.org
Sat May 30 09:07:55 UTC 2009
http://perforce.freebsd.org/chv.cgi?CH=163072
Change 163072 by dforsyth at squirrel on 2009/05/30 09:07:16
Ripped a bunch of stuff apart. Committing mostly for backup.
Affected files ...
.. //depot/projects/soc2009/dforsyth_libpkg/pkg.c#5 edit
.. //depot/projects/soc2009/dforsyth_libpkg/pkg.h#4 edit
.. //depot/projects/soc2009/dforsyth_libpkg/pkg_info.c#1 add
.. //depot/projects/soc2009/dforsyth_libpkg/pkg_util.c#1 add
.. //depot/projects/soc2009/dforsyth_libpkg/pkg_util.h#1 add
.. //depot/projects/soc2009/dforsyth_libpkg/pkgdb.c#5 edit
.. //depot/projects/soc2009/dforsyth_libpkg/pkgdb.h#2 edit
Differences ...
==== //depot/projects/soc2009/dforsyth_libpkg/pkg.c#5 (text+ko) ====
@@ -2,76 +2,35 @@
#include <stdlib.h>
#include <string.h>
+#include <sys/queue.h>
+
+#include "pkg_util.h"
#include "pkg.h"
-struct pkg {
- TAILQ_ENTRY(pkg) next;
-
- char *ident; /* User given name for this pkg. */
-
- char *pkg_name; /* name taken from contents file. */
- char *pkg_comment;
- char *cwd;
- int pkg_rev;
-
- int has_comment;
- int has_contents;
- int has_display;
- int has_mtree_dirs;
- int has_desc;
- int has_required_by;
-};
-
/* Create a new pkg. */
struct pkg *
pkg_new(const char *ident)
{
struct pkg *p;
+ char *new_ident;
if (ident == NULL)
return (NULL);
- p = malloc(sizeof(*p));
- if (p == NULL)
- return (p);
- memset(p, 0, sizeof(*p));
-
- p->ident = strdup(ident);
- if (p->ident == NULL) {
- pkg_free(p);
+ p = calloc(1, sizeof(*p));
+ new_ident = strdup(ident);
+ if (p == NULL || new_ident == NULL) {
+ free(new_ident);
+ free(p);
return (NULL);
}
+ p->ident = new_ident;
return (p);
}
-/* Read in, verify, and assign the information in p's contents file. */
-
-int
-set_pkg_contents(struct pkg *p, char *p_c /* <-- place holder. */)
-{
- if (p == NULL)
- return (-1);
- if (p_c == NULL)
- return (-1);
-
- return (0);
-}
-
/* Read in contents of comment file. */
-
-int
-set_pkg_comment(struct pkg *p, char *pkg_comment)
-{
- if (p == NULL)
- return (-1);
- if (pkg_comment == NULL)
- return (-1);
-
- return (0);
-}
-
char *
pkg_ident(struct pkg *p)
{
@@ -82,21 +41,12 @@
}
char *
-pkg_name(struct pkg *p)
+pkg_comment(struct pkg *p)
{
if (p == NULL)
return (NULL);
- return (p->pkg_name);
-}
-
-char *
-pkg_comment(struct pkg *p)
-{
- if (p == NULL)
- return (NULL);
-
- return (p->pkg_comment);
+ return (p->comment);
}
void
@@ -104,11 +54,7 @@
{
if (p == NULL)
return;
-
+
free(p->ident);
- free(p->pkg_name);
- free(p->pkg_comment);
- free(p->cwd);
-
free(p);
}
==== //depot/projects/soc2009/dforsyth_libpkg/pkg.h#4 (text+ko) ====
@@ -1,30 +1,36 @@
#ifndef __PKG_H__
#define __PKG_H__
-#define COMMENT_FILE "+COMMENT"
-#define CONTENTS_FILE "+CONTENTS"
-#define DESC_FILE "+DESC"
-#define DISPLAY_FILE "+DISPLAY"
-#define MTREE_DIRS_FILE "+MTREE_DIRS"
+struct pkg_file {
+ char *name;
+ char *path;
+ char *md5;
+};
-/* pkgdb. */
-struct pkgdb;
-struct pkg_head;
-struct dirent;
+struct pkg_contents {
+ int rev;
+ char *name;
+ char **file_list; /* place holder */
+ char *cwd;
+ char **conflict;
+};
-struct pkgdb *pkgdb_new_hierdb(const char *db_root);
+struct pkg {
+ TAILQ_ENTRY(pkg) next; /* Hide meh */
-int pkgdb_reset(struct pkgdb *db);
-struct pkgdb_subdir *pkgdb_read_pkg(struct pkgdb *db, const char *name);
-struct pkg *pkgdb_next_pkg(struct pkgdb *db);
-
-void pkgdb_free_hierdb(struct pkgdb *db);
-
-int subdir_sel(struct dirent *ent);
-void free_ptr_array(void **arr, int c);
-
-/* pkg. */
-struct pkg;
+ char *ident; /* User given name for this pkg. */
+ char *path;
+
+ char *comment;
+ struct pkg_contents *contents;
+
+ int has_comment;
+ int has_contents;
+ int has_display;
+ int has_mtree_dirs;
+ int has_desc;
+ int has_required_by;
+};
struct pkg *pkg_new(const char *ident);
==== //depot/projects/soc2009/dforsyth_libpkg/pkgdb.c#5 (text+ko) ====
@@ -7,31 +7,10 @@
#include <sys/stat.h>
#include <dirent.h>
+#include "pkg_util.h"
+#include "pkgdb.h"
#include "pkg.h"
-struct pkgdb {
- int dirty; /* changes have been made to this database. */
-
- char *db_root;
-
- int p_count;
- struct pkg *p_curr;
- TAILQ_HEAD(pkg_head, pkg) p_head;
-
- /* Callbacks */
- /* tuuuummmmbbbllleeewwwweeeedddddd*/
-};
-
-struct pkg {
- TAILQ_ENTRY(pkg) next;
-
- char *name;
- char *path;
- int file_count;
- char **file_list;
- int dirty;
-};
-
/* Everything in here is written with the current database setup in mind.
* I'll add some stuff for flat databases later. */
@@ -44,7 +23,6 @@
struct stat sb;
struct pkgdb *db;
char *new_db_root;
- struct p_head *new_p_headp;
if (db_root == NULL)
return (NULL);
@@ -54,110 +32,76 @@
return (NULL);
db = calloc(1, sizeof(*db));
- new_db_root = strdup(db_root);
- // new_p_headp = calloc(1, sizeof(*db->p_headp));
- if (db == NULL || new_db_root == NULL/* || new_p_headp == NULL*/) {
+ new_db_root = path_strdup(db_root);
+ if (db == NULL || new_db_root == NULL) {
free(db);
free(new_db_root);
- // free(new_p_headp);
return (NULL);
}
db->db_root = new_db_root;
- // db->p_headp = new_p_headp;
- TAILQ_INIT(&db->p_head);
- db->sd_count = 0;
+ db->p_count = 0;
db->dirty = 1;
+ /* Set the callbacks for database access */
+
return (db);
}
-/* Don't know if I'll leave this in here, the dirty var is completely
- * internal... */
-int
-pkgdb_is_dirty(struct pkgdb *db)
-{
- if (db == NULL)
- return (-1);
-
- return (db->dirty);
-}
-
-int
-pkgdb_set_dirty(struct pkgdb *db)
-{
- if (db == NULL)
- return (-1);
-
- return (db->dirty = 1);
-}
-
-int
-pkgdb_set_not_dirty(struct pkgdb *db)
-{
- if (db == NULL)
- return (-1);
-
- return (db->dirty = 0);
-}
-
/* Read in the names of all subdirectories in db->db_root, and add them to
* the db's package list. Set the current package to the head of the
* list. The packages in db's package list are not verified. Returns the
* number of subdirectories in the database. */
int
-pkgdb_reset(struct pkgdb *db)
+pkgdb_init_hierdb(struct pkgdb *db)
{
int i;
- struct pkg *sd;
+ int p_count;
+ struct pkg *p;
struct dirent **ents;
if (db == NULL)
return (-1);
-
+
+ TAILQ_INIT(&db->p_head);
if (db->dirty == 0) {
- /* No changes since the last reset, don't bother walking the
+ /* No changes since the last init, don't bother walking the
* database again. */
db->p_curr = TAILQ_FIRST(&db->p_head);
- return (db->sd_count);
+ return (db->p_count);
}
- db->sd_count = scandir(db->db_root, &ents, subdir_sel, alphasort);
+ p_count = scandir(db->db_root, &ents, subdir_sel, alphasort);
/* Clear out old list. */
pkgdb_free_pkg_list(db);
/* Later on I should look into inserting changes into the existing
* list, rather than just bombing the whole thing. */
- TAILQ_INIT(&db->p_head);
- for (i = 0; i < db->sd_count; ++i) {
- sd = pkgdb_read_pkg(db, ents[i]->d_name);
- if (sd == NULL) {
+ for (i = 0; i < p_count; ++i) {
+ p = pkgdb_read_pkg_hierdb(db, ents[i]->d_name);
+ if (p == NULL) {
pkgdb_free_pkg_list(db);
free(ents);
return (-1);
}
- TAILQ_INSERT_TAIL(&db->p_head, sd, next);
+ TAILQ_INSERT_TAIL(&db->p_head, p, next);
free(ents[i]);
}
free(ents);
+
db->p_curr = TAILQ_FIRST(&db->p_head);
+ db->p_count = p_count;
db->dirty = 0;
- return (db->sd_count);
+ return (db->p_count);
}
-int
-subdir_sel(struct dirent *ent)
-{
- if (strcmp(ent->d_name, ".") != 0 && strcmp(ent->d_name, "..") != 0)
- return (1);
- return (0);
-}
+/* Read in all the package information we can right here. */
struct pkg *
-pkgdb_read_pkg(struct pkgdb *db, const char *ident)
+pkgdb_read_pkg_hierdb(struct pkgdb *db, const char *ident)
{
int i;
int c;
@@ -165,10 +109,11 @@
char *path;
struct stat sb;
struct pkg *p;
+ struct dirent *e;
struct dirent **ents;
- p = pkg_new(name);
- path = pkgdb_path(db, p);
+ p = pkg_new(ident);
+ path = pkgdb_pkg_path(db, p);
if (p == NULL || path == NULL) {
pkg_free(p);
free(path);
@@ -180,12 +125,30 @@
free(path);
return (NULL);
}
-
+
c = scandir(path, &ents, subdir_sel, alphasort);
for (i = 0; i < c; ++i) {
- /* Check file names and set values in p. */
-
- free(ents[i]);
+ s = 0; /* Reset s */
+ /* Go through all the files in this package, grab the information
+ * that we need. */
+ e = ents + i;
+ s = pkg_info_identify_file(e);
+ switch (s) {
+ case IS_COMMENTS:
+ /* Read the comments file into the comments field of this
+ * package. */
+ break;
+ case IS_CONTENTS:
+ /* Do contents parsing stuff. Like...
+ p->contents = pkg_info_parse_contents_file(p,
+ CONTENTS_FILE); */
+ break;
+ case IS_MTREE_DIRS:
+ break;
+ default:
+ /* This is an irrelevant file. */
+ }
+ free(e);
}
free(ents);
@@ -193,23 +156,52 @@
return (p);
}
+/* Grab a package from the database via ident. No need to initialize,
+ * this is a direct query. */
+
+/*
+struct pkg *
+pkgdb_query_pkg(struct pkgdb *db, const char *ident)
+{
+ Need to add callbacks before do this.
+}
+*/
+
+char *
+pkgdb_pkg_path(struct pkgdb *db, struct pkg *p)
+{
+ char *new_path;
+
+ if (db == NULL || p == NULL) {
+ return (NULL);
+ }
+
+ new_path = malloc(strlen(db->db_root) + strlen(p->ident) + 1);
+ if (new_path == NULL)
+ return (NULL);
+
+ strcpy(new_path, db->db_root);
+ strcat(new_path, p->ident);
+
+ return (new_path);
+}
+
/* Move the current subdir pointer to the next one in the list. Return
* the previous subdir. Return NULL if there are no more left. */
struct pkg *
pkgdb_next_pkg(struct pkgdb *db)
{
- struct pkg *sd;
+ struct pkg *p;
if (db == NULL)
return (NULL);
+
+ if ((p = db->p_curr) == NULL)
+ return (NULL);
- sd = db->p_curr;
- if (sd == NULL)
- return (NULL);
-
db->p_curr = TAILQ_NEXT(db->p_curr, next);
- return (sd);
+ return (p);
}
/* Free a hierdb. */
@@ -228,14 +220,14 @@
void
pkgdb_free_pkg_list(struct pkgdb *db)
{
- struct pkg *sd;
- struct pkg *sdn;
+ struct pkg *p;
+ struct pkg *pn;
- sd = TAILQ_FIRST(&db->p_head);
- while (sd != NULL) {
- sdn = TAILQ_NEXT(sd, next);
- pkg_free(sd);
- sd = sdn;
+ p = TAILQ_FIRST(&db->p_head);
+ while (p != NULL) {
+ pn = TAILQ_NEXT(p, next);
+ pkg_free(p);
+ p = pn;
}
TAILQ_INIT(&db->p_head);
}
==== //depot/projects/soc2009/dforsyth_libpkg/pkgdb.h#2 (text+ko) ====
@@ -1,4 +1,40 @@
#ifndef __PKGDB_H__
#define __PKGDB_H__
+#define COMMENT_FILE "+COMMENT"
+#define CONTENTS_FILE "+CONTENTS"
+#define DESC_FILE "+DESC"
+#define DISPLAY_FILE "+DISPLAY"
+#define MTREE_DIRS_FILE "+MTREE_DIRS"
+#define REQUIRED_BY_FILE "+REQUIRED_BY"
+
+#include <sys/queue.h>
+
+struct pkgdb {
+ int dirty; /* changes have been made to this database. */
+
+ char *db_root;
+
+ int p_count;
+ struct pkg *p_curr;
+ TAILQ_HEAD(pkg_head, next) p_head;
+
+ /* Callbacks */
+ /* tuuuummmmbbbllleeewwwweeeedddddd*/
+};
+// struct pkg_head;
+
+struct pkgdb *pkgdb_new_hierdb(const char *db_root);
+
+int pkgdb_init_hierdb(struct pkgdb *db);
+struct pkg *pkgdb_read_pkg_hierdb(struct pkgdb *db, const char *ident);
+struct pkg *pkgdb_next_pkg(struct pkgdb *db);
+
+struct pkg *pkgdb_query_pkg(struct pkgdb *db, const char *ident);
+
+char *pkgdb_pkg_path(struct pkgdb *db, struct pkg *p);
+
+void pkgdb_free_hierdb(struct pkgdb *db);
+void pkgdb_free_pkg_list(struct pkgdb *db);
+
#endif
More information about the p4-projects
mailing list