Date: Fri, 29 May 2009 06:15:48 GMT From: David Forsythe <dforsyth@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 162993 for review Message-ID: <200905290615.n4T6Fmpd080625@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=162993 Change 162993 by dforsyth@squirrel on 2009/05/29 06:15:32 Started removing subdir mess. Affected files ... .. //depot/projects/soc2009/dforsyth_libpkg/pkg.c#4 edit .. //depot/projects/soc2009/dforsyth_libpkg/pkg.h#3 edit .. //depot/projects/soc2009/dforsyth_libpkg/pkgdb.c#4 edit Differences ... ==== //depot/projects/soc2009/dforsyth_libpkg/pkg.c#4 (text+ko) ==== @@ -5,12 +5,21 @@ #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. */ ==== //depot/projects/soc2009/dforsyth_libpkg/pkg.h#3 (text+ko) ==== @@ -1,20 +1,24 @@ +#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" + /* pkgdb. */ struct pkgdb; -struct pkgdb_subdir; -struct subdir_head; +struct pkg_head; struct dirent; struct pkgdb *pkgdb_new_hierdb(const char *db_root); int pkgdb_reset(struct pkgdb *db); -struct pkgdb_subdir *pkgdb_subdir_hash(struct pkgdb *db); -struct pkgdb_subdir *pkgdb_read_subdir(struct pkgdb *db, const char *name); +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); -void pkgdb_free_pkgdb_subdir(struct pkgdb_subdir *sd); -void pkgdb_free_pkgdb_subdir_list(struct pkgdb *db); int subdir_sel(struct dirent *ent); void free_ptr_array(void **arr, int c); @@ -32,3 +36,5 @@ char *pkg_comment(struct pkg *p); void pkg_free(struct pkg *p); + +#endif ==== //depot/projects/soc2009/dforsyth_libpkg/pkgdb.c#4 (text+ko) ==== @@ -14,16 +14,16 @@ char *db_root; - int sd_count; - struct pkgdb_subdir *sd_curr; - TAILQ_HEAD(subdir_head, pkgdb_subdir) sd_head; + int p_count; + struct pkg *p_curr; + TAILQ_HEAD(pkg_head, pkg) p_head; /* Callbacks */ /* tuuuummmmbbbllleeewwwweeeedddddd*/ }; -struct pkgdb_subdir { - TAILQ_ENTRY(pkgdb_subdir) next; +struct pkg { + TAILQ_ENTRY(pkg) next; char *name; char *path; @@ -44,7 +44,7 @@ struct stat sb; struct pkgdb *db; char *new_db_root; - struct sd_head *new_sd_headp; + struct p_head *new_p_headp; if (db_root == NULL) return (NULL); @@ -55,16 +55,16 @@ db = calloc(1, sizeof(*db)); new_db_root = strdup(db_root); - // new_sd_headp = calloc(1, sizeof(*db->sd_headp)); - if (db == NULL || new_db_root == NULL/* || new_sd_headp == NULL*/) { + // new_p_headp = calloc(1, sizeof(*db->p_headp)); + if (db == NULL || new_db_root == NULL/* || new_p_headp == NULL*/) { free(db); free(new_db_root); - // free(new_sd_headp); + // free(new_p_headp); return (NULL); } db->db_root = new_db_root; - // db->sd_headp = new_sd_headp; - TAILQ_INIT(&db->sd_head); + // db->p_headp = new_p_headp; + TAILQ_INIT(&db->p_head); db->sd_count = 0; db->dirty = 1; @@ -110,7 +110,7 @@ pkgdb_reset(struct pkgdb *db) { int i; - struct pkgdb_subdir *sd; + struct pkg *sd; struct dirent **ents; if (db == NULL) @@ -119,30 +119,30 @@ if (db->dirty == 0) { /* No changes since the last reset, don't bother walking the * database again. */ - db->sd_curr = TAILQ_FIRST(&db->sd_head); + db->p_curr = TAILQ_FIRST(&db->p_head); return (db->sd_count); } db->sd_count = scandir(db->db_root, &ents, subdir_sel, alphasort); /* Clear out old list. */ - pkgdb_free_pkgdb_subdir_list(db); + 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->sd_head); + TAILQ_INIT(&db->p_head); for (i = 0; i < db->sd_count; ++i) { - sd = pkgdb_read_subdir(db, ents[i]->d_name); + sd = pkgdb_read_pkg(db, ents[i]->d_name); if (sd == NULL) { - pkgdb_free_pkgdb_subdir_list(db); + pkgdb_free_pkg_list(db); free(ents); return (-1); } - TAILQ_INSERT_TAIL(&db->sd_head, sd, next); + TAILQ_INSERT_TAIL(&db->p_head, sd, next); free(ents[i]); } free(ents); - db->sd_curr = TAILQ_FIRST(&db->sd_head); + db->p_curr = TAILQ_FIRST(&db->p_head); db->dirty = 0; return (db->sd_count); @@ -156,102 +156,62 @@ return (0); } -struct pkgdb_subdir * -pkgdb_read_subdir(struct pkgdb *db, const char *name) +struct pkg * +pkgdb_read_pkg(struct pkgdb *db, const char *ident) { int i; - int s; - int slash; + int c; + int s; /* My var names are so descriptive. */ + char *path; struct stat sb; - struct pkgdb_subdir *sd; - char *new_name; - char *new_path; - DIR *sd_dirp; + struct pkg *p; struct dirent **ents; - slash = (db->db_root[strlen(db->db_root) - 1] == '/' ? 0 : 1); - - sd = calloc(1, sizeof(*sd)); - new_name = strdup(name); - new_path = malloc(strlen(db->db_root) + slash + strlen(name) + 1); - if (sd == NULL || new_name == NULL || new_path == NULL) { - free(sd); - free(new_name); - free(new_path); + p = pkg_new(name); + path = pkgdb_path(db, p); + if (p == NULL || path == NULL) { + pkg_free(p); + free(path); } - strcpy(new_path, db->db_root); - strcat(new_path, "/"); - strcat(new_path, name); - sd->name = new_name; - sd->path = new_path; - - s = lstat(sd->path, &sb); + s = lstat(path, &sb); if (s < 0 || S_ISLNK(sb.st_mode) || !S_ISDIR(sb.st_mode)) { - pkgdb_free_pkgdb_subdir(sd); + pkg_free(p); + free(path); return (NULL); } - sd->file_count = scandir(sd->path, &ents, subdir_sel, alphasort); - sd->file_list = calloc(sd->file_count, sizeof(char *)); - if (sd->file_list == NULL) { - pkgdb_free_pkgdb_subdir(sd); - return (NULL); - } - for (i = 0; i < sd->file_count; ++i) { - sd->file_list[i] = strdup(ents[i]->d_name); - if (sd->file_list[i] == NULL) { - sd->file_count = i; /* free up to */ - pkgdb_free_pkgdb_subdir(sd); - free(ents); - 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]); } + free(ents); - - return (sd); + free(path); + return (p); } /* 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 pkgdb_subdir * -pkgdb_next_pkgdb_subdir(struct pkgdb *db) +struct pkg * +pkgdb_next_pkg(struct pkgdb *db) { - struct pkgdb_subdir *sd; + struct pkg *sd; if (db == NULL) return (NULL); - sd = db->sd_curr; + sd = db->p_curr; if (sd == NULL) return (NULL); - db->sd_curr = TAILQ_NEXT(db->sd_curr, next); + db->p_curr = TAILQ_NEXT(db->p_curr, next); return (sd); } -struct pkg * -pkgdb_next_pkg(struct pkgdb *db) -{ - struct pkgdb_subdir *sd; - struct pkg *p; - - - if (db == NULL) - return (NULL); - - sd = pkgdb_next_pkgdb_subdir(db); - if (sd == NULL) - return (NULL); - - p = pkg_new(sd->name); - return (p); -} - - - /* Free a hierdb. */ void @@ -261,37 +221,21 @@ return; free(db->db_root); - pkgdb_free_pkgdb_subdir_list(db); + pkgdb_free_pkg_list(db); free(db); } void -pkgdb_free_pkgdb_subdir_list(struct pkgdb *db) +pkgdb_free_pkg_list(struct pkgdb *db) { - struct pkgdb_subdir *sd; - struct pkgdb_subdir *sdn; + struct pkg *sd; + struct pkg *sdn; - sd = TAILQ_FIRST(&db->sd_head); + sd = TAILQ_FIRST(&db->p_head); while (sd != NULL) { sdn = TAILQ_NEXT(sd, next); - pkgdb_free_pkgdb_subdir(sd); + pkg_free(sd); sd = sdn; } - TAILQ_INIT(&db->sd_head); -} - -void -pkgdb_free_pkgdb_subdir(struct pkgdb_subdir *sd) -{ - int i; - - if (sd == NULL) - return; - - free(sd->name); - free(sd->path); - for (i = 0; i < sd->file_count; ++i) - free(sd->file_list[i]); - free(sd->file_list); - free(sd); + TAILQ_INIT(&db->p_head); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200905290615.n4T6Fmpd080625>